What happens when a Terraform provisioner fails during resource creation?
Terraform marks the resource as tainted and stops the apply process unless you use the 'ignore_errors' option. This means the resource will be destroyed and recreated on the next apply.
Click to reveal answer
intermediate
What is the purpose of the 'on_failure' argument in Terraform provisioners?
The 'on_failure' argument controls what Terraform does if the provisioner fails. Options include 'fail' (default), 'continue', and 'warn'.
Click to reveal answer
intermediate
Explain the difference between 'fail' and 'continue' in the 'on_failure' setting.
'fail' stops the apply and marks the resource as tainted. 'continue' lets Terraform proceed even if the provisioner fails, without marking the resource as tainted.
Click to reveal answer
advanced
How can you prevent Terraform from destroying a resource if a provisioner fails?
Set 'on_failure' to 'continue' or use 'ignore_errors = true' in the provisioner block to avoid resource destruction on failure.
Click to reveal answer
beginner
Why should provisioners be used as a last resort in Terraform?
Provisioners can cause unpredictable failures and complicate resource management. It's better to use native Terraform resources or external configuration management tools.
Click to reveal answer
What does Terraform do by default if a provisioner fails?
AStops apply and marks resource as tainted
BIgnores the failure and continues
CAutomatically retries the provisioner
DDeletes the entire Terraform state
✗ Incorrect
By default, Terraform stops the apply and marks the resource as tainted when a provisioner fails.
Which 'on_failure' option allows Terraform to continue even if the provisioner fails?
Afail
Bcontinue
Cwarn
Dignore
✗ Incorrect
'continue' lets Terraform proceed without marking the resource as tainted.
What is the effect of setting 'ignore_errors = true' in a provisioner?
ATerraform ignores provisioner failures and continues
BTerraform pauses the apply process
CTerraform deletes the resource immediately
DTerraform will retry the provisioner indefinitely
✗ Incorrect
'ignore_errors = true' tells Terraform to ignore failures and continue the apply.
Why is it recommended to minimize the use of provisioners in Terraform?
AThey are deprecated and no longer supported
BThey increase the cost of cloud resources
CThey can cause unpredictable failures and complexity
DThey slow down Terraform plan operations
✗ Incorrect
Provisioners can cause unpredictable failures and make resource management harder.
If a provisioner fails and 'on_failure' is set to 'warn', what happens?
ATerraform retries the provisioner
BTerraform stops and marks resource as tainted
CTerraform ignores the failure silently
DTerraform continues but logs a warning
✗ Incorrect
'warn' lets Terraform continue but logs a warning about the failure.
Describe how Terraform handles provisioner failures and the options to control this behavior.
Think about what happens when a script run by Terraform fails and how you can tell Terraform to react differently.
You got /3 concepts.
Explain why relying on provisioners in Terraform can be risky and what alternatives exist.
Consider how you would manage configuration without running scripts inside Terraform.
You got /3 concepts.
Practice
(1/5)
1.
What does the on_failure argument in a Terraform provisioner control?
easy
A. It controls what happens if the provisioner script or command fails.
B. It sets the timeout duration for the provisioner execution.
C. It defines the order in which provisioners run.
D. It specifies the operating system for the provisioner.
Solution
Step 1: Understand provisioner purpose
Provisioners run scripts or commands after resource creation.
Step 2: Role of on_failure
The on_failure argument controls what Terraform does if the provisioner fails.
Final Answer:
It controls what happens if the provisioner script or command fails. -> Option A
Quick Check:
on_failure controls failure behavior [OK]
Hint: Remember: on_failure decides action on provisioner failure [OK]
Common Mistakes:
Confusing on_failure with timeout settings
Thinking on_failure sets provisioner order
Assuming on_failure defines OS type
2.
Which of the following is the correct syntax to make a provisioner continue even if it fails?
A. The on_failure argument is not allowed in provisioners.
B. The on_failure value should be a string with quotes.
C. The provisioner type remote-exec is not supported.
D. The inline command is invalid and causes syntax error.
Solution
Step 1: Check on_failure syntax
The value for on_failure must be a quoted string, e.g., "fail" or "continue".
Step 2: Identify impact of missing quotes
Without quotes, Terraform treats it as an identifier, causing unexpected behavior or ignoring the setting.
Final Answer:
The on_failure value should be a string with quotes. -> Option B
Quick Check:
on_failure values require quotes [OK]
Hint: Always quote on_failure values "fail" or "continue" [OK]
Common Mistakes:
Omitting quotes around on_failure values
Confusing command errors with syntax errors
Thinking on_failure is unsupported
5.
You want to run a local-exec provisioner that might fail but should not stop Terraform from creating other resources. Which configuration achieves this?