Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam Terraform Associate All Questions

View all questions & answers for the Terraform Associate exam

Exam Terraform Associate topic 1 question 6 discussion

Actual exam question from HashiCorp's Terraform Associate
Question #: 6
Topic #: 1
[All Terraform Associate Questions]

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?

  • A. terraform taint null_resource.run_script
  • B. terraform apply -target=null_resource.run_script
  • C. terraform validate null_resource.run_script
  • D. terraform plan -target=null_resource.run_script
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
alirasouli
Highly Voted 2 years ago
As discussed, the `taint` command used to be the right choice; however, it is deprecated. The right answer is: terraform apply -replace="null_resource.run_script" Reference: https://developer.hashicorp.com/terraform/cli/commands/taint
upvoted 37 times
...
Sproket
Highly Voted 2 years, 4 months ago
Selected Answer: A
You are all correct that taint has been deprecated and replaced with -replace. But neither D nor any other option here uses the -replace command. Therefore option A is the only valid option given these choices.
upvoted 18 times
Pietjeplukgeluk
1 year, 9 months ago
Not so sure, read Arrash his comment below. If a provisioner fails, it would be marked as tained by default without any user interaction required. This only leaves the apply as a required step....
upvoted 3 times
...
...
Nunyabiznes
Most Recent 1 month, 4 weeks ago
The correct answer is A. terraform taint null_resource.run_script. This command marks the null resource as tainted, which means that Terraform considers the resource to be out-of-date and will recreate it during the next terraform apply run. When Terraform recreates the null resource, it will also rerun the local-exec provisioner. Option B, terraform apply -target=null_resource.run_script, would work, but it is overkill because it would apply all the resources in the configuration, not just the null resource with the local-exec provisioner. Option C, terraform validate null_resource.run_script, only checks the syntax of the configuration, and does not affect the state of the resource. Option D, terraform plan -target=null_resource.run_script, generates a plan for applying changes to the configuration, but does not apply those changes, so it would not rerun the local-exec provisioner.
upvoted 3 times
...
Bere
1 month, 4 weeks ago
Selected Answer: A
1) Create main.tf: terraform { required_version = ">= 0.13" } resource "null_resource" "run_script" { provisioner "local-exec" { command = "echo 'Hello, Terraform!' > example.txt" } } 2) terraform init 3) terraform apply 4) Modify the content of the example.txt file manually or delete it. 5) terraform taint null_resource.run_script 6) terraform apply The local-exec provisioner should now run again, and the example.txt file will be recreated with the content specified in the command of the local-exec provisioner block. As described here: https://developer.hashicorp.com/terraform/cli/commands/taint This command is deprecated. For Terraform v0.15.2 and later, we recommend using the -replace option with terraform apply instead But there is no option that uses the -replace command, so option A as described in my step 5 is the only valid option.
upvoted 2 times
...
reynaldiekoz
3 months ago
Selected Answer: A
im sureee
upvoted 1 times
...
hrajkuma
4 months, 1 week ago
it is option -> A for sure
upvoted 1 times
...
090200f
4 months, 2 weeks ago
Warning: This command is deprecated. For Terraform v0.15.2 and later, we recommend using the -replace option with terraform apply instead, So { $ terraform apply -replace="aws_instance.example[0]" } but there is no like this apply -replace option in the mentioned options so answer is A : terraform taint ..........
upvoted 1 times
...
enklau
4 months, 2 weeks ago
thats right
upvoted 1 times
...
gofavad926
1 year, 1 month ago
Selected Answer: A
A. However taint command is deprecated now and we should use terraform apply -destroy
upvoted 2 times
...
ledjo
1 year, 2 months ago
Selected Answer: A
terraform apply -replace is missing here, therefore the only valid answer, even if deprecated as a command, is the first one A.
upvoted 2 times
...
BaburTurk
1 year, 3 months ago
Selected Answer: B
B. terraform apply -target=null_resource.run_script Running the terraform apply -target=null_resource.run_script command will specifically target the null_resource.run_script resource and execute its provisioner again. This is useful when you want to rerun the local-exec provisioner without affecting other resources.
upvoted 3 times
...
Jayanth
1 year, 3 months ago
A. terraform taint null_resource.run_script
upvoted 1 times
...
Busi57
1 year, 4 months ago
Selected Answer: A
I think A
upvoted 1 times
...
nebulabc
1 year, 4 months ago
To rerun the script defined in the local-exec provisioner of a null resource called null_resource.run_script, you can use the terraform apply command with the -target flag to specifically target the null resource. This command instructs Terraform to only apply changes to the specified target resource, which in this case is the null_resource.run_script. It will re-run the local-exec provisioner associated with that null resource.
upvoted 1 times
nebulabc
1 year, 4 months ago
So, B is correct.
upvoted 1 times
...
...
Ni33
1 year, 6 months ago
Selected Answer: A
A is correct
upvoted 2 times
...
FarziWaliMarzi
1 year, 7 months ago
Selected Answer: A
I think point to note is "you realize that you need to rerun the script". It is NOT talking about failure. So marking it taint is the only right option, so that on next run, it can be deleted and recreated.
upvoted 2 times
aanataliya
1 year, 2 months ago
you dont need to taint to re run script in local-exec provisioner with null resource. reference: https://jhooq.com/terraform-null-resource/
upvoted 1 times
...
...
Power123
1 year, 7 months ago
terraform apply -replace="null_resource.run_script" Ans: A
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...