Terraform Plan shows changes that are not applied.
Last updated: November 7, 2024
Issue: Plan Shows Changes That Are Not Applied
Symptom: A Terraform plan suggests several changes, but fewer changes are actually made during the apply phase. For example, the plan might indicate "4 to change," but after applying, it only reports "1 changed."
This article explains a possibility for this discrepancy occurs and how to interpret it accurately.
Possible Cause: "Known After Apply" Attributes
In Terraform, certain resource attributes are "known after apply," meaning their final values or states cannot be fully determined until after the apply phase. This can lead to scenarios where Terraform's plan phase identifies potential changes, but the apply phase realizes fewer adjustments are necessary.
For example:
During the planning phase, Terraform may suggest changes for resources where it cannot yet confirm the final state.
Upon applying, Terraform might detect that these resources do not require modification after all, resulting in fewer changes.
This is a common behavior when working with resources that depend on external conditions or attributes that are not fixed until runtime.
Example Scenario
Imagine you see a plan output like this:
..
- aws_security_group.my_sg will be updated
egress.#: "0" => "1" (known after apply)
ingress.#: "0" => "1" (known after apply)
- aws_instance.my_instance will be updated
private_ip: "" => (known after apply)
public_ip: "" => (known after apply)
..
Plan: 0 to add, 4 to change, 0 to destroy.After running, the output might show:
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.In this case, Terraform initially anticipated potential changes but recognized that only one resource truly required an update.
Additional Reference
For further information and user discussions on this topic, check out this helpful discussion on the Terraform forum, where users share similar experiences with varying plan and apply outputs.
Summary
This discrepancy is normal when working with "known after apply" attributes. Understanding this behavior can help avoid confusion when the plan and apply phases display differing outputs.
If you continue to see unexpected results or have specific questions, feel free to reach out to Spacelift Support for further assistance.