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…
Like this:
Like Loading...