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?
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?
To rerun the script in a local-exec provisioner within a null resource in Terraform, you should use the command 'terraform taint null_resource.run_script'. This command marks the specified resource as tainted, which forces Terraform to consider it as requiring replacement during the next apply phase. When you subsequently run 'terraform apply', Terraform will recreate the null resource and rerun the provisioner script. While 'terraform taint' is deprecated in favor of 'terraform apply -replace', 'terraform taint' remains the correct choice among the given options for rerunning the script.
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
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.
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....
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.
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.
A. However taint command is deprecated now and we should use terraform apply -destroy
terraform apply -replace is missing here, therefore the only valid answer, even if deprecated as a command, is the first one 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.
A is correct
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.
you dont need to taint to re run script in local-exec provisioner with null resource. reference: https://jhooq.com/terraform-null-resource/
it is option -> A for sure
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 ..........
thats right
A. terraform taint null_resource.run_script
I think A
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.
So, B is correct.
terraform apply -replace="null_resource.run_script" Ans: A
(1/3) Answer should be B. The first thing to realise is that the question is testing failure behaviour of provisioners. Hence the need of re-running the script.
(2/3)= This is my understanding: By default, provisioners that fail will also cause the Terraform apply itself to fail. The 'on_failure' setting can be used to change this. The allowed values are: • continue - Ignore the error and continue with creation or destruction. -This also means if there are multiple commands clubbed [ using & in Windows or ; in Linux] ( in the inline or command argument) or multiple provisioners following, they will execute. -Also, other following terraform resources(based on computed dependencies) will continue to get created/destroyed. • fail - Raise an error and stop applying OR destroying (the default behaviour). >If this is a creation provisioner, taint the resource. >Destroy provisioners are run before the resource is destroyed. If they fail, Terraform will error and rerun the provisioners again on the next terraform apply. Due to this behavior, care should be taken for destroy provisioners to be safe to run multiple times.
(3/3) -This also means if there are multiple commands clubbed [ using & in Windows or ; in Linux] ( in the inline or command argument) or multiple provisioners following, they will NOT execute. -Also, other following terraform resources(based on computed dependencies) will NOT get created/destroyed == With no specific input on 'on_failure', the default action is 'fail'-ie either taint the resource(creation time provisioner) or AUTOMATIC re-run of provisioner block(destroy time provisioner). In both cases, simple 'terraform apply'(with target flag perhaps) is sufficient to re run the script.