0
0
Terraformcloud~20 mins

Local-exec provisioner in Terraform - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Local-exec Provisioner in Terraform
📖 Scenario: You are setting up a simple cloud server using Terraform. After the server is created, you want to run a local script on your machine to notify you that the server is ready.
🎯 Goal: Build a Terraform configuration that creates a resource and uses the local-exec provisioner to run a local command after resource creation.
📋 What You'll Learn
Create a Terraform resource block for a null resource named example
Add a local-exec provisioner inside the resource
Configure the provisioner to run the exact command echo Server is ready
Ensure the Terraform configuration is valid and deployable
💡 Why This Matters
🌍 Real World
Local-exec provisioners are useful for running scripts or commands on your local machine after cloud resources are created, such as sending notifications or updating local files.
💼 Career
Understanding provisioners helps cloud engineers automate deployment workflows and integrate Terraform with other tools and scripts.
Progress0 / 4 steps
1
Create a null resource named example
Write a Terraform resource block for a null_resource named example with an empty body.
Terraform
Need a hint?

The null_resource is a special Terraform resource that does nothing but can be used with provisioners.

2
Add a local-exec provisioner block
Inside the null_resource "example" block, add a provisioner "local-exec" block with an empty command attribute.
Terraform
Need a hint?

The local-exec provisioner runs commands on your local machine after resource creation.

3
Set the command to echo Server is ready
Set the command attribute inside the local-exec provisioner to the exact string echo Server is ready.
Terraform
Need a hint?

This command will print a message on your local machine when the resource is created.

4
Add a triggers argument to force re-execution
Add a triggers argument inside the null_resource "example" block with a map containing always_run = timestamp() to ensure the provisioner runs every time.
Terraform
Need a hint?

The triggers argument with timestamp() forces Terraform to run the provisioner every time you apply.