nerdexam
HashiCorp

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.

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

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)
  • A
    71% (44)
  • B
    10% (6)
  • C
    3% (2)
  • D
    16% (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`.

Aterraform taint null_resource.run_scriptCorrect

`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.

Bterraform apply -target=null_resource.run_script

`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.

Cterraform validate null_resource.run_script

`terraform validate` checks configuration syntax and semantics, but it does not modify the state or force resources to be rerun or recreated.

Dterraform plan -target=null_resource.run_script

`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

#terraform taint#provisioners#null_resource#resource lifecycle

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice