Terraform Classroom Series – 17/Sep/2019

Terraform Setup

  1. Install Terraform:
    • Windows: choco install terraform -y
    • Other:
      • Download terraform zip from https://www.terraform.io/downloads.html
      • unzip the file
      • Add folder of terraform to Environment variable PATH
      • note: Look at packer installation
    • Install Visual Studio Code
    • Add Terraform Extension to Visual Studio Code

Basics of Terraform DSL

  • Input for terraform is folder/directory
  • Terraform will pick all the files in the input folder with *.tf
  • Provider Syntax
provider "<provider name>" {
    arg1    = value1
    ...
    ...
    argn    = valuen
}
####### Example ###########

provider "aws" {
    region      = "us-west-2"
    secret_key  = "jkdsahfkjadsfhkjasdfhdkjahfdakj"
    access_key  = "kjsdhfkjsdfkjhdsf"
}
  • Resources Syntax
resource "<resource type>" "<your name for this resource>" {
    arg1    = value1
    ...
    ...
    argn    = valuen
}

############### Example ###############

resource "aws_instance" "mywebserver" {
    ami             = "<ami id>"
    instance_type   = "t2.micro"
}

Execution Steps

  1. Create a directory with name "hello-aws"
  2. create a file inside directory "hello-aws" named "main.tf" with above contents
terraform init <dirpath of hello-aws>
terraform validate <dirpath of hello-aws>
terraform apply <dirpath of hello-aws>

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner