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.