Skip to main content

Lab 35: VPC Variable Setup Using Terraform

The Nautilus DevOps team is automating VPC creation using Terraform to manage networking efficiently. As part of this task, they need to create a VPC with specific requirements.

For this task, create an AWS VPC using Terraform with the following requirements:

  1. The VPC name xfusion-vpc should be stored in a variable named KKE_vpc.
  2. The VPC should have a CIDR block of 10.0.0.0/16.

Note:

  1. The configuration values should be stored in a variables.tf file.
  2. The Terraform script should be structured with a main.tf file referencing variables.tf.
  3. The Terraform working directory is /home/bob/terraform.
  4. Right-click under the EXPLORER section in VS Code and select Open in Integrated Terminal to launch the terminal.
# /home/bob/terraform/main.tf

resource "aws_vpc" "xfusion_vpc" {
cidr_block = var.vpc_cidr_block
enable_dns_support = true
enable_dns_hostnames = true

tags = {
Name = var.KKE_vpc
}
}
# /home/bob/terraform/variables.tf
variable "KKE_vpc" {
description = "The name for the VPC"
type = string
default = "xfusion-vpc"
}

variable "vpc_cidr_block" {
description = "The CIDR block for the VPC"
type = string
default = "10.0.0.0/16"
}
terraform init
# or apply forcefully without creating plan and applying it
terraform apply -auto-approve