diff --git a/.images/aws-regions.png b/.images/aws-regions.png new file mode 100644 index 0000000..4a79efe Binary files /dev/null and b/.images/aws-regions.png differ diff --git a/.images/gcp-regions.png b/.images/gcp-regions.png new file mode 100644 index 0000000..1e0c362 Binary files /dev/null and b/.images/gcp-regions.png differ diff --git a/aws-region/README.md b/aws-region/README.md index ecd27ac..99c9f2e 100644 --- a/aws-region/README.md +++ b/aws-region/README.md @@ -12,6 +12,8 @@ tags: [helper, parameter] A parameter with all AWS regions. This allows developers to select the region closest to them. +![AWS Regions](../.images/aws-region.png) + ## Examples ### Default Region diff --git a/gcp-region/README.md b/gcp-region/README.md index 9407845..38692ee 100644 --- a/gcp-region/README.md +++ b/gcp-region/README.md @@ -10,15 +10,18 @@ tags: [gcp, regions, zones, helper] This module adds Google Cloud Platform regions to your Coder template. +![GCP Regions](../.images/gcp-regions.png) + ## Examples 1. Add only GPU zones in the US West 1 region: ```hcl - module "regions" { - source = "https://registry.coder.com/modules/gcp-regions" - default = ["us-west1"] - gpu_only = true + module "gcp_regions" { + source = "git::https://github.com/coder/modules.git//gcp-region?branch=gcp-region" + default = ["us-west1-a"] + regions = ["us-west1"] + gpu_only = false } ``` @@ -26,7 +29,19 @@ This module adds Google Cloud Platform regions to your Coder template. ```hcl module "regions" { - source = "https://registry.coder.com/modules/gcp-regions" - default = ["europe-west"] + source = "https://registry.coder.com/modules/gcp-regions" + regions = ["europe-west"] + single_zone_per_region = false + } + ``` + +3. Add a single zone from each region in US and Europe that laos has GPUs + + ```hcl + module "regions" { + source = "https://registry.coder.com/modules/gcp-regions" + regions = ["us", "europe"] + gpu_only = true + single_zone_per_region = true } ``` diff --git a/gcp-region/main.tf b/gcp-region/main.tf index 1114466..4d675c8 100644 --- a/gcp-region/main.tf +++ b/gcp-region/main.tf @@ -22,6 +22,12 @@ variable "description" { } variable "default" { + default = null + description = "Default zone" + type = string +} + +variable "regions" { description = "List of GCP regions to include." type = list(string) default = ["us-central1"] @@ -51,6 +57,12 @@ variable "custom_icons" { type = map(string) } +variable "single_zone_per_region" { + default = true + description = "Whether to only include a single zone per region." + type = bool +} + locals { zones = { # US Central @@ -343,17 +355,17 @@ locals { "europe-west2-a" = { gpu = true name = "London, England (a)" - icon = "/emojis/1f173-1f1ff.png" + icon = "/emojis/1f1ec-1f1e7.png" } "europe-west2-b" = { gpu = true name = "London, England (b)" - icon = "/emojis/1f173-1f1ff.png" + icon = "/emojis/1f1ec-1f1e7.png" } "europe-west2-c" = { gpu = false name = "London, England (c)" - icon = "/emojis/1f173-1f1ff.png" + icon = "/emojis/1f1ec-1f1e7.png" } "europe-west3-b" = { @@ -702,14 +714,16 @@ data "coder_parameter" "region" { description = var.description icon = "/icon/gcp.png" mutable = var.mutable + default = var.default != null && var.default != "" ? var.default : null dynamic "option" { for_each = { for k, v in local.zones : k => v - if anytrue([for d in var.default : startswith(k, d)]) && (!var.gpu_only || v.gpu) + if anytrue([for d in var.regions : startswith(k, d)]) && (!var.gpu_only || v.gpu) && (!var.single_zone_per_region || endswith(k, "-a")) } content { - icon = try(var.custom_icons[option.key], option.value.icon) - name = try(var.custom_names[option.key], option.value.name) + icon = try(var.custom_icons[option.key], option.value.icon) + # if single_zone_per_region is true, remove the zone letter from the name + name = try(var.custom_names[option.key], var.single_zone_per_region ? substr(option.value.name, 0, length(option.value.name) - 4) : option.value.name) description = option.key value = option.key } @@ -717,5 +731,11 @@ data "coder_parameter" "region" { } output "value" { - value = data.coder_parameter.region.value + description = "GCP zone identifier." + value = data.coder_parameter.region.value +} + +output "region" { + description = "GCP region identifier." + value = substr(data.coder_parameter.region.value, 0, length(data.coder_parameter.region.value) - 2) }