From 7f5b6e9ec0b625bf2c4277b3a63b02d0ea5a929c Mon Sep 17 00:00:00 2001 From: Stephen Kirby Date: Wed, 20 Sep 2023 19:49:41 +0000 Subject: [PATCH 1/6] azure region v0 --- azure-region/main.tf | 180 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 azure-region/main.tf diff --git a/azure-region/main.tf b/azure-region/main.tf new file mode 100644 index 0000000..ce1a174 --- /dev/null +++ b/azure-region/main.tf @@ -0,0 +1,180 @@ +terraform { + required_version = ">= 1.0" + + required_providers { + coder = { + source = "coder/coder" + version = ">= 0.12" + } + } +} + +varaible "display_name" { + default = "Azure Region" + description = "The display name of the Coder parameter." + type = string +} + +variable "description" { + default = "The region where your workspace will live." + description = "Description of the Coder parameter." +} + +variable "default" { + default = "eastus" + description = "The default region to use if no region is specified." + type = string +} + +variable "mutable" { + default = false + description = "Whether the parameter can be changed after creation." + type = bool +} + +variable "custom_names" { + default = {} + description = "A map of custom display names for region IDs." + type = map(string) +} + +variable "custom_icons" { + default = {} + description = "A map of custom icons for region IDs." + type = map(string) +} + +variable "exclude" { + default = [] + description = "A list of region IDs to exclude." + type = list(string) +} + +locals { + regions = { + "eastus" = { + name = "US (Virginia)" + icon = "/emojis/1f1fa-1f1f8.png" + } + "eastus2" = { + name = "US (Virginia) 2" + icon = "/emojis/1f1fa-1f1f8.png" + } + "southcentralus" = { + name = "US (Texas)" + icon = "/emojis/1f1fa-1f1f8.png" + } + "westus2" = { + name = "US (Washington)" + icon = "/emojis/1f1fa-1f1f8.png" + } + "westus3" = { + name = "US (Arizona)" + icon = "/emojis/1f1fa-1f1f8.png" + } + "centralus" = { + name = "US (Iowa)" + icon = "/emojis/1f1fa-1f1f8.png" + } + "canadacentral" = { + name = "Canada (Toronto)" + icon = "/emojis/1f1e8-1f1e6.png" + } + "brazilsouth" = { + name = "Brazil (Sao Paulo)" + icon = "/emojis/1f1e7-1f1f7.png" + } + "eastasia" = { + name = "East Asia (Hong Kong)" + icon = "/emojis/1f1f0-1f1f7.png" + } + "southeastasia" = { + name = "Southeast Asia (Singapore)" + icon = "/emojis/1f1f0-1f1f7.png" + } + "australiaeast" = { + name = "Australia (New South Wales)" + icon = "/emojis/1f1e6-1f1fa.png" + } + "chinanorth3" = { + name = "China (Hebei)" + icon = "/emojis/1f1e8-1f1f3.png" + } + "centralindia" = { + name = "India (Pune)" + icon = "/emojis/1f1ee-1f1f3.png" + } + "japaneast" = { + name = "Japan (Tokyo)" + icon = "/emojis/1f1ef-1f1f5.png" + } + "koreacentral" = { + name = "Korea (Seoul)" + icon = "/emojis/1f1f0-1f1f7.png" + } + "northeurope" = { + name = "Europe (Ireland)" + icon = "/emojis/1f1ea-1f1fa.png" + } + "westeurope" = { + name = "Europe (Netherlands)" + icon = "/emojis/1f1ea-1f1fa.png" + } + "francecentral" = { + name = "France (Paris)" + icon = "/emojis/1f1eb-1f1f7.png" + } + "germanywestcentral" = { + name = "Germany (Frankfurt)" + icon = "/emojis/1f1e9-1f1ea.png" + } + "norwayeast" = { + name = "Norway (Oslo)" + icon = "/emojis/1f1f3-1f1f4.png" + } + "swedencentral" = { + name = "Sweden (Gävle)" + icon = "/emojis/1f1f8-1f1ea.png" + } + "switzerlandnorth" = { + name = "Switzerland (Zurich)" + icon = "/emojis/1f1e8-1f1ed.png" + } + "qatarcentral" = { + name = "Qatar (Doha)" + icon = "/emojis/1f1f6-1f1e6.png" + } + "uaenorth" = { + name = "UAE (Dubai)" + icon = "/emojis/1f1e6-1f1ea.png" + } + "southafricanorth" = { + name = "South Africa (Johannesburg)" + icon = "/emojis/1f1ff-1f1e6.png" + } + "uksouth" = { + name = "UK (London)" + icon = "/emojis/1f1ec-1f1e7.png" + } + } +} + +data "coder_parameter" "region" { + name = "azure_region" + display_name = var.display_name + description = var.description + default = var.default + mutable = var.mutable + dynamic "option" { + for_each = { for k, v in local.regions : k => v if !(contains(var.exclude, k)) } + content { + name = try(var.custom_names[option.key], option.value.name) + icon = try(var.custom_icons[option.key], option.value.icon) + value = option.key + } + } +} + +output "value" { + value = data.coder_parameter.region.value +} From bdd5c374e72c01ff9d11e9f4a73d98c0f18b3ff4 Mon Sep 17 00:00:00 2001 From: Stephen Kirby Date: Wed, 20 Sep 2023 20:25:35 +0000 Subject: [PATCH 2/6] updated README --- azure-region/README.md | 34 +++++++++++++++++++++++++++++++++- azure-region/main.tf | 4 ++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/azure-region/README.md b/azure-region/README.md index afeaa37..af63a31 100644 --- a/azure-region/README.md +++ b/azure-region/README.md @@ -13,4 +13,36 @@ A parameter with all Azure regions. This allows developers to select the region ## Examples -TODO \ No newline at end of file +### Default region + +```hcl +module "azure_region" { + source = "https://registry.coder.com/modules/azure-region" + default = "eastus" +} + +provider "azure" { + region = module.azure_region.value + ... +} +``` + +### Customize existing regions + +Change the display name for a region: + +```hcl +module "azure-region" { + source = "https://registry.coder.com/modules/azure-region" + custom_names = { + "eastus": "Eastern United States!" + } + custom_icons = { + "eastus": "/icons/smiley.svg" + } +} + +provider "aws" { + region = module.aws_region.value +} +``` diff --git a/azure-region/main.tf b/azure-region/main.tf index ce1a174..4cd3b2b 100644 --- a/azure-region/main.tf +++ b/azure-region/main.tf @@ -51,7 +51,7 @@ variable "exclude" { } locals { - regions = { + all_regions = { "eastus" = { name = "US (Virginia)" icon = "/emojis/1f1fa-1f1f8.png" @@ -166,7 +166,7 @@ data "coder_parameter" "region" { default = var.default mutable = var.mutable dynamic "option" { - for_each = { for k, v in local.regions : k => v if !(contains(var.exclude, k)) } + for_each = { for k, v in local.all_regions : k => v if !(contains(var.exclude, k)) } content { name = try(var.custom_names[option.key], option.value.name) icon = try(var.custom_icons[option.key], option.value.icon) From 18e999ccc56146786ecf7c60c86b77248d0b0f8f Mon Sep 17 00:00:00 2001 From: Stephen Kirby Date: Wed, 20 Sep 2023 20:26:30 +0000 Subject: [PATCH 3/6] added region exclusion --- azure-region/README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/azure-region/README.md b/azure-region/README.md index af63a31..d19f99c 100644 --- a/azure-region/README.md +++ b/azure-region/README.md @@ -46,3 +46,18 @@ provider "aws" { region = module.aws_region.value } ``` + +### Exclude Regions + +Hide the `westus2` region: + +```hcl +module "aws-region" { + source = "https://registry.coder.com/modules/aws-region" + exclude = [ "westus2" ] +} + +provider "aws" { + region = module.aws_region.value +} +``` \ No newline at end of file From 78c93cac045385b4ce75c0d545a11e65b86cf66d Mon Sep 17 00:00:00 2001 From: Stephen Kirby Date: Wed, 20 Sep 2023 20:44:18 +0000 Subject: [PATCH 4/6] improved opening README line to reflect jetbrains gateway --- azure-region/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-region/README.md b/azure-region/README.md index d19f99c..f21c0b7 100644 --- a/azure-region/README.md +++ b/azure-region/README.md @@ -9,7 +9,7 @@ tags: [helper, parameter, azure] # Azure Region -A parameter with all Azure regions. This allows developers to select the region closest to them. +This module adds a parameter with all Azure regions. This allows developers to select the region closest to them. ## Examples From 61dc0747674f53f9898e033cbb3638654eda4fe3 Mon Sep 17 00:00:00 2001 From: Stephen Kirby Date: Wed, 20 Sep 2023 21:36:44 +0000 Subject: [PATCH 5/6] fixed 'varaible' typo --- azure-region/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-region/main.tf b/azure-region/main.tf index 4cd3b2b..c71a06b 100644 --- a/azure-region/main.tf +++ b/azure-region/main.tf @@ -9,7 +9,7 @@ terraform { } } -varaible "display_name" { +variable "display_name" { default = "Azure Region" description = "The display name of the Coder parameter." type = string From 1f2f049ffa3b12f926995e1ce616cdbaba839b0a Mon Sep 17 00:00:00 2001 From: Stephen Kirby Date: Wed, 20 Sep 2023 21:37:40 +0000 Subject: [PATCH 6/6] dropped coder version --- azure-region/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-region/main.tf b/azure-region/main.tf index c71a06b..434ada4 100644 --- a/azure-region/main.tf +++ b/azure-region/main.tf @@ -4,7 +4,7 @@ terraform { required_providers { coder = { source = "coder/coder" - version = ">= 0.12" + version = ">= 0.11" } } }