Table of Contents

Infra - Terraform

About

Terraform is an orchestration tool that will bootstrap, initialize resources and can start a configuration management tool

Configuration Management

Terraform is not a configuration management tool Using provisioners, Terraform enables any configuration management tool to be used to setup a resource once it has been created.

Installation

choco install terraform
terraform version
Terraform v0.12.1

Configuration Syntax

Terraform configurations can contain multiple resources, multiple resource types, and these types can even span multiple providers.

provider block

provider "aws" {
  access_key = "ACCESS_KEY_HERE"
  secret_key = "SECRET_KEY_HERE"
  region     = "us-east-1"
}

Each “Provider” is its own encapsulated binary distributed separately from Terraform itself.

Resource Block

The resource block defines a resource that exists within the infrastructure.

resource "aws_instance" "example" {
  ami           = "ami-2757f631"
  instance_type = "t2.micro"
}

where:

State

Terraform wrote some data into the terraform.tfstate file.

terraform show shows the current state

This state file is extremely important; it keeps track of the IDs of created resources so that Terraform knows what it is managing.

This file must be saved and distributed to anyone who might run Terraform.

It is generally recommended to setup remote state when working with Terraform, to share the state automatically.

Every Terraform setup has two parts:

Command Workflow

Init

init:

used after:

terraform init

Plan

terraform plan

Apply

terraform apply

The output format is similar to the diff format generated by tools such as Git.

Show

terraform show

inspect the current state

Destroy

terraform destroy