Terraform Provisioners Explained
Learn what Terraform provisioners are, how local-exec and remote-exec work, when they are useful, and why they should be used carefully.
What is a Terraform provisioner?
A provisioner runs scripts or commands during resource creation or destruction. Provisioners can be useful, but they should not become the main way to configure infrastructure.
local-exec example
resource "null_resource" "example" { provisioner "local-exec" { command = "echo Resource created" } }
remote-exec example
provisioner "remote-exec" { inline = [ "sudo apt update", "sudo apt install -y nginx" ] }
When provisioners are used
- Bootstrap a VM after creation.
- Run a one-time local command.
- Call external tooling carefully.
- Temporary migration workflows.
Common mistakes
- Using provisioners for all server configuration.
- Making Terraform depend on fragile SSH connections.
- Storing secrets in inline commands.
- Not handling retries or partial failures.
Best practices
- Use provisioners only when there is no better option.
- Keep commands idempotent where possible.
- Do not print secrets.
- Prefer immutable images or cloud-init for VM setup.
Related guides
- Terraform Learning Path
- Terraform Commands Explained
Official references
- Terraform provisioners documentation
Join the discussion
0 CommentsAsk questions, add context, or share what worked.
More from Melochip Editorial
Learn what Playwright testing is, why modern QA teams use it, how testers can get started, and the major types...
7 min read · Sep 19, 2026
Learn how Kubernetes Deployments and ReplicaSets work with practical YAML, scaling, self-healing, rolling upda...
7 min read · Sep 17, 2026
Learn Kubernetes security best practices with RBAC, Secrets, ServiceAccounts, Pod securityContext, NetworkPoli...
6 min read · Sep 17, 2026Related articles
Learn how Kubernetes Deployments and ReplicaSets work with practical YAML, scaling, self-healing, rolling upda...
7 min read · Sep 17, 2026
Learn Kubernetes monitoring and logs with kubectl logs, events, metrics-server, top commands, Prometheus, Graf...
5 min read · Sep 17, 2026
Learn Kubernetes Ingress with controllers, IngressClass, host and path routing, TLS, DNS, annotations, redirec...
8 min read · Sep 17, 2026
Learn Kubernetes ConfigMaps and Secrets with YAML, environment variables, file mounts, update behavior, immuta...
8 min read · Sep 17, 2026Stay in the loop. Get new Melochip articles
Receive Melochip article updates when new articles are available. Explicit opt-in only.
No comments yet. Start the discussion.