nerdexam
HashiCorp

TA-002-P · Question #223

During a terraform apply, a resource is successfully created but eventually fails during provisioning. What happens to the resource?

The correct answer is A. The resource will be planned for destruction and recreation upon the next terraform apply. If a creation-time provisioner fails, the resource is marked as tainted. A tainted resource will be planned for destruction and recreation upon the next terraform apply. Terraform does this because a failed provisioner can leave a resource in a semi-configured state. Because…

Use the Terraform CLI (terraform plan, apply, destroy, fmt, init, validate, workspace, import, taint, providers, output)

Question

During a terraform apply, a resource is successfully created but eventually fails during provisioning. What happens to the resource?

Options

  • AThe resource will be planned for destruction and recreation upon the next terraform apply
  • BTerraform will retry to provision again.
  • CThe failure of provisioner will be ignored and it will not cause a failure to terraform apply
  • DThe resource will be automatically destroyed.

How the community answered

(28 responses)
  • A
    89% (25)
  • B
    7% (2)
  • C
    4% (1)

Explanation

If a creation-time provisioner fails, the resource is marked as tainted. A tainted resource will be planned for destruction and recreation upon the next terraform apply. Terraform does this because a failed provisioner can leave a resource in a semi-configured state. Because Terraform cannot reason about what the provisioner does, the only way to ensure proper creation of a resource is to recreate it. This is tainting. You can change this behavior by setting the on_failure attribute, which is covered in detail below.

Topics

#terraform apply#provisioners#resource lifecycle#error handling

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice