Skip to content

feat(registry/coder/modules/aws-region): regions.json catalog, default_availability_zone output, optional parameter - #1138

Draft
phorcys420 wants to merge 12 commits into
mainfrom
phorcys/aws-region-availability-zone
Draft

phorcys420 wants to merge 12 commits into
mainfrom
phorcys/aws-region-availability-zone

Conversation

@phorcys420

@phorcys420 phorcys420 commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

Refactors aws-region into a data-driven catalog (following the aws-ec2-instance-type pattern), adds region/AZ outputs, makes the parameter optional, and keeps the region picker working under Coder dynamic parameters.

What changed

  • regions.json: generated catalog of {value, name, icon} per region, loaded with jsondecode so the module needs no AWS provider or credentials at plan time.
  • Icons live in the JSON: the flag emoji is baked into regions.json by the documented regenerate script; main.tf just reads region.icon, so there is no icon map in Terraform.
  • default_availability_zone output: resolves the selected region to a concrete zone (e.g. us-east-1a), replacing the "${region}a" guess the AWS templates do inline.
  • regions output: the full catalog keyed by region ID (name, icon, default_availability_zone).
  • create_parameter (default true): set false to skip the coder_parameter and use the outputs only; value falls back to var.default.
  • Dynamic parameters compatibility: the catalog is read with try(file("${path.module}/regions.json"), file("regions.json")) so options render under both Terraform and Coder's preview evaluator, which resolve file() relative to different base directories.
  • Input validation on default and exclude (region ID format).
  • Tests: main.tftest.hcl covers option rendering, outputs, exclude, custom names/icons, and the create_parameter toggle.
  • README documents the outputs, outputs-only usage, and regenerating regions.json via the AWS CLI.
  • Version bump 1.0.31 -> 1.1.0.

No breaking input changes. The new output is named default_availability_zone (it was not part of a prior release).

Testing

  • terraform test (10 runs) pass
  • terraform validate, terraform fmt, prettier, and the README validator are clean
  • Region options verified to render under coder/preview (radio, 28 options, icons sourced from the JSON) and via terraform apply
Implementation notes & decisions
  • regions.json (names and icons) was derived from the original main.tf region map, so names/icons are byte-identical; the eu grouping (all European regions share the EU flag) is preserved.
  • The README regenerate script is the single source of the flag logic: names come from the SSM longName parameter, the flag from SSM geolocationCountry (lowercased) converted to Coder's regional-indicator emoji asset, with eu-* regions forced to the shared EU flag. Terraform stays lightweight and only reads what the script emits.
  • default_availability_zone is computed as <region>a (every commercial AWS region exposes an a zone), matching what the AWS templates already do.
  • Dynamic parameters: Coder's preview resolves file() relative to the module directory while Terraform resolves it relative to the root module, so file("${path.module}/...") alone renders zero options under dynamic parameters. The try() fallback loads the file under both.
  • create_parameter = false uses the standard count toggle; the regions catalog output is always available.
  • Version bumped to 1.1.0 per CONTRIBUTING (feature = minor); latest release tag is v1.0.31.

Generated by Coder Agents on behalf of @phorcys420.

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Module Scorecard Check

coder/aws-region: 100 → 91

⚠️ Score regression: 100 → 91 (-9). Check the drilldown for which criteria dropped.

Theme Before After
Presentation & Onboarding 17 / 17 17 / 17
Integration — —
Credential Hygiene N/A 16 / 20
Restricted-Environment N/A N/A
Engineering Quality 10 / 10 10 / 10
Overall 100 / 100 91 / 100
Full scorecard for this PR
Presentation & Onboarding Credential Hygiene Restricted-Environment Readiness Engineering Quality Overall
17 / 17 16 / 20 N/A 10 / 10 91 / 100
Drilldown

Presentation & Onboarding — 17 / 17

Criterion Max Score Notes
Configuration-mode examples 12 12 Five documented examples cover every major mode: basic default selection, AZ output usage, create_parameter = false (outputs-only mode), custom_names/custom_icons overrides, and exclude filtering. Each example uses sensible defaults and is self-contained.
Visual preview 5 5 Three embedded images verified to exist: aws-regions.png (112.7 KB), aws-custom.png (52.8 KB), aws-exclude.png (56.2 KB).

Credential Hygiene — 16 / 20

Criterion Max Score Notes
Secrets marked sensitive 16 16 The module contains no sensitive inputs (no API keys, tokens, or credentials). All variables are non-sensitive configuration (region IDs, display names, icons, booleans). README examples contain no inline secrets. Vacuously satisfied.
Non-hardcoded auth path 4 0 The module performs no authentication and interacts with no external service that requires credentials. No README section documents an auth path (ServiceAccount, IAM, API key helper, etc.) because none is needed, but the criterion is not marked "if applicable" and no such path is demonstrated.

