DEV Community

Cover image for 5.Create VPC with IPv6 Using Terraform
Thu Kha Kyawe
Thu Kha Kyawe

Posted on

5.Create VPC with IPv6 Using Terraform

Lab Information

The Nautilus DevOps team is strategically planning the migration of a portion of their infrastructure to the AWS cloud. Acknowledging the magnitude of this endeavor, they have chosen to tackle the migration incrementally rather than as a single, massive transition. Their approach involves creating Virtual Private Clouds (VPCs) as the initial step, as they will be provisioning various services under different VPCs.

For this task, create a VPC named datacenter-vpc in the us-east-1 region with the Amazon-provided IPv6 CIDR block using terraform.

The Terraform working directory is /home/bob/terraform. Create the main.tf file (do not create a different .tf file) to accomplish this task.

Note: Right-click under the EXPLORER section in VS Code and select Open in Integrated Terminal to launch the terminal.

Lab Solutions

Create main.tf

# main.tf

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

provider "aws" {
  region = "us-east-1"
}

resource "aws_vpc" "datacenter_vpc" {
  cidr_block                       = "10.0.0.0/16"
  assign_generated_ipv6_cidr_block = true
  enable_dns_hostnames             = true
  enable_dns_support               = true

  tags = {
    Name = "datacenter-vpc"
  }
}
Enter fullscreen mode Exit fullscreen mode

This configuration:

Provider Configuration: Sets up the AWS provider for the us-east-1 region as required.

VPC Resource: Creates the datacenter-vpc with:

IPv4 CIDR block: 10.0.0.0/16 (required as a base VPC)

Amazon-provided IPv6 CIDR: Enabled via assign_generated_ipv6_cidr_block = true

DNS hostnames enabled: Allows instances to receive DNS hostnames

DNS support enabled: Enables DNS resolution within the VPC

Proper tagging: Name tag set to datacenter-vpc

Key Points:

The assign_generated_ipv6_cidr_block = true parameter is what requests an Amazon-provided IPv6 CIDR block for the VPC

AWS automatically assigns an IPv6 CIDR block from Amazon's pool of IPv6 addresses

You still need to provide an IPv4 CIDR block as it's required for VPC creation

The IPv6 CIDR block will be automatically generated and associated by AWS

To deploy this configuration:

Navigate to the Terraform directory:

cd /home/bob/terraform
Enter fullscreen mode Exit fullscreen mode

Initialize Terraform:

terraform init
Enter fullscreen mode Exit fullscreen mode

Plan the deployment to verify the configuration:

terraform plan
Enter fullscreen mode Exit fullscreen mode

Apply the configuration:

terraform apply
Enter fullscreen mode Exit fullscreen mode

Then type yes when prompted to confirm the creation of the VPC.

The VPC will be created in the us-east-1 region with:

Name: datacenter-vpc

IPv4 CIDR: 10.0.0.0/16

Amazon-provided IPv6 CIDR block (automatically assigned)

Region: us-east-1

This dual-stack VPC (supporting both IPv4 and IPv6) will provide the Nautilus DevOps team with modern networking capabilities for their cloud migration strategy.


Resources & Next Steps
📦 Full Code Repository: KodeKloud Learning Labs
📖 More Deep Dives: Whispering Cloud Insights - Read other technical articles
💬 Join Discussion: DEV Community - Share your thoughts and questions
💼 Let's Connect: LinkedIn - I'd love to connect with you

Credits
• All labs are from: KodeKloud
• I sincerely appreciate your provision of these valuable resources.

Top comments (0)