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
54 changes: 54 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,58 @@ 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 no `default` value works, ensure you set the `required` UIMeta keyword. Users will then be required to provide a value before deploying.

**(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
It is recommended to put dependent variables immediately (or soon) after their parent variable by using the UIMeta `group` and `order` variables. This helps make a more logical, consistent flow for users.

```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.
:::
74 changes: 37 additions & 37 deletions modules/data_science/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@
*/

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

variable "billing_budget_alert_spend_basis" {
description = "The type of basis used to determine if spend has passed the threshold. {{UIMeta group=0 order=6 updatesafe }}"
description = "The type of basis used to determine if spend has passed the threshold. {{UIMeta group=0 order=6 updatesafe dependson=create_budget==true required }}"
type = string
default = "CURRENT_SPEND"
}

variable "billing_budget_alert_spent_percents" {
description = "A list of percentages of the budget to alert on when threshold is exceeded. {{UIMeta group=0 order=7 updatesafe }}"
description = "A list of percentages of the budget to alert on when threshold is exceeded. {{UIMeta group=0 order=7 updatesafe dependson=create_budget==true required }}"
type = list(number)
default = [0.5, 0.7, 1]
}

variable "billing_budget_amount" {
description = "The amount to use as the budget in USD. {{UIMeta group=0 order=8 updatesafe }}"
description = "The amount to use as the budget in USD. {{UIMeta group=0 order=8 updatesafe dependson=create_budget==true required }}"
type = number
default = 500
}

variable "billing_budget_amount_currency_code" {
description = "The 3-letter currency code defined in ISO 4217 (https://cloud.google.com/billing/docs/resources/currency#list_of_countries_and_regions). It must be the currency associated with the billing account. {{UIMeta group=0 order=9 updatesafe }}"
description = "The 3-letter currency code defined in ISO 4217 (https://cloud.google.com/billing/docs/resources/currency#list_of_countries_and_regions). It must be the currency associated with the billing account. {{UIMeta group=0 order=9 updatesafe dependson=create_budget==true required }}"
type = string
default = "USD"
}
Expand All @@ -50,13 +50,13 @@ variable "billing_budget_calendar_period" {
}

variable "billing_budget_credit_types_treatment" {
description = "Specifies how credits should be treated when determining spend for threshold calculations. {{UIMeta group=0 order=11 updatesafe }}"
description = "Specifies how credits should be treated when determining spend for threshold calculations. {{UIMeta group=0 order=10 updatesafe dependson=create_budget==true required }}"
type = string
default = "INCLUDE_ALL_CREDITS"
}

variable "billing_budget_labels" {
description = "A single label and value pair specifying that usage from only this set of labeled resources should be included in the budget. {{UIMeta group=0 order=12 updatesafe }}"
description = "A single label and value pair specifying that usage from only this set of labeled resources should be included in the budget. {{UIMeta group=0 order=11 updatesafe dependson=create_budget==true }}"
type = map(string)
default = {}
validation {
Expand All @@ -66,35 +66,35 @@ variable "billing_budget_labels" {
}

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=13 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=create_budget==true }}"
type = list(string)
default = null
}

variable "billing_budget_notification_email_addresses" {
description = "A list of email addresses which will be recieving billing budget notification alerts. A maximum of 5 channels are allowed. {{UIMeta group=0 order=14 updatesafe }}"
description = "A list of email addresses which will be recieving billing budget notification alerts. A maximum of 4 channels are allowed as the first element of `trusted_users` is automatically added as one of the channel. {{UIMeta group=0 order=13 updatesafe dependson=create_budget==true required }}"
type = set(string)
default = []
validation {
condition = length(var.billing_budget_notification_email_addresses) <= 5
error_message = "Maximum of 5 email addresses are allowed for the budget monitoring channel."
condition = length(var.billing_budget_notification_email_addresses) <= 4
error_message = "Maximum of 4 email addresses are allowed for the budget monitoring channel."
}
}

variable "billing_budget_pubsub_topic" {
description = "If true, creates a Cloud Pub/Sub topic where budget related messages will be published. Default is false. {{UIMeta group=0 order=15 updatesafe }}"
description = "If true, creates a Cloud Pub/Sub topic where budget related messages will be published. Default is false. {{UIMeta group=0 order=14 updatesafe dependson=create_budget==true }}"
type = bool
default = false
}

variable "boot_disk_size_gb" {
description = "The size of the boot disk in GB attached to this instance. {{UIMeta group=3 order=8 options=50,100,500 }}"
description = "The size of the boot disk in GB attached to this instance. {{UIMeta group=2 order=8 options=50,100,500 required }}"
type = number
default = 100
}

variable "boot_disk_type" {
description = "Disk types for notebook instances. {{UIMeta group=3 order=7 }}"
description = "Disk types for notebook instances. {{UIMeta group=2 order=7 required }}"
type = string
default = "PD_SSD"
}
Expand All @@ -106,13 +106,13 @@ variable "create_budget" {
}

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. {{UIMeta group=3 order=3 }}"
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. {{UIMeta group=2 order=3 }}"
type = bool
default = false
}

variable "create_network" {
description = "If the module has to be deployed in an existing network, set this variable to false. {{UIMeta group=2 order=1 }}"
description = "If the module has to be deployed in an existing network, set this variable to false. {{UIMeta group=3 order=1 }}"
type = bool
default = true
}
Expand All @@ -124,19 +124,19 @@ variable "create_project" {
}

variable "create_usermanaged_notebook" {
description = "Set to true if you want to create user managed workbench notebooks. If you want to create google managed workbench notebook, set this variable to false. {{UIMeta group=3 order=1 }}"
description = "Set to true if you want to create user managed workbench notebooks. If you want to create 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. {{UIMeta group=3 order=4 }}"
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 "container_image_tag" {
description = "Container Image Tag, only set if creating container image notebook instance by setting `create_container_image` variable to true. {{UIMeta group=3 order=5 }}"
description = "Container Image Tag, only set if creating container image notebook instance by setting `create_container_image` variable to true. {{UIMeta group=2 order=5 dependson=create_container_image==true required }}"
type = string
default = "latest"
}
Expand All @@ -148,7 +148,7 @@ variable "deployment_id" {
}

variable "enable_gpu_driver" {
description = "Install GPU driver on the instance. {{UIMeta group=3 order=9 }}"
description = "Install GPU driver on the instance. {{UIMeta group=2 order=9 }}"
type = bool
default = false
}
Expand All @@ -160,61 +160,61 @@ variable "enable_services" {
}

variable "folder_id" {
description = "Folder ID where the project should be created. It can be skipped if already setting organization_id. Leave blank if the project should be created directly underneath the Organization node. {{UIMeta group=0 order=2 updatesafe }}"
description = "Folder ID where the project should be created. It can be skipped if already setting organization_id. Leave blank if the project should be created directly underneath the Organization node. {{UIMeta group=0 order=2 updatesafe required }}"
type = string
default = ""
}

variable "gpu_accelerator_type" {
description = "Type of GPU you would like to spin up. {{UIMeta group=3 order=10 }}"
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. {{UIMeta group=2 order=11 dependson=enable_gpu_driver==true required }}"
type = number
default = 0
}

variable "image_family" {
description = "Image of the AI notebook. {{UIMeta group=3 order=13 }}"
description = "Image of the AI notebook. {{UIMeta group=2 order=13 dependson=create_usermanaged_notebook==true required }}"
type = string
default = "tf-latest-cpu"
}

variable "image_project" {
description = "Google Cloud project where the image is hosted. {{UIMeta group=3 order=12 }}"
description = "Google Cloud project where the image is hosted. {{UIMeta group=2 order=12 dependson=create_usermanaged_notebook==true required }}"
type = string
default = "deeplearning-platform-release"
}

variable "ip_cidr_range" {
description = "Unique IP CIDR Range for AI Notebooks subnet. {{UIMeta group=2 order=4 }}"
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. {{UIMeta group=3 order=6 }}"
description = "Type of VM you would like to spin up. {{UIMeta group=2 order=6 required }}"
type = string
default = "n1-standard-1"
}

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

variable "notebook_count" {
description = "Number of AI Notebooks requested. {{UIMeta group=3 order=2 updatesafe }}"
description = "Number of AI Notebooks requested. {{UIMeta group=2 order=2 updatesafe required }}"
type = number
default = 1
}

variable "organization_id" {
description = "Organization ID where GCP Resources need to get spin up. It can be skipped if already setting folder_id. {{UIMeta group=0 order=1 }}"
description = "Organization ID where GCP Resources need to get spin up. It can be skipped if already setting folder_id. {{UIMeta group=0 order=1 required }}"
type = string
default = ""
}
Expand All @@ -232,7 +232,7 @@ variable "owner_users" {
}

variable "project_id_prefix" {
description = "If `create_project` is true, this will be the prefix of the Project ID & name created. If `create_project` is false this will be the actual Project ID, of the existing project where you want to deploy the module. {{UIMeta group=1 order=2 }}"
description = "If `create_project` is true, this will be the prefix of the Project ID & name created. If `create_project` is false this will be the actual Project ID, of the existing project where you want to deploy the module. {{UIMeta group=1 order=2 required }}"
type = string
default = "radlab-data-science"
}
Expand All @@ -244,31 +244,31 @@ variable "resource_creator_identity" {
}

variable "set_domain_restricted_sharing_policy" {
description = "Enable org policy to allow all principals to be added to IAM policies. {{UIMeta group=0 order=16 updatesafe }}"
description = "Enable org policy to allow all principals to be added to IAM policies. {{UIMeta group=0 order=15 updatesafe }}"
type = bool
default = false
}

variable "set_external_ip_policy" {
description = "Enable org policy to allow External (Public) IP addresses on virtual machines. {{UIMeta group=0 order=17 updatesafe }}"
description = "Enable org policy to allow External (Public) IP addresses on virtual machines. {{UIMeta group=0 order=16 updatesafe }}"
type = bool
default = false
}

variable "set_shielded_vm_policy" {
description = "Apply org policy to disable shielded VMs. {{UIMeta group=0 order=18 updatesafe }}"
description = "Apply org policy to disable shielded VMs. {{UIMeta group=0 order=17 updatesafe }}"
type = bool
default = false
}

variable "set_trustedimage_project_policy" {
description = "Apply org policy to set the trusted image projects. {{UIMeta group=0 order=19 updatesafe }}"
description = "Apply org policy to set the trusted image projects. {{UIMeta group=0 order=18 updatesafe }}"
type = bool
default = false
}

variable "subnet_name" {
description = "Name of the subnet where to deploy the Notebooks. {{UIMeta group=2 order=3 }}"
description = "Name of the subnet where to deploy the Notebooks. {{UIMeta group=3 order=4 dependson=create_usermanaged_notebook==true required }}"
type = string
default = "subnet-ai-notebook"
}
Expand All @@ -286,7 +286,7 @@ variable "trusted_users" {
}

variable "zone" {
description = "Cloud Zone associated to the AI Notebooks. List of zones - https://cloud.google.com/compute/docs/regions-zones#available. {{UIMeta group=0 order=20 }}"
description = "Cloud Zone associated to the AI Notebooks. List of zones - https://cloud.google.com/compute/docs/regions-zones#available. {{UIMeta group=0 order=20 required }}"
type = string
default = "us-central1-c"
}
Loading