TERRAFORM-ASSOCIATE-004 · Question #263
During a terraform apply, a resource is successfully created but eventually fails during provisioning. What happens to the resource?
The correct answer is D. the resource is marked as tainted. If a Terraform resource is successfully created but then fails during its provisioning stage, the resource is marked as 'tainted' in the state file.
Question
Options
- ATerraform attempts to provision the resource up to three times before exiting with an error
- Bit is automatically deleted
- Cthe terraform plan is rolled back and all provisioned resources are removed
- Dthe resource is marked as tainted
How the community answered
(44 responses)- A5% (2)
- C2% (1)
- D93% (41)
Why each option
If a Terraform resource is successfully created but then fails during its provisioning stage, the resource is marked as 'tainted' in the state file.
Terraform does not automatically retry resource provisioning attempts; upon failure, the resource is marked as tainted, requiring manual intervention or a subsequent apply.
Terraform does not automatically delete a resource that failed during provisioning; instead, it marks the resource as tainted so it can be re-evaluated and potentially replaced on the next apply.
Terraform does not automatically roll back an entire plan or remove all provisioned resources if a single resource's provisioner fails; only the failed resource is marked as tainted.
If a resource is successfully created but its associated provisioner fails, Terraform marks that resource as 'tainted' in the state file, signaling that it is in an inconsistent state and will be destroyed and recreated on the subsequent `terraform apply`.
Concept tested: Terraform resource provisioning failure
Source: https://developer.hashicorp.com/terraform/language/resources/provisioners/syntax#failure-behavior
Topics
Community Discussion
No community discussion yet for this question.