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.
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.
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_ipandcreation_dateare 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.idis 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_onincludes a resource with pending changes is read during apply, so its attributes are unknown in the plan.
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 withterraform show tfplanfor a readable version. - JSON view:
terraform show -json tfplanexposesresource_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
idfrom a surprising attribute. - Replacement hints: a changed attribute marked
# forces replacementnext to a known-after-apply value means a new resource, and therefore new IDs, will cascade downstream.
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_eachon 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.
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_onon 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.
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
lifecyclecarefully:ignore_changescan hide an attribute from diffs, but it does not make an unknown value known. - Add preconditions: a
preconditionon 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.
- <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.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- 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.
- 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.
- 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.
- Ignoring unknowns on an existing attribute It usually means an upstream replacement is coming, which can destroy and recreate dependent resources.