DevOps Classroom notes 02/Jan/2025

Setting up VS Code for terraform

  • We need to install an extension for Terraform from hashicorp
    Preview

Creating the required infra with Terraform

Activity 1: I want to create a vpc with 4 subnets in AWS

AWS Credentials

  • Ensure you have aws cli installed and configured (view classroom recording to create one)

Data types in Terraform

  • official docs
  • string: this will be in quotes
  • number
  • bool
  • list
  • set
  • map or object

Hashicorp Configuration Language (HCL)

Terraform AWS Provider

terraform {
    required_providers {
        aws = {
            source = "hashicorp/aws"
            version = "5.82.2"
        }
    }

}

provider "<name>" {
    arg1 = value1
    ...
    ..
    argn = valuen

}
terraform {
    required_providers {
      aws = {
        source = "hashicorp/aws"
        version = "5.82.2"
      }
    }
}

provider "aws" {
    region = "ap-south-1"
}
  • Now from terminal
    • download providers and initialize terraform init
      Preview
    • Format the template terraform fmt
    • Validate the template terraform validate
  • Resource block in terraform
resource "type" "identifier" {
    arg1 = value1
    ...
    ..
    argn = valuen
}
  • Now to find resources,
    • Search in provider docs
    • google terraform <cloud> <resource>
  • vpc resource docs
  • Add the vpc resource block so as of now the template is
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "5.82.2"
    }
  }
}

provider "aws" {
  region = "ap-south-1"
}


resource "aws_vpc" "network" {
  cidr_block = "10.10.0.0/16"
  tags = {
    Name = "from tf"
  }

}
  • Now to create infrastructure, execute terraform apply where the plan will be shown
    Preview
  • To be continued…

Published
Categorized as Uncategorized Tagged

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
Animated Social Media Icons by Acurax Responsive Web Designing Company

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