Infra - Terraform

> Infrastructure as code

1 - About

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

Advertising

3 - 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.

4 - Installation

choco install terraform
  • Test it
terraform version
Terraform v0.12.1

5 - Configuration Syntax

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

5.1 - provider block

  • provider block is used to configure the named provider
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.

Advertising

5.2 - 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:

  • aws_instance is the resource type with the aws prefix defining the provider.
  • example is the resource name.
  • the block defines the resource configuration

6 - 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

7 - Command Workflow

7.1 - Init

init:

  • initializes local settings, data,
  • download and install any Provider

used after:

  • a version control check out
  • or a configuration file modification
terraform init
Advertising

7.2 - Plan

terraform plan

7.3 - Apply

terraform apply

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

  • The + prefix indicates that the resource will be created.
  • The - prefix indicates that the resource will be destroyed.

7.4 - Show

terraform show

inspect the current state

7.5 - Destroy

terraform destroy
infra/terraform.txt · Last modified: 2019/06/05 19:13 by gerardnico