Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Depends on functionalities and Set mandatory fields via UI Meta flag #187

Open
wants to merge 12 commits into
base: staging
Choose a base branch
from
Open
52 changes: 52 additions & 0 deletions docs/docs/rad-lab-ui/ui_configure/ui-meta.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ To enable programmitic generation of the UI, we have introduced a custom syntax
Below are the keywords within this custom DSL and how they impact the UI. None, some, or all can be used on a given variable to change its behavior in the UI.

## Group

Some variables are connected to each other and should be presented together. For example disk type and disk size are both related to the storage disk. The `group` field is a number. RAD Lab UI parses the `group` field and **groups variables by this number** and also **orders the pages** (of grouped variables) by this as well.

**(Example)** Both variables will be presented on the 3rd page:

```terraform
variable "network_name" {
description = "Name of the network to be created. {{UIMeta group=3 }}"
Expand All @@ -31,9 +33,11 @@ variable "subnet_name" {
:::

## Order

Within a [group](#group), the order of the variables is determined by the `order` keyword. It is a whole number and sorted in ascending order (smallest first).

**(Example)** `subnet_name` will be shown before `network_name`:

```terraform
variable "network_name" {
description = "Name of the network to be created. {{UIMeta group=3 order=2 }}"
Expand All @@ -49,9 +53,11 @@ variable "subnet_name" {
```

## Options

Some variables are presented as a dropdown of options instead of a free-form input. The `options` keyword is a comma-delimted list of options the user can select from. Only one option is selectable (no multi-select).

**(Example)** A dropdown with three options (50, 100, and 500) will be displayed to the user

```terraform
variable "boot_disk_size_gb" {
description = "The size of the boot disk (GB) {{UIMeta options=50,100,500 }}"
Expand All @@ -61,10 +67,56 @@ variable "boot_disk_size_gb" {
```

## Updatesafe

After a module has been deployed (the project created and resources created within it), some Terraform updates can be **destructive**. To warn the users that they may be performing a potentially destructive action, the `updatesafe` key word is added (or omitted) to the `UIMeta`.

Any time a user makes an update to an existing deployment, the `updatesafe` values are checked. If **ANY** of the changed variables do **NOT** have the `updatesafe` keyword, the user will be warned that they likely will lose data by applying the update. Put another way, only if **ALL** the changed variables are `updatesafe` will the prompt be skipped.

## Required

Some of the variables are required to have value for deployment. If not `default` value works, ensure you set the `required` UIMeta keyword. Users will then be required to provide a value before deploying.
saurabhkg891 marked this conversation as resolved.
Show resolved Hide resolved

**(Example)** `billing_account_id` will be shown as required for users and User must have to provide the input.

```terraform
variable "billing_account_id" {
description = "Billing Account associated to the GCP Resources. {{UIMeta group=0 order=3 required }}"
type = string
}
```

## Depends On

Some of the variables are depends on other variables input, in order to make it dependent of the variables is determined by the `dependson` keyword. So based on user input and depends on condition satified to be shown the dependent variables.

**(Example)** `container_image_repository` will be shown once `create_container_image` value will be true, similarly `ip_cidr_range` will be shown once `create_network` and `create_usermanaged_notebook` value will be true , similarly for other variables it will work based on `dependson` conditions with `||` and `&&` operands.

saurabhkg891 marked this conversation as resolved.
Show resolved Hide resolved
```terraform
variable "container_image_repository" {
description = "Container Image Repo, only set if creating container image notebook instance by setting \`create_container_image\` variable to true. {{UIMeta group=2 order=4 dependson=create_container_image==true required }}"
type = string
default = ""
}

variable "ip_cidr_range" {
description = "Unique IP CIDR Range for AI Notebooks subnet {{UIMeta group=3 order=5 dependson=create_network==true&&create_usermanaged_notebook==true required }}"
type = string
default = "10.142.190.0/24"
}

variable "network_name" {
description = "Name of the network to be created. {{UIMeta group=3 order=2 dependson=create_usermanaged_notebook==true||enable_gpu_driver==true required }}"
type = string
default = "ai-notebook"
}

variable "subnet_name" {
description = "Name of the subnet where to deploy the Notebooks. {{UIMeta group=3 dependson=(enable_gpu_driver==true||create_usermanaged_notebook==true)&&(create_network==true||set_external_ip_policy==true) required }}"
type = string
default = "subnet-ai-notebook"
}
```

:::danger
Ensure you backup any data before performing a destructive action.
:::
30 changes: 18 additions & 12 deletions radlab-ui/webapp/__mocks__/terraform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const DATA_SCIENCE_VARS = `

# {{UIMeta group=1 order=1 }}
variable "billing_account_id" {
description = "Billing Account associated to the GCP Resources"
description = "Billing Account associated to the GCP Resources. {{UIMeta group=0 order=3 required }}"
type = string
}

Expand All @@ -21,7 +21,7 @@ variable "boot_disk_type" {
variable "create_container_image" {
description = "If the notebook needs to have image type as Container set this variable to true, set it to false when using dafault image type i.e. VM."
type = bool
default = false
default = true
}

variable "create_network" {
Expand All @@ -36,8 +36,14 @@ variable "create_project" {
default = true
}

variable "create_usermanaged_notebook" {
description = "Set to true if you want to create a user managed workbench notebook. If you want to create a Google managed workbench notebook, set this variable to false. {{UIMeta group=2 order=1 }}"
type = bool
default = true
}

variable "container_image_repository" {
description = "Container Image Repo, only set if creating container image notebook instance by setting \`create_container_image\` variable to true"
description = "Container Image Repo, only set if creating container image notebook instance by setting \`create_container_image\` variable to true. {{UIMeta group=2 order=4 dependson=create_container_image==true required }}"
type = string
default = ""
}
Expand Down Expand Up @@ -67,13 +73,13 @@ variable "folder_id" {
}

variable "gpu_accelerator_type" {
description = "Type of GPU you would like to spin up"
description = "Type of GPU you would like to spin up. {{UIMeta group=2 order=10 dependson=enable_gpu_driver==true required }}"
type = string
default = ""
}

variable "gpu_accelerator_core_count" {
description = "Number of of GPU core count. {{UIMeta group=3 order=11 }}"
description = "Number of of GPU core count"
type = number
default = 0
}
Expand All @@ -91,19 +97,19 @@ variable "image_project" {
}

variable "ip_cidr_range" {
description = "Unique IP CIDR Range for AI Notebooks subnet"
description = "Unique IP CIDR Range for AI Notebooks subnet {{UIMeta group=3 order=5 dependson=create_network==true&&create_usermanaged_notebook==true required}}"
type = string
default = "10.142.190.0/24"
}

variable "machine_type" {
description = "Type of VM you would like to spin up"
description = "Type of VM you would like to spin up.{{UIMeta group=3 order=5 dependson=create_network==true&&enable_gpu_driver==true}}"
type = string
default = "n1-standard-1"
}

variable "network_name" {
description = "Name of the network to be created."
description = "Name of the network to be created. {{UIMeta group=3 order=2 dependson=create_usermanaged_notebook==true||enable_gpu_driver==true required}}"
type = string
default = "ai-notebook"
}
Expand Down Expand Up @@ -139,7 +145,7 @@ variable "set_external_ip_policy" {
}

variable "set_shielded_vm_policy" {
description = "Apply org policy to disable shielded VMs. {{UIMeta updatesafe}}"
description = "Apply org policy to disable shielded VMs. {{UIMeta dependson=set_external_ip_policy==true||enable_gpu_driver==true updatesafe}}"
type = bool
default = true
}
Expand All @@ -151,7 +157,7 @@ variable "set_trustedimage_project_policy" {
}

variable "subnet_name" {
description = "Name of the subnet where to deploy the Notebooks. {{UIMeta group=3 }}"
description = "Name of the subnet where to deploy the Notebooks. {{UIMeta group=3 dependson=(enable_gpu_driver==true||create_usermanaged_notebook==true)&&(create_network==true||set_external_ip_policy==true) required }}"
type = string
default = "subnet-ai-notebook"
}
Expand All @@ -163,7 +169,7 @@ variable "trusted_users" {
}

variable "zone" {
description = "Cloud Zone associated to the AI Notebooks {{UIMeta group=1 order=1 options=us-central1-b,us-east1-a,us-west3-b,us-east4-c }}"
description = "Cloud Zone associated to the AI Notebooks {{UIMeta group=1 order=1 options=us-central1-b,us-east1-a,us-west3-b,us-east4-c required }}"
type = string
default = "us-east4-c"
otherfield = "bar"
Expand All @@ -186,7 +192,7 @@ variable "billing_budget_alert_spent_percents" {
}

variable "billing_budget_services" {
description = "A list of services ids to be included in the budget. If omitted, all services will be included in the budget. Service ids can be found at https://cloud.google.com/skus/. {{UIMeta group=0 order=12 updatesafe }}"
description = "A list of services ids to be included in the budget. If omitted, all services will be included in the budget. Service ids can be found at https://cloud.google.com/skus/. {{UIMeta group=0 order=12 updatesafe dependson=(enable_gpu_driver==true||set_external_ip_policy==true)&&(create_network==true||create_usermanaged_notebook==true)}}"
type = list(string)
default = null
}
Expand Down
Loading