What if your computer could finish the boring setup work for you every time you change cloud resources?
Why Local-exec provisioner in Terraform? - Purpose & Use Cases
Imagine you create a server in the cloud and then have to manually run commands on your own computer to configure it or move files every time you make a change.
This manual way is slow and easy to forget steps. You might run commands in the wrong order or miss one, causing errors and wasting time.
The Local-exec provisioner lets Terraform automatically run commands on your local machine right after creating or changing resources. This means no more manual steps or mistakes.
terraform apply # Then manually run: scp file.txt user@server:/path # Then ssh user@server 'sudo systemctl restart service'
resource "null_resource" "example" { provisioner "local-exec" { command = "scp file.txt user@server:/path && ssh user@server 'sudo systemctl restart service'" } }
You can automate local tasks triggered by cloud changes, making your deployments faster and error-free.
After launching a new virtual machine, automatically copying configuration files from your laptop and restarting services without lifting a finger.
Manual local commands are slow and error-prone.
Local-exec runs local commands automatically during Terraform runs.
This saves time and reduces mistakes in cloud setups.