provisioner
A block inside a resource that runs a script, locally or on the new machine, after the resource is created or before it is destroyed.
They run arbitrary commands with your credentials, and their effects are invisible to plans and state.
In more detail
HashiCorp calls provisioners a last resort: Terraform cannot plan what the script will do, cannot detect drift in its results, and a failed script leaves the resource marked as tainted. Prefer a provider feature, machine start-up data, a pre-built image or a configuration management tool.
Example
provisioner "local-exec" {
command = "echo created"
}Related terms
- configuration management — Keeping the software, settings, files and services on your machines in a known, described state, and putting them back when they wander from it.
- null_resource — A resource from the hashicorp/null provider that creates nothing real, used as a placeholder or to run actions when its triggers change.
- provisioning — Creating the machines, disks and networks themselves, so that there is something to log into and configure.
Taught in
- Provisioners: Why They Are A Last Resort — Infrastructure as Code with Terraform
- State Locking With Use Lockfile — Infrastructure as Code with Terraform
- Dependencies, depends_on And Lifecycle Rules — HashiCorp Terraform Associate (004) Exam Prep
- Sensitive Data, Ephemeral Values And Secrets From Vault — HashiCorp Terraform Associate (004) Exam Prep
- State Locking: One Writer At A Time — HashiCorp Terraform Associate (004) Exam Prep