You need to prove an expression works before editing a large config. What do you use?
BeginnerScenarioResources Variables and Expressions
Answer
Situation read → You don't want to apply to learn what cidrsubnet or a for expression returns.
What I'd do → Use terraform console.
$ terraform console
> cidrsubnet("10.0.0.0/16", 8, 3)
"10.0.3.0/24"
> { for k, v in var.subnets : k => upper(v) }
> exit
Why → It evaluates expressions against your real variables and, with state, resource attributes, without changing anything.
Interview tip → Pipe expressions in non-interactively: echo 'length(var.azs)' | terraform console.
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