0
0
Terraformcloud~5 mins

Local-exec provisioner in Terraform - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the local-exec provisioner in Terraform?
The local-exec provisioner runs a command on the machine where Terraform is executed, allowing you to perform local actions during resource creation or destruction.
Click to reveal answer
beginner
How does local-exec differ from remote-exec provisioner?
local-exec runs commands on the local machine where Terraform runs, while remote-exec runs commands on the remote resource (like a VM) after it is created.
Click to reveal answer
beginner
Which argument is required inside a local-exec provisioner block to specify the command to run?
The command argument specifies the shell command or script to execute locally.
Click to reveal answer
intermediate
Can local-exec provisioner access Terraform resource attributes?
Yes, you can use Terraform interpolation syntax to pass resource attributes as part of the command string to local-exec.
Click to reveal answer
beginner
What is a common use case for local-exec provisioner?
A common use case is to run local scripts for configuration, notify external systems, or trigger local automation after resource creation.
Click to reveal answer
Where does the local-exec provisioner run its commands?
AOn the remote resource created
BOn the machine running Terraform
COn the Terraform cloud server
DOn a separate management server
Which argument must you include in a local-exec provisioner block?
Ainline
Bscript_path
Ccommand
Dremote_command
Can local-exec provisioner run after a resource is destroyed?
ANo, it only runs on creation
BOnly on resource update
COnly if manually triggered
DYes, using the <code>when = destroy</code> setting
Which of these is NOT a recommended use of local-exec?
ARunning commands on the remote VM
BTriggering local notifications
CRunning local scripts after resource creation
DCalling local automation tools
How can you pass resource data to a local-exec command?
AUsing Terraform interpolation syntax inside the command string
BUsing environment variables only
CYou cannot pass resource data
DBy writing to a remote file first
Explain what the local-exec provisioner does in Terraform and give an example of when you might use it.
Think about actions you want to perform on your own computer after creating cloud resources.
You got /3 concepts.
    Describe how you would configure a local-exec provisioner to run a shell command that uses an attribute from a created resource.
    Remember Terraform lets you insert resource data inside strings with ${}.
    You got /3 concepts.