Terrform Learning

 Terraform Learning


Agenda:


1) Infrastructure as Code (IaC)


2) Terraform Fundamentals


3) Terraform State


4) Terraform Modules


5) Terraform Built-in Functions and Dynamic Blocks


6) Terraform CLI


Understanding Infrastructure As Code (IaC)

IaC allows you to define infrastructure in human and machine-readable code.

Terraform is a tool which is cloud agnostic and enables you to do IaC.


Benefits of IaC

No more clicks – Write down what you want to deploy (VMs, apps…) as human readable.

Enables DevOps – Codification of deployment means it can be version controlled enabling visibility and collaboration across teams.

Declare your Infrastructure – Infrastructure, in case of Terraform, is written declaratively making it easy to read and understand.

Speed, cost and Reduced Risk – No fat Fingers, immutable code, no deployment drift.


Terraform Fundamentals

Terraform – Another IaC tool, but why?
a) Automate software defined n/w
b) Interacts and take care of communication with control layer APIs with ease.
c) Supports vast array of private and pulic clouds
d) Track state of each resource deployed.
The Core terraform workflow:

WRITE => PLAN => APPLY


A)Write: Write your terraform code: 
This would generaly start off with creating a GitHub repo as a common best practice. 

b) Plan: Reveiw: you will continuouly add and review your code changes in your project.

c) Apply: Deploy: After done last review plan you will be ready to provision real infrastructure.


HANDS ON - TERRAFORM INSTALLATION 

Linux (CentOS/RHEL)
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repocd
sudo yum -y install terraform
curl -sL https://azurecliprod.blob.core.windows.net/rhel7_6_install.sh | sudo bash


Linux (Ubuntu/Debian)
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add –
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main“
sudo apt-get update && sudo apt-get install terraform


Initializing the working directory:

terraform init: Inisializes the working directory that contains your terraform code.
-it downloads ansilary compoentes (downloads modules and plugins)
-Setup backend (setup backend for storing terraform state file, a mechanism by which terraform tracks the resoureces)

Review your Terraform Code:
terraform plan: Reads the code and then creates and shows a "plan" of execution and deployment.

Note: this command dones not deploys anything, consider this as a readonly command.

Allows the user to “review” the action plan before executing anything.
At this stage, authentication credentials are used to connect to your infrastructure, if required  


Deploying your terraform code:
terraform apply: Deploys infrastructurs and statements in your code
Updates the deployment state tracking mechanism file a.k.a "state file"

Cleaning upd your terraform deployments:
terraform destroy: Destroys all the infrastructure created

-Looks at the recorded, stored state file created during deployment and destroys all resources created by your code.
-Should be used with caution, as it is a non-reversible command. Take backups and be sure that you want to delete infrastructure.

Terrafrom workflow Review:
WRITE COER => FMT => INIT => VALIDATE => PLAN => APPLY => DESTROY.



Comments

Popular posts from this blog

Cloud Computing in simple

How to Write an Effective Design Document

Bookmark