Terraform Associate Exam QuestionsBrowse all questions from this exam

Terraform Associate Exam - Question 207


While deploying a virtual machine, the first launch user_data script fails due to race condition with another resource deployed during the same Terraform run.

What is the least disruptive method to correct the issue?

Show Answer
Correct Answer: C

Running terraform apply again is the least disruptive method to address the issue. This command will attempt to apply the changes and create the resources defined in the configuration, including the virtual machine and its user_data script. It allows Terraform to retry operations that might have failed due to a race condition, without marking any resources as tainted or destroying other dependencies, ensuring minimal disruption to the overall deployment process.

Discussion

14 comments
Sign in to comment
zaaath
Apr 13, 2023

I'd go with A. If a user_data script fails during the creation of an EC2 instance, Terraform will not mark the resource as tainted automatically. This is because Terraform does not have visibility into the success or failure of the user_data script, as it is executed within the instance itself, and not directly controlled by Terraform. However, if the user_data script failure causes the instance to become unresponsive or otherwise unusable, Terraform may detect this during a subsequent plan or apply operation and mark the instance as "tainted". A tainted resource is one that Terraform cannot verify the current state of, and must be recreated in order to bring it back to a known state.

MantisOption: A
May 5, 2023

The script deployment will not have been tracked within Terraform - and will therefore not re-run on the next 'apply' command. The resource the script is running on will have to be redeployed to trigger the script to run a second time - the least disruptive way do achieve this is with the 'taint' command

NunyabiznesOption: C
Apr 7, 2023

if it fails, you just re-run terraform apply again , why even run taint for something that didn't even got created in the first place. For example, you're trying to create Resource A, but it fails because resource B was being created. So what do you do to create resource A again ? - terraform apply

Oleg_golOption: C
May 6, 2023

C. Run terraform apply again

ArizonaClassics
Jan 14, 2023

I will go for A

Abuu
Jan 20, 2023

A is the Answer since the particular object has become degraded or damaged and Terraform taint will propose to replace it in the next plan you create.

Pietjeplukgeluk
Feb 14, 2023

The question leaves room for interpretation. If a creation-time provisioner fails, the resource is marked as tainted. A tainted resource will be planned for destruction and recreation upon the next terraform apply. https://developer.hashicorp.com/terraform/language/resources/provisioners/syntax

David_C_90
Mar 14, 2023

The question states user_data not provisioners...

campsOption: A
Mar 31, 2023

In this scenario, the user_data script failed due to a race condition with another resource being deployed simultaneously during the same Terraform run. The least disruptive method to correct the issue is to use the terraform taint command followed by terraform apply. Running terraform taint against the virtual machine's resource name marks the resource as tainted. Tainting a resource indicates that it has a problem and should be destroyed and recreated during the next terraform apply. By doing this, you force Terraform to recreate the virtual machine with the corrected user_data script, resolving the race condition without affecting other resources.

Ni33
May 10, 2023

A is correct

alex78Option: C
Jan 28, 2024

If a creation-time provisioner fails, the resource is marked as tainted. A tainted resource will be planned for destruction and recreation upon the next terraform apply. https://developer.hashicorp.com/terraform/language/resources/provisioners/syntax

F_M
Aug 30, 2024

We're not talking about provisioners but user_data a.k.a. cloud init.

gplusplusOption: C
Jan 7, 2025

should be already tainted

March2023Option: A
Jun 17, 2023

going with A

lavendran93Option: C
Sep 12, 2024

A. Run terraform taint: This would force the virtual machine to be destroyed and recreated, which is more disruptive than reapplying. I think B

chessmaster5000Option: A
Mar 22, 2025

You can mark the resource as tainted using terraform taint, which tells Terraform that the resource is bad and needs to be destroyed. Then run terraform apply to surgically fix the broken VM instead of terraform destroy which would tear down everything.