DevOps Classroom Series – 07/Jan/2020 – Terraform

Terraform Example for creating simple AWS Resource

  • Service: What cloud provider is offering you
  • Resource: Anything created using Service

Setup Terraform DEV Environment

  • Install Terraform
  • Install Visual Studio Code
  • Install Terraform Extension into Visual Studio Code Preview

Manual: Create a VPC in oregon Region

Preview Preview

Terraform: Create a VPC in oregon Region

  • Create a new directory hello-tf as folder is input to terraform
  • Create a new file called as main.tf
  • To create resources in aws, use aws provider. Provider syntax is
provider 'provider type' {
    arg1  'value1'
    ...
    ...
    argn  'valuen'
}
  • Using The above syntax and the documentation over here, lets fill the aws provider
provider "aws" {
    access_key = "<ACCESS-KEY>"
    secret_key = "<SECRET-KEY>"
    region = "us-west-2"
}
  • Note: Inputs in Terraform are called as arguments and outputs are called as attributes.

  • Now we need to create a VPC Resource. Search the Resources in Documentation page or just google ‘terraform resource <cloud> <resource>’

  • Resource Syntax is

resource "type" "name" {
    arg1  'value1'
    ...
    ...
    argn  'valuen'
}
  • Lets add the VPC resource details to existing main.tf file
provider "aws" {
    access_key = "<ACCESS-KEY>"
    secret_key = "<SECRET-KEY>"
    region = "us-west-2"
}

resource "aws_vpc" "myvpc" {
    cidr_block = "192.168.0.0/16"

    tags = {
        "Name" = "from-tf"
    }
}
  • Now to execute this terraform tempalte, Launch Powershell in the directory where terraform template is written
terraform init .
terraform validate .
terraform apply .
  • Once you are done resource can be removed using
terraform destroy .

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

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

Please turn AdBlock off
Customized Social Media Icons from Acurax Digital Marketing Agency

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube