TA-002-P · Question #6
You run a local-exec provisioner in a null resource called null_resource.run_script and realize that you need to rerun the script. Which of the following commands would you use first?
The correct answer is A. terraform taint null_resource.run_script. To force a local-exec provisioner within a null_resource to rerun, you must first taint the resource, marking it for recreation on the next apply.
Question
You run a local-exec provisioner in a null resource called null_resource.run_script and realize that you need to rerun the script. Which of the following commands would you use first?
Options
- Aterraform taint null_resource.run_script
- Bterraform apply -target=null_resource.run_script
- Cterraform validate null_resource.run_script
- Dterraform plan -target=null_resource.run_script
How the community answered
(62 responses)- A71% (44)
- B10% (6)
- C3% (2)
- D16% (10)
Why each option
To force a `local-exec` provisioner within a `null_resource` to rerun, you must first `taint` the resource, marking it for recreation on the next `apply`.
`terraform taint` marks a resource as tainted, signaling to Terraform that it must be destroyed and recreated on the next `terraform apply`. For a `null_resource` with a `local-exec` provisioner, tainting it ensures the provisioner script is executed again during the recreation process.
`terraform apply -target` would try to apply changes to the resource if any are pending, but it won't force a rerun of a `local-exec` provisioner without the resource first being tainted or otherwise marked for recreation.
`terraform validate` checks configuration syntax and semantics, but it does not modify the state or force resources to be rerun or recreated.
`terraform plan -target` would show what changes *would* occur for that specific resource, but without tainting it, it wouldn't show a rerun of a `local-exec` provisioner unless other changes to the resource triggered it.
Concept tested: Rerunning Terraform provisioners (taint)
Source: https://developer.hashicorp.com/terraform/cli/commands/taint
Topics
Community Discussion
No community discussion yet for this question.