DevOps Classroom notes 02/Jan/2025

Setting up VS Code for terraform

  • We need to install an extension for Terraform from hashicorp

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
    • 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
  • To be continued…
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a comment

Turn on JavaScript to leave a comment.

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

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company
Exit mobile version
%%footer%%