PROVISIONERS IN TERRAFORM (PART-5)

Updated: Aug 9, 2020





Hello Readers, This blog is the Part-5 of our Terraform course series. In case you missed previous blogs please check out part one of it before going further. Also, we appreciate your feedback on the articles which would help us in improving.


In this article we have mentioned some code example names, these can be found in the Github repository.


In this article, we are going to talk about provisioners which are nothing but provide a way to combine infra orchestration with Terraform. What if you want to install packages, create user, directories, start, and enable services when an ec2 instance built with Terraform comes up. Here is where provisioners are helpful.






Introduction


Provisioners can be used to model specific actions on the local machine or on a remote machine in order to prepare servers or other infrastructure objects for service.

Till now we have been working only on the creation and destruction of infrastructure scenarios.

Let’s take an example:

We created a web-server EC2 instance with Terraform.

Problem: It is only an EC2 instance, it does not have any software installed.

What if we want a complete end to end solution?

We can use provisioners ….

Provisioners are used to execute scripts on a local or remote machine as part of resource creation or destruction.

Let’s take an example:





In scenarios where not only, we want ec2 instance to be created but also some configuration to be done, we can do it with provisioners.


Types of provisioners

Terraform has the capability to turn provisioners both at the time of resource creation as well as destruction.

There are two main types of provisioners:




  • Local exec will execute script or command on the machine from where we are executing the terraform command.

  • Remote exec will execute a command on the ec2 instance that is launched with terraform




Code for remote exec

Code for local exec


Happy Learning :-)









314 views1 comment
 

Subscribe Form

©2020 by Linux Advise