0
0
Terraformcloud~15 mins

Provisioner failure behavior in Terraform - Mini Project: Build & Apply

Choose your learning style9 modes available
Provisioner Failure Behavior in Terraform
📖 Scenario: You are managing cloud infrastructure using Terraform. Sometimes, when Terraform runs a provisioner script on a resource, the script might fail. You want to control what happens when this failure occurs.Terraform allows you to specify how it should behave if a provisioner fails, using the on_failure setting.
🎯 Goal: Build a Terraform configuration that creates a simple resource with a local-exec provisioner. Configure the provisioner to handle failure by choosing the on_failure behavior.You will create the resource, add the provisioner, and set the failure behavior to continue.
📋 What You'll Learn
Create a Terraform resource of type null_resource named example
Add a local-exec provisioner that runs the command exit 1 (which will fail)
Add the on_failure argument to the provisioner and set it to continue
💡 Why This Matters
🌍 Real World
In real cloud infrastructure, provisioners run scripts or commands on resources after creation. Sometimes these scripts fail, and you need to decide if Terraform should stop or continue.
💼 Career
Understanding provisioner failure behavior helps cloud engineers manage infrastructure deployments reliably and avoid unexpected interruptions.
Progress0 / 4 steps
1
Create a null_resource named example
Create a Terraform resource block for null_resource named example.
Terraform
Need a hint?

The resource block starts with resource "null_resource" "example" { and ends with }.

2
Add a local-exec provisioner with a failing command
Inside the null_resource named example, add a provisioner block of type local-exec that runs the command exit 1.
Terraform
Need a hint?

The provisioner block should have command = "exit 1" inside.

3
Add on_failure behavior to continue on failure
Inside the local-exec provisioner block, add the argument on_failure and set it to continue.
Terraform
Need a hint?

The on_failure argument controls what happens if the provisioner fails.

4
Complete the Terraform configuration
Ensure the Terraform configuration has the null_resource named example with a local-exec provisioner running exit 1 and on_failure = "continue" set.
Terraform
Need a hint?

Review the full resource block to confirm all parts are present.