# Required providers configuration terraform { required_providers { aws = { source = "hashicorp/aws" version = "~>4.52.0" } } required_version = "~> 1.0" } # AWS provider configuration provider "aws" { profile = "default" region = "us-east-1" } # Create AWS VPC resource "aws_vpc" "vpc" { cidr_block = var.vpc_cidr } # Create public subnet 1 resource "aws_subnet" "public_subnet1" { cidr_block = "10.0.1.0/24" vpc_id = aws_vpc.vpc.id availability_zone = "${var.region}a" tags = { Name = "Subnet for ${var.region}a" } } # Create public subnet 2 resource "aws_subnet" "public_subnet2" { cidr_block = "10.0.2.0/24" vpc_id = aws_vpc.vpc.id availability_zone = "${var.region}b" tags = { Name = "Subnet for ${var.region}b" } } # Create a route table resource "aws_route_table" "public_rt" { vpc_id = aws_vpc.vpc.id route { cidr_block = "0.0.0.0/0" gateway_id = aws_internet_gateway.gw.id } tags = { Name = "public_rt" } } # Associate the route table with public subnet 1 resource "aws_route_table_association" "public_rt_table_a" { subnet_id = aws_subnet.public_subnet1.id route_table_id = aws_route_table.public_rt.id } # Associate the route table with public subnet 2 resource "aws_route_table_association" "public_rt_table_b" { subnet_id = aws_subnet.public_subnet2.id route_table_id = aws_route_table.public_rt.id } # Create an Internet Gateway resource "aws_internet_gateway" "gw" { vpc_id = aws_vpc.vpc.id } # Create IAM Role for Lambda Function resource "aws_iam_role" "lambda_role" { name = "Lambda_Function_Role" assume_role_policy = <