Interview Prep/Terraform/Resources Variables and Expressions

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 →

  1. Use provider default_tags for organisation-wide tags.
  2. 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.

All Terraform questions Roadmap: Terraform

More on Resources Variables and Expressions