How to Install Terraform in Centos & Deploy EC2 through Terraform
Step-1 : Make sure you have wget and unzip tool installed in your system. If you don’t have then you can download from below command.
# yum install wget unzip
Step-2 : First you need to update your system by using yum update command.
# yum update
Step-3 : Then you need to download the latest version of Terraform package.
# wget https://releases.hashicorp.com/terraform/1.0.1/terraform_1.0.1_linux_amd64.zip
Step-4 : Once downloaded you need to unzip the package on /usr/local/bin.
# unzip terraform_0.12.17_linux_amd64.zip -d /usr/local/bin/
Step-5 : After successfully unzipping the package, you can check the terraform version using terraform -v command.
# terraform –v
Step-6 : Create a Directory and Configuration File.
#mkdir Terraform_Project
#cd Terraform_Project
#gedit or vim project.tf
Step-7 : Now create a user and downlaod csv file, after downloading csv file the access_key and secret_key will be there.
Step-8 : Now open project.tf file and add below code.
provider “aws” {
region = “us-east-2”
access_key = “my-access-key”
secret_key = “my-secret-key”
}
resource “aws_instance” “us-east-2” {
ami = “ami-005e54dee72cc1d00”
instance_type = “t2.micro”
Step-9 : Initialize Terraform by executing terraform init command.
#terraform init
Step-10 : To add a plan run the terraform plan command.
#terraform plan
Step-11 : Now execute terraform apply command to run the instance.
#terraform apply
Now you can see terraform has been successfully created.
centos 7