add module exoscale-zone
							parent
							
								
									0068642d3b
								
							
						
					
					
						commit
						c4690dd3f3
					
				@ -0,0 +1 @@
 | 
			
		||||
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 68.03 68.03"><defs><style>.cls-1{fill:#da291c;}</style></defs><title>Artboard 1</title><polygon class="cls-1" points="34.02 13.31 11.27 52.72 14.52 52.72 34.02 18.94 34.02 24.57 17.77 52.72 21.02 52.72 34.02 30.2 34.02 35.83 24.27 52.72 27.52 52.72 34.02 41.46 34.02 47.09 30.77 52.72 34.02 52.72 34.02 52.72 56.77 52.72 34.02 13.31"/></svg>
 | 
			
		||||
| 
		 After Width: | Height: | Size: 427 B  | 
@ -0,0 +1,93 @@
 | 
			
		||||
---
 | 
			
		||||
display_name: exoscale-zone
 | 
			
		||||
description: A parameter with human zone names and icons
 | 
			
		||||
icon: ../.icons/exoscale.svg
 | 
			
		||||
maintainer_github: WhizUs
 | 
			
		||||
verified: false
 | 
			
		||||
tags: [helper, parameter, zones, regions, exoscale]
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
# exoscale-zone
 | 
			
		||||
 | 
			
		||||
A parameter with all Exoscale zones. This allows developers to select
 | 
			
		||||
the zone closest to them.
 | 
			
		||||
 | 
			
		||||
Customize the preselected parameter value:
 | 
			
		||||
 | 
			
		||||
```hcl
 | 
			
		||||
module "exoscale-zone" {
 | 
			
		||||
    source = "https://registry.coder.com/modules/exoscale-zone"
 | 
			
		||||
    default = "ch-dk-2"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
data "exoscale_compute_template" "my_template" {
 | 
			
		||||
  zone = module.exoscale-zone.value
 | 
			
		||||
  name = "Linux Ubuntu 22.04 LTS 64-bit"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
resource "exoscale_compute_instance" "instance" {
 | 
			
		||||
  zone    = module.exoscale-zone.value
 | 
			
		||||
  ....
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||

 | 
			
		||||
 | 
			
		||||
## Examples
 | 
			
		||||
 | 
			
		||||
### Customize zones
 | 
			
		||||
 | 
			
		||||
Change the display name and icon for a zone using the corresponding maps:
 | 
			
		||||
 | 
			
		||||
```hcl
 | 
			
		||||
module "exoscale-zone" {
 | 
			
		||||
    source = "https://registry.coder.com/modules/exoscale-zone"
 | 
			
		||||
    default = "at-vie-1"
 | 
			
		||||
    custom_names = {
 | 
			
		||||
        "at-vie-1": "Home Vienna"
 | 
			
		||||
    }
 | 
			
