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 (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
alirasouli
Highly Voted 2 years, 4 months 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 38 times
...
Sproket
Highly Voted 2 years, 8 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
2 years 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
...
...
eLJoudi
Most Recent 1 week, 2 days ago
Selected Answer: A
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"
upvoted 1 times
...
YesPlease
1 month, 1 week ago
Selected Answer: D
"taint" is deprecated, so this is WRONG "validate" does not have any options to target files and checks all config files for syntax, so this is WRONG So that leaves APPLY and PLAN....the question is asking which will you run *FIRST*. Terraform BEST-PRACTICES always wants you to run PLAN before APPLY so that you know exactly what changes will happen and this ensures that you understand and approve the intended changes.
upvoted 1 times
...
palashpal
1 month, 3 weeks ago
Selected Answer: A
As the resource is already present in the state file, so terraform will display message No changes. Your infrastructure matches the configuration. But with taint options, terraform will recreate the resource in next apply as shown below. terraform taint null_resource.run_script Resource instance null_resource.run_script has been marked as tainted. # terraform apply null_resource.run_script: Refreshing state... [id=1726701550426365360] Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: -/+ destroy and then create replacement Terraform will perform the following actions: # null_resource.run_script is tainted, so must be replaced -/+ resource "null_resource" "run_script" { ~ id = "1726701550426365360" -> (known after apply) } Plan: 1 to add, 0 to change, 1 to destroy. Hence option A is correct
upvoted 1 times
...
Nunyabiznes
5 months, 2 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
prabdarq
3 months, 2 weeks ago
Hi @Nunyabiznes.... You are right, The correct answer is A. But I would like to clarify the reason as to why Option B wont work. Terraform apply will get executed, But no changes will be made, as they were already run. As we need to rerun the script taint/replace has to be used. Kindly let me know if my understanding is correct
upvoted 1 times
...
...
Bere
5 months, 2 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
6 months, 3 weeks ago
Selected Answer: A
im sureee
upvoted 1 times
...
hrajkuma
8 months ago
it is option -> A for sure
upvoted 1 times
...
090200f
8 months 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
8 months, 1 week ago
thats right
upvoted 1 times
...
gofavad926
1 year, 5 months ago
Selected Answer: A
A. However taint command is deprecated now and we should use terraform apply -destroy
upvoted 2 times
...
ledjo
1 year, 6 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, 6 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, 7 months ago
A. terraform taint null_resource.run_script
upvoted 1 times
...
Busi57
1 year, 7 months ago
Selected Answer: A
I think A
upvoted 1 times
...
nebulabc
1 year, 8 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, 8 months ago
So, B is correct.
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 ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago