Terraform & Devops
  • Home
  • TERRAFORM CERTIFCATION
  • AWS-CLOUD
  • GCP-CLOUD
  • ANSIBLE
  • KUBERNETES
  • Aboutus
  • Contact Us
No Result
View All Result
  • Home
  • TERRAFORM CERTIFCATION
  • AWS-CLOUD
  • GCP-CLOUD
  • ANSIBLE
  • KUBERNETES
  • Aboutus
  • Contact Us
No Result
View All Result
Terraform & Devops
No Result
View All Result
Home TERRAFORM CERTIFCATION

Terraform Provisioners

by abubakarsiddiq858
January 4, 2021
in TERRAFORM CERTIFCATION
151 3
0
Terraform  Provisioners
176
SHARES
2.2k
VIEWS
Share on FacebookShare on Twitter

Terraform  Provisioners

A Provisioners can be used to model specific actions on the local machine or on a remote machine in order to prepare some tasks.

For example if you are creating a server and after that some software need to installed on top it for example in our case we are installing Httpd server. Terraform wont recommend to use provisioners .

“what if the provisioners Fails  in this case “If a creation-time provisioner fails, the resource is marked as tainted. A tainted resource will be planned for destruction and recreation upon the next terraform apply . “Terraform does this because a failed provisioner can leave a resource in a semi-configured state”

Types of provisioners:

 

In day to day activities we use 3 types of provioners.

  1. Local provisioners.
  2. Remote Provisioners
  3. File provisioner

 

 

  1. Local provisioners:

The local-exec provisioner invokes a local executable code on our local machine after a resource is created.

The following example shows we create a EC2 instance after that it will give us the attribute private IP address of the server.

provider "aws" {
access_key = ""
secret_key = ""
region = ""
}


resource aws_instance "myec23" {
ami = "ami-0e306788ff2473ccb"
instance_type = "t2.large"

provisioner "local-exec" {
command = "echo ${aws_instance.myec23.private_ip} >> private_ips.txt"
}
}

  1. Remote Provisioners:

Remote provisioners help to execute the scripts on remote servers after they are created.

  • For example if you are creating a server and after that some software need to installed on top it for example in our case we are installing Httpd server. Terraform wont recommend to use provisioners.
  • When we work with remote provisioners we have to include the script to be executed under INLINE BLOCK.
provider "aws" {
access_key = ""
secret_key = ""
region = "ap-south-1"
}
resource "aws_instance" "myec2" {
ami = "ami-026669ec456129a70"
instance_type = "t2.large"
key_name = "yyyy"

tags = {
name = "myec3"
}
provisioner "remote-exec" {
inline = [
"sudo yum install httpd -y",
"sudo service httpd on",
"sudo service httpd start"
]
}
connection {
type = "ssh"
user = "ec2-user"
private_key = file("./newpemkeyfile.pem")
host = self.public_ip
}
}

In the above we can see  a Connection block .

  • the default connection type is SSH.
  • we need to specfify the path of private key pem file .In our case we are passing through File fumction.

 

 

  1. File Provioners:

 

The file provisioner is used to copy files or directories from the machine executing Terraform to the newly created resource.

  • They are widely used with Ansible
  • The usecase is if we need to copy some files from Master node to control nodes we can use File provioners.
Example:

provisioner "file" {
source = "conf/configs.d"
destination = "/etc"
}

# Copies all files and folders in apps/app1 to D:/IIS/webapp1
provisioner "file" {
source = "apps/app1/"
destination = "D:/helloworld"
}
}

In the above Example Source  refers Source refers to where the files are present and destination refers to where we need to copy the files.

That’s all about provisioners hope you might have enjoyed this article.

 

Tags: Business TipsMarket StoriesOil MarketSillicon ValleyUnited StatedVenture Capital
  • Trending
  • Comments
  • Latest
Terraform – Modules

Terraform – Modules

January 4, 2021
Terraform Life cycle

Terraform Life cycle

January 4, 2021
Terraform – Functions

Terraform – Functions

January 4, 2021
Terraform installation

Terraform installation

January 4, 2021
Implementing VPC Architecture using Terraform

Implementing VPC Architecture using Terraform

0
Local and dynamic blocks:

Local and dynamic blocks:

0
Terraform  Provisioners

Terraform Provisioners

0
Managing Terraform States in Remote Locations:

Managing Terraform States in Remote Locations:

0
Implementing VPC Architecture using Terraform

Implementing VPC Architecture using Terraform

August 28, 2021
Build a CICD Pipeline with Git Jenkins Terraform

Build a CICD Pipeline with Git Jenkins Terraform

May 24, 2021

Configuring VPC Components in AWS

February 8, 2021

Introduction to AWS

February 7, 2021

Recent News

Implementing VPC Architecture using Terraform

Implementing VPC Architecture using Terraform

August 28, 2021
Build a CICD Pipeline with Git Jenkins Terraform

Build a CICD Pipeline with Git Jenkins Terraform

May 24, 2021

Categories

  • Uncategorized
  • AWS-CLOUD
  • TERRAFORM CERTIFCATION

Site Navigation

  • Home
  • Advertisement
  • Contact Us
  • Privacy & Policy
  • Other Links
Terraform & Devops

We bring you the best Premium WordPress Themes that perfect for news, magazine, personal blog, etc. Check our landing page for details.

No Result
View All Result
  • Home
  • TERRAFORM CERTIFCATION
  • AWS-CLOUD
  • GCP-CLOUD
  • ANSIBLE
  • KUBERNETES
  • Aboutus
  • Contact Us

© 2021 TheTerraform.in - All Rights Reserved.
Designed By TenXinfotech.

Welcome Back!

Login to your account below

Forgotten Password?

Create New Account!

Fill the forms below to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In

Add New Playlist