		||||
    custom_icons = {
 | 
			
		||||
        "at-vie-1": "/emojis/1f3e0.png"
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
data "exoscale_compute_template" "my_template" {
 | 
			
		||||
  zone = module.exoscale-zone.value
 | 
			
		||||
  name = "Linux Ubuntu 22.04 LTS 64-bit"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
resource "exoscale_compute_instance" "instance" {
 | 
			
		||||
  zone    = module.exoscale-zone.value
 | 
			
		||||
  ....
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||

 | 
			
		||||
 | 
			
		||||
### Exclude regions
 | 
			
		||||
 | 
			
		||||
Hide the Switzerland zones Geneva and Zurich
 | 
			
		||||
 | 
			
		||||
```hcl
 | 
			
		||||
module "exoscale-zone" {
 | 
			
		||||
    source = "https://registry.coder.com/modules/exoscale-zone"
 | 
			
		||||
    exclude = [ "ch-gva-2", "ch-dk-2" ]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
data "exoscale_compute_template" "my_template" {
 | 
			
		||||
  zone = module.exoscale-zone.value
 | 
			
		||||
  name = "Linux Ubuntu 22.04 LTS 64-bit"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
resource "exoscale_compute_instance" "instance" {
 | 
			
		||||
  zone    = module.exoscale-zone.value
 | 
			
		||||
  ....
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||

 | 
			
		||||
 | 
			
		||||
## Related templates
 | 
			
		||||
 | 
			
		||||
An exoscale sample template will be delivered soon.
 | 
			
		||||
@ -0,0 +1,25 @@
 | 
			
		||||
import { describe, expect, it } from "bun:test";
 | 
			
		||||
import {
 | 
			
		||||
  executeScriptInContainer,
 | 
			
		||||
  runTerraformApply,
 | 
			
		||||
  runTerraformInit,
 | 
			
		||||
  testRequiredVariables,
 | 
			
		||||
} from "../test";
 | 
			
		||||
 | 
			
		||||
describe("exoscale-zone", async () => {
 | 
			
		||||
  await runTerraformInit(import.meta.dir);
 | 
			
		||||
 | 
			
		||||
  testRequiredVariables(import.meta.dir, {});
 | 
			
		||||
 | 
			
		||||
  it("default output", async () => {
 | 
			
		||||
    const state = await runTerraformApply(import.meta.dir, {});
 | 
			
		||||
    expect(state.outputs.value.value).toBe("");
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it("customized default", async () => {
 | 
			
		||||
    const state = await runTerraformApply(import.meta.dir, {
 | 
			
		||||
      default: "at-vie-1",
 | 
			
		||||
    });
 | 
			
		||||
    expect(state.outputs.value.value).toBe("at-vie-1");
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
@ -0,0 +1,110 @@
 | 
			
		||||
terraform {
 | 
			
		||||
  required_version = ">= 1.0"
 | 
			
		||||
 | 
			
		||||
  required_providers {
 | 
			
		||||
    coder = {
 | 
			
		||||
      source  = "coder/coder"
 | 
			
		||||
      version = ">= 0.12"
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
variable "display_name" {
 | 
			
		||||
  default     = "Exoscale Region"
 | 
			
		||||
  description = "The display name of the parameter."
 | 
			
		||||
  type        = string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
variable "description" {
 | 
			
		||||
  default     = "The region to deploy workspace infrastructure."
 | 
			
		||||
  description = "The description of the parameter."
 | 
			
		||||
  type        = string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
variable "default" {
 | 
			
		||||
  default     = ""
 | 
			
		||||
  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 {
 | 
			
		||||
  # This is a static list because the zones don't change _that_
 | 
			
		||||
  # frequently and including the `exoscale_zones` data source requires
 | 
			
		||||
  # the provider, which requires a zone.
 | 
			
		||||
  # https://www.exoscale.com/datacenters/
 | 
			
		||||
  zones = {
 | 
			
		||||
    "de-fra-1" = {
 | 
			
		||||
      name = "Frankfurt - Germany"
 | 
			
		||||
      icon = "/emojis/1f1e9-1f1ea.png"
 | 
			
		||||
    }
 | 
			
		||||
    "at-vie-1" = {
 | 
			
		||||
      name = "Vienna 1 - Austria"
 | 
			
		||||
      icon = "/emojis/1f1e6-1f1f9.png"
 | 
			
		||||
    }
 | 
			
		||||
    "at-vie-2" = {
 | 
			
		||||
      name = "Vienna 2 - Austria"
 | 
			
		||||
      icon = "/emojis/1f1e6-1f1f9.png"
 | 
			
		||||
    }
 | 
			
		||||
    "ch-gva-2" = {
 | 
			
		||||
      name = "Geneva - Switzerland"
 | 
			
		||||
      icon = "/emojis/1f1e8-1f1ed.png"
 | 
			
		||||
    }
 | 
			
		||||
    "ch-dk-2" = {
 | 
			
		||||
      name = "Zurich - Switzerland"
 | 
			
		||||
      icon = "/emojis/1f1e8-1f1ed.png"
 | 
			
		||||
    }
 | 
			
		||||
    "bg-sof-1" = {
 | 
			
		||||
      name = "Sofia - Bulgaria"
 | 
			
		||||
      icon = "/emojis/1f1e7-1f1ec.png"
 | 
			
		||||
    }
 | 
			
		||||
    "de-muc-1" = {
 | 
			
		||||
      name = "Munich - Germany"
 | 
			
		||||
      icon = "/emojis/1f1e9-1f1ea.png"
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
data "coder_parameter" "zone" {
 | 
			
		||||
  name         = "exoscale_zone"
 | 
			
		||||
  display_name = var.display_name
 | 
			
		||||
  description  = var.description
 | 
			
		||||
  default      = var.default == "" ? null : var.default
 | 
			
		||||
  mutable      = var.mutable
 | 
			
		||||
  dynamic "option" {
 | 
			
		||||
    for_each = { for k, v in local.zones : 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.zone.value
 | 
			
		||||
}
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue