Every resource needs a base set of tags plus its own. How do you combine them cleanly?
BeginnerScenarioResources Variables and Expressions
Answer
Situation read → Tag drift and inconsistent tagging.
What I'd do →
- Use provider
default_tagsfor organisation-wide tags. - Use
merge()for resource-specific additions.
resource "aws_s3_bucket" "logs" {
bucket = "${local.name_prefix}-logs"
tags = merge(local.common_tags, { DataClass = "internal" })
}
Why → default_tags applies uniformly with no per-resource code; merge handles the cases that need extras. Later maps override earlier keys.
Interview tip → Not every resource supports tags, so I validate coverage with a policy check rather than trusting convention.
More on Resources Variables and Expressions
You need three identical web servers. How do you declare them, and what is the catch with `count`?BeginnerYou manage subnets from a list of CIDRs. Someone removes the second CIDR and Terraform plans to recreate the third subnet. Why, and what do you change?IntermediateHow do you stop someone passing `environment = "production"` when only `dev`, `stage` and `prod` are valid?BeginnerA module takes a database password and exposes the connection string as an output. How do you stop them leaking into plan output?BeginnerA monitoring stack should only exist in prod. How do you create a resource conditionally?BeginnerYou have subnets defined as `{ web = {...}, db = {...} }` per VPC, nested two levels deep. How do you create them with `for_each`?Advanced