Using Provisioners, local-exec, or remote-exec
Explore how to use Terraform provisioners such as local-exec and remote-exec to run scripts during resource creation. Understand when and how to use provisioners effectively, their potential pitfalls, and alternatives for managing configuration and data loading in cloud environments.
We'll cover the following...
When a resource is created, we may have some scripts or operations we’d like to perform locally or on the remote resource. Terraform provisioners are used to accomplish this goal. To a certain degree, they break the declarative and idempotent model of Terraform. Provisioner execution isn’t necessarily atomic or idempotent because it’s executing an arbitrary script or instruction. Terraform isn’t able to track the results and status of provisioners in the same way it can for other resources. For this reason, HashiCorp recommends using provisioners only as a last resort.
Use cases
There are three basic provisioner use cases:
- Loading data into a virtual machine.
- Bootstrapping a