Terraform Provisioners - Day 3
In Terraform, provisioners are used to perform tasks on the local machine or on a remote resource after it has been created by Terraform. They are typically used for actions that cannot be defined directly within the resource configuration. Provisioners can be helpful for tasks like installing software, configuring applications, or running scripts.
There are several types of provisioners in Terraform:
Local-exec Provisioner:
- Executes commands on the local machine where Terraform is being run.
Remote-exec Provisioner:
- Executes commands on a remote resource via SSH.
Creation-Time Provisioner:
Creation-Time provisioners are only run during creation, not during updating or any other lifecycle. If a creation-Time provisioners fails, the resource is marked as tainted.
Destroy-Time Provisioner:
If when = destroy
is specified, the provisioner will run when the resource it is defined within is destroyed.
It's important to note that while provisioners can be useful, they should be used judiciously. In many cases, it's preferable to use configuration management tools or other external systems for complex provisioning tasks. Provisioners are typically considered as a last resort when no other option is available.
Reference: https://developer.hashicorp.com/terraform/language/resources/provisioners/syntax
Subscribe to my newsletter
Read articles from Anandhi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Anandhi
Anandhi
DevOps enthusiast on a mission to automate, collaborate, and transform software delivery