⚡ ~/naveed Interview Prep
⚡ Portfolio Home 👤 About Naveed Bio & Credentials 📫 Contact Naveed Get In Touch ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
← Back to All Terraform & IaC Interview Questions Scenario 57 of 120 in Terraform & IaC
Senior DevOps / SRE [L2] Terraform Terraform Modules & State Production Scenario [L2]
🎯 Target Role / Context: Terraform Scenario #52 (L2) · Use VPC ID from another module

Q: A Terraform resource shows as `(known after apply)` for an attribute. What does this mean?

(known after apply) in a Terraform plan means the value cannot be computed until the provider creates or changes the resource, for example an ARN, an ID, or a generated IP. It is normal for new resources and usually harmless.

#Terraform #L2 #IaC #Cloud Infrastructure
🎙️ Candidate Opening & Architectural Context
"<strong>(known after apply)</strong> in a Terraform plan means the value cannot be computed until the provider creates or changes the resource, for example an ARN, an ID, or a generated IP. It is normal for new resources and usually harmless. It becomes a problem when an unknown value feeds something Terraform must know at plan time, such as <code>count</code> or <code>for_each</code>. Interviewers use this question to see whether you understand the plan and apply phases, can read a plan critically, and know how to restructure code that depends on unknowns."
Advertisement
⚡ Recommended Practice Lab

Want to master this scenario in a live sandbox? KodeKloud's HashiCorp Certified Terraform Associate (003) Interactive Labs covers this exact problem with hands-on terminal drills.

🛠️ Production Runbook & Step-by-Step Resolution

Direct Answer: <strong>(known after apply)</strong> in a Terraform plan means the value cannot be computed until the provider creates or changes the resource, for example an ARN, an ID, or a generated IP. It is normal for new resources and usually harmless. It becomes a problem when an unknown value feeds something Terraform must know at plan time, such as <code>count</code> or <code>for_each</code>. Interviewers use this question to see whether you understand the plan and apply phases, can read a plan critically, and know how to restructure code that depends on unknowns.

1️⃣

Mental model: why a value is (known after apply)

Terraform builds a plan from configuration and prior state, and every attribute is either known, or unknown until a provider returns it.

  • Computed by the provider: attributes such as id, arn, public_ip and creation_date are assigned by the remote API, so a plan for a new resource must show them as unknown.
  • Derived values: anything built from an unknown value is also unknown. An output that interpolates aws_instance.web.id is unknown until the instance exists.
  • On updates: an attribute that previously had a value and now shows -> (known after apply) means an upstream change will recompute it. Find the upstream change; do not assume a bug.
  • Deferred data sources: a data source whose depends_on includes a resource with pending changes is read during apply, so its attributes are unknown in the plan.
2️⃣

Hands-on: read the plan and the JSON for unknown attributes

The human-readable plan tells you what changes; the JSON plan tells you exactly which fields are unknown.

terraform plan -out=tfplan
terraform show tfplan | grep -n "known after apply"

terraform show -json tfplan \
  | jq -r '.resource_changes[]
           | select(.change.after_unknown != {})
           | [.address, (.change.after_unknown | keys | join(","))] | @tsv'
  • Save the plan: terraform plan -out=tfplan, then render it with terraform show tfplan for a readable version.
  • JSON view: terraform show -json tfplan exposes resource_changes[].change.after_unknown, a map marking each attribute that will be computed.
  • Filter with jq: list only resources whose planned change contains unknowns, to separate the harmless id from a surprising attribute.
  • Replacement hints: a changed attribute marked # forces replacement next to a known-after-apply value means a new resource, and therefore new IDs, will cascade downstream.
Advertisement
3️⃣

Failure mode: unknown values in for_each and count

The error that actually blocks teams is Invalid for_each argument ... cannot be determined until apply.

# Bad: keys depend on a value known only after apply
resource "aws_route53_record" "bad" {
  for_each = toset([aws_instance.web.public_ip])
  ...
}

# Good: static keys, unknown value used only as the value
locals { records = { web = "www" } }

resource "aws_route53_record" "ok" {
  for_each = local.records
  name     = "${each.value}.example.com"
  records  = [aws_instance.web.public_ip]  # unknown is fine here
  ...
}
  • Why it happens: Terraform must know the full set of instance keys at plan time to build the graph. Keys derived from a resource ID or ARN created in the same run are unknown, so planning fails.
  • Fix by design: key for_each on static values such as names from a variable or a map literal, and put the unknown value in the map's value instead of its key.
  • Split the stack: if the keys truly come from another resource, create that resource in a separate root module or layer and read it back with a data source or remote state.
  • Last resort: a two-phase terraform apply -target=... works, but it is a workaround that leaves your configuration unable to converge from scratch; document it or remove the dependency.
Pro Tip: Unknown values are allowed in resource arguments, but not in <code>count</code>, <code>for_each</code>, provider configuration blocks that need them to authenticate, or <code>backend</code> settings.
4️⃣

Troubleshooting unexpected (known after apply) on an update

When a stable attribute suddenly turns unknown on an existing resource, work through the cause in order.

  • Upstream replacement: check whether a dependency shows must be replaced. The new object will get a new ID, so every reference becomes unknown.
  • Provider computed fields: some attributes are recomputed whenever a sibling argument changes, for example a policy document hash or a rendered user data. Confirm with the JSON plan.
  • Data source timing: remove unnecessary depends_on on a data source, since it forces deferral. Prefer implicit dependencies by reference.
  • Module outputs: a module output built from an unknown value is unknown to every caller, so one deep change can ripple across stacks.
5️⃣

Prevention and review habits

Make unknowns visible in review so they are explained rather than discovered at apply time.

  • Review the plan, not the diff: reviewers should read the planned output, specifically for replacements that turn many values unknown.
  • Use lifecycle carefully: ignore_changes can hide an attribute from diffs, but it does not make an unknown value known.
  • Add preconditions: a precondition on a variable catches bad inputs before they create unresolvable graphs.
  • Keep layers small: separate network, identity and workload stacks so a replacement in one does not make the next unknown.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: Treat <code>(known after apply)</code> on a brand-new resource as normal, but treat it on an existing attribute as a signal to trace upstream for a replacement, and use <code>terraform show -json</code> with <code>after_unknown</code> to prove it."
⚡ 60-Second Elevator Pitch Talking Points
  • <code>(known after apply)</code> means the provider computes the value during apply, such as an ID or ARN, so the plan cannot know it yet.
  • I verify with <code>terraform show -json</code> and the <code>after_unknown</code> field, and trace unexpected unknowns to an upstream replacement.
  • I design configurations with static <code>for_each</code> keys so unknown values only appear as map values, never as keys or counts.
⛔ Critical Candidate Mistakes to Avoid in This Scenario

Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:

  1. Keying <code>for_each</code> on a resource ID or IP created in the same apply Terraform needs all keys at plan time, so it errors out; use static keys and put the unknown in the value.
  2. Fixing unknown-value errors permanently with <code>-target</code> It hides a graph design problem, and a fresh environment cannot be built with a single apply.
  3. Adding <code>depends_on</code> to data sources out of habit It defers the read to apply time and turns the data source's attributes unknown across the plan.
  4. Ignoring unknowns on an existing attribute It usually means an upstream replacement is coming, which can destroy and recreate dependent resources.
Advertisement
Want more Terraform & IaC scenarios?
Explore our complete collection of scenario-based Terraform & IaC interview runbooks.
Browse All Terraform & IaC Questions →