+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Username :sreejith.awsspace@gmail.com
Password : E
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
How to run Ansible playbook from Terraform | Terraform Ansible Integration | WhatsAPP No-8817442344
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Learning Path
- Terraform -- Whatever we do in AWS is all the services we will present
- Ansible -- configuration with jenkins with oracle script
- Linux Shell Patching
- AWS SysOps last
- DevOps : Pipeline
Terraform Basics :
4. Step-01: MacOS: Install Terraform
- Install Terraform CLI : Terraform binary which we need to install on our local desktop
- AWS CLI : If we are using AWS as the provider to provision the infrastructure on AWS cloud the AWS CLI needs to be installed.
- VS code editor has the IDE for writing terraform configuration file
- Terraform syntax related language plugin which is also called , terraform plugin for VS code.
These are the things that we need to install to start with terraform . we can install on the below OS based on the environment we are using .
So lets get back to our GitHub repository and start in a step by step manner .
Click the install tools for terraform AWSCLI
0.14.3 is the version we are using. in the lecture. MacOS
Copy the unzipped terraform binary to /usr/local/bin
terraform version
6. Step-02: Install VSCode Editor, VS Code Terraform Plugin and AWS CLI
In the previous step we have installed the terraform CLI binary
Terraform plugin for VS Code
https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform
After installing the VScode we need to go-ahead and install terraform plugin
Hashicorp terraform plugin for VS Code which is also known as "Syntax Highlighting and auto completion for terraform"
Next is AWS CLI : on our local desktop
next we need to setup our AWS credential and configure those credentials for the same .
AWS CLI Installation
https://docs.aws.amazon.com/cli/latest/userguide/getting-started-version.html
7. Step-03: Configure AWS CLI
Generate a security credential from whichever user you are going to create , give the administrative privileges.
Click on "Create access key"
aws configure on our command line .
it will store the credentials in this respective folder .
cat $HOME / .aws/credentials
8. Step-04: Windows: Install Terraform & AWS CLI on Windows
In Windows :
https://www.terraform.io/downloads
After download take it to a directory unzip it , you will get a binary file
terraform_1.1.7_windows_amd64
Create a c:\terraform.bin
copy the binary there
environment variable - Path add c:\terraform.bin
Open command prompt > terraform version
I already installed AWS CLI --
10. Step-06: Introduction to Terraform Workflow using Terraform Commands
terraform command basics
To provision the infrastructure using terraform we need to use the core 5 commands to do this .
Terraform init -- to create the terraform configuration files .
We will initialize the working directory where those configuration files are there which will download the plugins which is nothing but providers configured in your configuration files. It is going to down load some providers .
11. Step-07: Update Terraform manifest with AMI ID and Region
we are in our Git Hub repository , hashi corp certified associate
Firstly determine what you are going to provision on the AWS cloud . we need to review the terraform manifest and before we review the terraform manifest the three pre-requisite condition met .
Go to AWS search VPC in the respective region. click on VPC
If you do not have a defualt VPC you can create one in the Actions tab
2. AMI needs to exist in the region that you are providing , or create an AMI id.
Go to VSC code
The above is the basic terraform configuration file. Dont worry on the code present in there we are ignoring that for now. We will learn about each block in the next section - Provider Block -- Resource Block . terraform block etc
In this section we are only going to master the terraform commands.
Here you will find the AMI id
We will copy this AMI ID and paste it here
ensure the region and take the code to put it in the code
3 . step
cat $HOME /.aws/credentials
Next we will move to terraform Core Commands .
12. Step-08: Execute Terraform core commands
Go to the respective location which is 02-02
And inside that you will find a file called .
ec2-instance.tf
Any file that ends with .tf is the terraform configuration file . so terraform will process that file automatically by understanding
This directory becomes the current working directory
$ terraform init
it initializes the provider plugins . It is going to download the Provider hasicorp plugin, what is mentioned in Source "hashicorp/aws" plugin
terraform has provided the lock file to record the provider selection .terraform.lock.hcl
On our local machine
This will download on our local desktop .
These downloaded providers are used to communicate to their respective providers by Terraform .
.terraform.lock.hcl -- this tells which provider version it has downloaded.
This contains the registry and the version of the provider that it has downloaded .
The most important things is the .terraform.tf file not the lock file .
.terraform folder is the important thing .
Inside the file you will notice the following folder and finally inside the folder 3.22.0
This is the provider whatever we have downloaded which will be used by the terraform command line to communicate to the aws cloud provider APIs
$ terraform validate -- if there is any issue with the respective file which is ec2-instance.tf it will tell what the problems with our file ec2-instance.tf file
Validate : Validate will check the terraform configuration file , its syntax and if there is any issues with the file. If there is any problem it will indicate the issue .
$ terraform plan
Plan will create an execution plan for us , what it is going to create on the AWS CLOUD .
You only need to provide AMI and the instance type and the rest will be created automatically .
The below parameter will be automatically picked up. rest all will be applied automatically .
plan is it tells you what it is going to create . "+" means create
$ terraform apply
it will prompt you before applying , we day "Yes"
Now go to AWS console and cross verify if the EC2 service has been provisioned .
$ terraform destroy
Now you will see a "-" sign indicating that the service will be destroyed .
say "yes" to prompt
13. Step-09: Terraform Configuration Syntax
Syntax
whatever terraform configurations you write are plan text files . All .tf files are called the terraform configuration files .
Whenever we are executing the terraform commands we should be in the working directory ,The below highlighted one is called the working directory
We shoukd be executing the terraform command where our terraform configuration file are present.
-- WORKING DIRECTORY
If we understand these things on a high level we can implement may terraform commands effectively .
This is a basic configuration of Terraform .
resource is of the block-type is the most important block . We have Top level blocks and Block inside Blocks.
Block inside - Blocks are something like Provisioners - From terraform side we will have something like Provisioners those provisioner blocks can be defined inside these resources . Those are one of things that we call Block Inside Blocks .
For AWS instance we will have something called Tags block . You will define multiple tags for your AWS instance , those are also examples of block inside blocks .
Next thing is Block Labels.
We have two block labels
But when you consider a variable you are only going to have one label .
How many block labels should be used for respective blocks type -- will be seen later .
Next is Arguments :
Every resource is going to have argument which is nothing but that resource specific information , examples
ami =
instance_type =
Commenting : We can do commenting inside terraform configuration files .
14. Step-10: Terraform Arguments, Meta-Arguments and Attributes
We will understand , Arguments, Meta-Arguments and Attributes inside a resource block
Required Arguments and Optional Arguments, if you don't provide the Optional Arguments there is no harm . But if you do not provide the required arguments

Then you will have Attribute reference documentation , you need to export some output values and fpr that you might need Attributes
For instance if you want to get the Public IP of the EC2 instance
Meta-Argument : In arguments an attribute you have seen resource specific values . Meta Argument are terraform specific arguments .
arguments an attribute are always cloud provider attributes . This changes the behaviour of the resource how you are going to use it.
15. Step-11: Understand about Terraform Top Level Blocks
Terraform has limited amount of Top Level blocks
Top level block are as mentioned above , once we understand these top level blocks we will be 95 % experts in terraform
Calling the module block for you are providing some information to that module.
16. Step-11: Terraform Top Level Blocks Example
How does the Top level block look like in a sample example .
Comments
Post a Comment