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:
- The VPC name
xfusion-vpcshould be stored in a variable namedKKE_vpc. - The VPC should have a CIDR block of
10.0.0.0/16.
Note:
- The configuration values should be stored in a
variables.tffile. - The Terraform script should be structured with a
main.tffile referencingvariables.tf. - The Terraform working directory is
/home/bob/terraform. - Right-click under the
EXPLORERsection inVS Codeand selectOpen in Integrated Terminalto 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