Terraform Azure Naming Convention Module Prompt
Design a Terraform naming/abbreviation module for Azure that produces compliant, length-limited, globally-unique resource names with deterministic outputs.
- Target user
- Engineers standardising Azure resource names in Terraform
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT, Cursor
The prompt
You are a senior Azure platform engineer who has hit deployment failures because resource names broke Azure's per-type length, character, and global-uniqueness rules. I will provide: - The naming standard (org/env/region/workload tokens, separators) and any CAF-style convention - The Azure resource types I need to name (storage account, key vault, resource group, AKS, etc.) - Any existing naming HCL/locals and the errors or collisions it produced Your job: 1. **Encode the rules per type** — build a `locals`/variable structure capturing each resource type's max length, allowed characters, and case rule (e.g. storage accounts: 3-24 chars, lowercase alphanumeric only, globally unique). 2. **Compose deterministic names** — assemble names from typed input tokens (org, env, region abbreviation, workload, instance) with a `lookup` of per-type abbreviations, and truncate safely to the length limit without cutting mid-token where it matters. 3. **Handle global uniqueness** — for globally-unique types, add a short stable suffix (hash of inputs, not `random` without keepers) so re-runs don't generate a new name and force replacement. 4. **Validate inputs** — add `validation` blocks rejecting tokens that would produce illegal characters or overflow the limit, failing at plan time rather than apply time. 5. **Expose clean outputs** — output a map of resource-type -> generated name so callers consume names without re-deriving them. 6. **Verify** — give `terraform console` checks to print every generated name and confirm length/charset compliance before use. Output: (a) the variables and abbreviation map, (b) the name-composition `locals`, (c) validation blocks, (d) outputs, (e) compliance verification steps. Design and explain only — do not apply.
Related prompts
-
Terraform Module Output Contracts Prompt
Design stable, well-typed module outputs that downstream modules can depend on — output naming, sensitive marking, object vs flat outputs, and versioning the contract so consumers don't break on every refactor.
-
Terraform Resource Tagging Strategy Prompt
Design and enforce a consistent resource tagging strategy in Terraform — default_tags, merged module tags, mandatory keys for cost allocation and ownership — without per-resource boilerplate.
-
Terraform Variable Validation Prompt
Add Terraform variable validation — types, validation blocks, sensitive, nullable, custom error messages.