What is the Terraform lifecycle of a resource?
Answer
A Terraform resource goes through these lifecycle phases. Plan: Terraform reads current state, calls provider APIs to get actual resource state, and computes the diff with desired configuration. Generates a plan showing required actions. Apply - Create: provider plugin calls cloud API to create the resource. Terraform writes the new resource to state with its ID and attributes. Apply - Update in-place: provider API calls are made to modify specific attributes. State is updated. Apply - Destroy and recreate: some attributes require destroying and recreating (immutable parameters). Old resource is destroyed, new one created. create_before_destroy = true inverts the order. Apply - Destroy: cloud API called to delete the resource. State entry is removed. Read (Refresh): Terraform reads current resource state from the cloud API to detect drift. Understanding when update-in-place vs recreate happens is critical for managing production resources safely.
Previous
What is the Terraform provider version constraint syntax?
Next
What is Packer and how does it relate to Terraform?
More Terraform / IaC Questions
View all →- Intermediate What is the Terraform state locking mechanism?
- Intermediate How do you handle sensitive values in Terraform?
- Intermediate What are Terraform Provisioners and when should you avoid them?
- Intermediate What is Terraform import?
- Intermediate How do you structure Terraform code for large teams?