Restricted-Environment Readiness — N/A

All four criteria are N/A: the module downloads or installs nothing (it reads a local regions.json file via Terraform's file() function) and executes no scripts during deployment. The bash script in the README is a developer utility for regenerating the catalog, not part of the module's execution path.

Criterion Max Score Notes
Mirrorable artifact source 5 N/A No tool is downloaded or installed; regions.json is a local file read via file().
Bring-your-own binary 10 N/A No binary is downloaded or installed.
Egress transparency 3 N/A No external endpoints are contacted at install or runtime.
Runs without sudo 2 N/A No scripts execute during module deployment.

Engineering Quality — 10 / 10

Criterion Max Score Notes
Input quality 6 6 All 9 variables have clear description fields and sensible defaults. default and exclude include validation blocks with regex (^[a-z]{2}-[a-z]+-[0-9]+$) and descriptive error_message strings. create_parameter and mutable have appropriate boolean defaults.
Test coverage 4 4 main.tftest.hcl contains 10 test runs covering all business-logic paths: parameter name, order propagation, full-region option count, empty-default behavior, custom default, regions catalog output, exclusion, custom name/icon overrides, create_parameter = false mode, and the no-parameter/no-default edge case. Mix of plan and apply commands is appropriate. No TypeScript component exists (pure HCL module).

Overall — 91 / 100

Raw 43 / 47 → round(43 / 47 × 100) = 91

Tip

You can run this locally by telling your agent: "review this module against .github/scorecard/SCORECARD.md".


Scored against SCORECARD.md with solstice-1. Language-model scores are advisory.

…e flags, rename AZ output

- Move the flag emoji mapping into main.tf (flags map keyed by country);
  regions.json now stores value/name/country only.
- Rename output availability_zone -> default_availability_zone.
- Add create_parameter (default true); when false the picker is skipped and
  outputs fall back to var.default so admins can use the outputs only.
- Remove the terraform test file.
- Document how to regenerate regions.json via the AWS CLI.
@phorcys420 phorcys420 changed the title feat(registry/coder/modules/aws-region): store regions in regions.json and expose availability_zone feat(registry/coder/modules/aws-region): regions.json catalog, default_availability_zone output, optional parameter Sep 21, 2026
@phorcys420

Copy link
Copy Markdown
Member Author

just need to test

…parameters

Coder's dynamic parameters preview resolves file() relative to the module's own
directory, while Terraform resolves it relative to the root module. The previous
file("${path.module}/regions.json") therefore returned nothing under preview, so
the parameter rendered as a free-text input with no options.

Read the catalog with try(file("${path.module}/regions.json"), file("regions.json"))
so it loads under both engines. Verified with coder/preview (radio, 28 options)
and terraform apply.
…validation

Recover the module scorecard Engineering Quality points lost when the tests were
removed:

- Restore main.tftest.hcl covering options rendering, outputs, exclude, custom
  names/icons, and the create_parameter toggle (9 runs).
- Add self-contained validation to default and exclude (region ID format),
  compatible with terraform >= 1.0.
Use null instead of an empty-string sentinel for the default region:

- var.default now defaults to null and validates null or a region ID.
- coder_parameter reads default = var.default directly (no "" -> null shim).
- Add a test for create_parameter = false with no default (value null).
…names

The catalog mixed "EU (...)" and "Europe (...)" display names. Align every
European region to AWS's longName form ("Europe (...)"), which is what the
documented AWS CLI regeneration returns, so the names stay consistent and
reproducible.
The per-region field was named "country", but its value is a flag code such as
"eu" for the shared European flag, which is not a country. Rename it to "flag"
across regions.json, main.tf, the tests, and the README.
…ingle script

Replace the print-and-hand-edit steps with one script that writes regions.json
end to end: region names from the global-infrastructure longName SSM parameters,
and flag from the lowercased geolocationCountry (eu-* regions share the eu flag).
regions.json now stores only region ID and display name; the regeneration
script emits just those. main.tf derives each region's flag from its ID: a
region uses its geographic prefix's flag (us-*, eu-*, ...) with explicit entries
for the multi-country Asia Pacific and Middle East prefixes, then resolves the
emoji from flag_emojis. Verified options and icons render under coder/preview and
terraform apply.
Replace the flag_emojis + prefix_flags + region_flags + derived region_flag
machinery with a single region_icons map (region ID -> emoji) and a direct
lookup. Drops the redundant flag code field from the regions output; the icon is
the flag.

```tf
module "aws-region" {
module "aws_region" {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why _?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants