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.
- Target user
- Cloud engineers standardizing tags for cost, ownership, and compliance
- Difficulty
- Beginner
- Tools
- Claude, ChatGPT
The prompt
You are a cloud cost and governance engineer. Help me design a tagging strategy in Terraform that is consistent, enforced, and low-boilerplate. I will provide: - Cloud provider(s) and which tag-supporting resources we use - Current ad-hoc tags (if any) and the mess we want to fix - Mandatory dimensions (cost center, owner, environment, app, data-classification) - Tooling (provider version, CI, policy engine) Your job: 1. **Tag taxonomy** — define a canonical key set with naming rules (case, allowed values, format), separating mandatory keys from optional ones, and a value vocabulary (e.g. allowed `environment` values) to prevent "prod"/"Production"/"prd" drift. 2. **Provider default_tags** — use the AWS provider `default_tags` block (or equivalent) to apply org-wide tags once, and explain which resource types ignore default_tags so I know where I still need explicit tags. 3. **Module-level merge pattern** — show a `locals` + `merge()` pattern that combines org defaults, module-level tags, and caller-supplied `var.tags`, with a clear precedence order. Avoid repeating `tags =` on every resource where possible. 4. **Mandatory-key validation** — add `variable` validation (or a precondition) that fails the plan if any mandatory tag key is missing or has a disallowed value. 5. **Policy enforcement** — provide a Conftest/OPA or Checkov rule that scans the plan JSON and rejects resources missing required tags, as a backstop to in-code validation. 6. **Cost allocation wiring** — note which tags must be activated as cost-allocation tags in billing, and the lag before they appear in cost reports. 7. **Remediation** — a plan to backfill tags on existing resources: a query to find untagged resources and a safe `terraform plan` approach that adds tags without recreating resources. Output as: (a) the tag taxonomy doc, (b) the provider default_tags + locals/merge pattern, (c) variable validation rules, (d) the policy-as-code rule, (e) a backfill remediation plan. Bias toward: tags applied once at the provider/module level, a controlled value vocabulary, validation that fails fast.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Terraform GitHub Org Management Module Prompt
Manage a GitHub organization as code with repos, teams, memberships, and branch protection via for_each, importing existing repos safely.
-
Terraform TFLint Custom Ruleset Authoring Prompt
Author a custom TFLint ruleset — .tflint.hcl config, the terraform + aws bundled rulesets, and Go rules built on the TFLint plugin SDK to enforce naming conventions and required tags, then wire it into pre-commit and CI.
-
Terraform Aliased Provider Passing to Nested Modules Prompt
Wire aliased providers (multi-region, multi-account) down through nested module trees using explicit `configuration_aliases` and `providers = {}` maps instead of implicit inheritance.
-
Terraform Policy Bundle Rollout Strategy Prompt
Plan the staged, versioned rollout of a policy-as-code bundle (Sentinel/OPA/conftest) across many Terraform workspaces and teams — moving rules from advisory to soft-mandatory to hard-mandatory without blocking delivery or causing mass plan failures.
More Terraform prompts & error guides
Browse every Terraform prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.