wikiv2:tf_aws_ipv6
Table of Contents
Terraform AWS - IPv6
Definindo o provider
- 00-provider.tf
terraform { required_providers { aws = { source = "hashicorp/aws" version = "5.14.0" } } } provider "aws" { region = "us-east-2" access_key = "AKI..." secret_key = "RrV..." default_tags { tags = { Environment = "Lab" Terraform = "yes" } } }
Criando a VPC
- 01-vpc.tf
resource "aws_vpc" "us-east-tf-vpc" { cidr_block = "10.88.0.0/16" enable_dns_support = true enable_dns_hostnames = true assign_generated_ipv6_cidr_block = true tags = { Name = "us-east-tf-vpc" } }
Iniciando o provider e criando a VPC
$ terraform init Initializing the backend... Initializing provider plugins... - Finding hashicorp/aws versions matching "5.14.0"... - Installing hashicorp/aws v5.14.0... - Installed hashicorp/aws v5.14.0 (signed by HashiCorp) Terraform has created a lock file .terraform.lock.hcl to record the provider selections it made above. Include this file in your version control repository so that Terraform can guarantee to make the same selections by default when you run "terraform init" in the future. Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work. If you ever set or change modules or backend configuration for Terraform, rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary.
$ terraform plan Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # aws_vpc.us-east-tf-vpc will be created + resource "aws_vpc" "us-east-tf-vpc" { + arn = (known after apply) + assign_generated_ipv6_cidr_block = true + cidr_block = "10.88.0.0/16" + default_network_acl_id = (known after apply) + default_route_table_id = (known after apply) + default_security_group_id = (known after apply) + dhcp_options_id = (known after apply) + enable_dns_hostnames = true + enable_dns_support = true + enable_network_address_usage_metrics = (known after apply) + id = (known after apply) + instance_tenancy = "default" + ipv6_association_id = (known after apply) + ipv6_cidr_block = (known after apply) + ipv6_cidr_block_network_border_group = (known after apply) + main_route_table_id = (known after apply) + owner_id = (known after apply) + tags = { + "Name" = "us-east-tf-vpc" } + tags_all = { + "Environment" = "Lab" + "Name" = "us-east-tf-vpc" + "Terraform" = "yes" } } Plan: 1 to add, 0 to change, 0 to destroy. ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.
$ terraform apply Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # aws_vpc.us-east-tf-vpc will be created + resource "aws_vpc" "us-east-tf-vpc" { + arn = (known after apply) + assign_generated_ipv6_cidr_block = true + cidr_block = "10.88.0.0/16" + default_network_acl_id = (known after apply) + default_route_table_id = (known after apply) + default_security_group_id = (known after apply) + dhcp_options_id = (known after apply) + enable_dns_hostnames = true + enable_dns_support = true + enable_network_address_usage_metrics = (known after apply) + id = (known after apply) + instance_tenancy = "default" + ipv6_association_id = (known after apply) + ipv6_cidr_block = (known after apply) + ipv6_cidr_block_network_border_group = (known after apply) + main_route_table_id = (known after apply) + owner_id = (known after apply) + tags = { + "Name" = "us-east-tf-vpc" } + tags_all = { + "Environment" = "Lab" + "Name" = "us-east-tf-vpc" + "Terraform" = "yes" } } Plan: 1 to add, 0 to change, 0 to destroy. Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: yes aws_vpc.us-east-tf-vpc: Creating... aws_vpc.us-east-tf-vpc: Still creating... [10s elapsed] aws_vpc.us-east-tf-vpc: Still creating... [20s elapsed] aws_vpc.us-east-tf-vpc: Creation complete after 25s [id=vpc-0d4c4f7874d204897] Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
$ terraform state list aws_vpc.us-east-tf-vpc
$ terraform state show aws_vpc.us-east-tf-vpc # aws_vpc.us-east-tf-vpc: resource "aws_vpc" "us-east-tf-vpc" { arn = "arn:aws:ec2:us-east-2:662644875436:vpc/vpc-0d4c4f7874d204897" assign_generated_ipv6_cidr_block = true cidr_block = "10.88.0.0/16" default_network_acl_id = "acl-0a1e3381b16f43530" default_route_table_id = "rtb-08002bd19c277c42b" default_security_group_id = "sg-0ead025b81bd0f03b" dhcp_options_id = "dopt-0251f420400d60db9" enable_dns_hostnames = true enable_dns_support = true enable_network_address_usage_metrics = false id = "vpc-0d4c4f7874d204897" instance_tenancy = "default" ipv6_association_id = "vpc-cidr-assoc-03327de815092cc89" ipv6_cidr_block = "2600:1f16:7c3:6100::/56" ipv6_cidr_block_network_border_group = "us-east-2" ipv6_netmask_length = 0 main_route_table_id = "rtb-08002bd19c277c42b" owner_id = "662644875436" tags = { "Name" = "us-east-tf-vpc" } tags_all = { "Environment" = "Lab" "Name" = "us-east-tf-vpc" "Terraform" = "yes" } }
Criando subnets
- 02-subnets.tf
# Declare the data source data "aws_availability_zones" "available" { state = "available" } # Public Subnet A resource "aws_subnet" "us-east-2a-tf-public-subnet" { vpc_id = aws_vpc.us-east-tf-vpc.id ipv6_cidr_block = cidrsubnet(aws_vpc.us-east-tf-vpc.ipv6_cidr_block, 8, 0) cidr_block = cidrsubnet(aws_vpc.us-east-tf-vpc.cidr_block, 4, 10) availability_zone_id = data.aws_availability_zones.available.zone_ids[0] tags = { "Name" = "us-east-2a-tf-public-subnet" } } # Public Subnet B resource "aws_subnet" "us-east-2b-tf-public-subnet" { vpc_id = aws_vpc.us-east-tf-vpc.id ipv6_cidr_block = cidrsubnet(aws_vpc.us-east-tf-vpc.ipv6_cidr_block, 8, 1) cidr_block = cidrsubnet(aws_vpc.us-east-tf-vpc.cidr_block, 4, 11) availability_zone_id = data.aws_availability_zones.available.zone_ids[1] tags = { "Name" = "us-east-2b-tf-public-subnet" } }
$ terraform validate
Success! The configuration is valid.
$ terraform plan aws_vpc.us-east-tf-vpc: Refreshing state... [id=vpc-0d4c4f7874d204897] data.aws_availability_zones.available: Reading... data.aws_availability_zones.available: Read complete after 1s [id=us-east-2] Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # aws_subnet.us-east-2a-tf-public-subnet will be created + resource "aws_subnet" "us-east-2a-tf-public-subnet" { + arn = (known after apply) + assign_ipv6_address_on_creation = false + availability_zone = (known after apply) + availability_zone_id = "use2-az1" + cidr_block = "10.88.160.0/20" + enable_dns64 = false + enable_resource_name_dns_a_record_on_launch = false + enable_resource_name_dns_aaaa_record_on_launch = false + id = (known after apply) + ipv6_cidr_block = "2600:1f16:7c3:6100::/64" + ipv6_cidr_block_association_id = (known after apply) + ipv6_native = false + map_public_ip_on_launch = false + owner_id = (known after apply) + private_dns_hostname_type_on_launch = (known after apply) + tags = { + "Name" = "us-east-2a-tf-public-subnet" } + tags_all = { + "Environment" = "Lab" + "Name" = "us-east-2a-tf-public-subnet" + "Terraform" = "yes" } + vpc_id = "vpc-0d4c4f7874d204897" } # aws_subnet.us-east-2b-tf-public-subnet will be created + resource "aws_subnet" "us-east-2b-tf-public-subnet" { + arn = (known after apply) + assign_ipv6_address_on_creation = false + availability_zone = (known after apply) + availability_zone_id = "use2-az2" + cidr_block = "10.88.176.0/20" + enable_dns64 = false + enable_resource_name_dns_a_record_on_launch = false + enable_resource_name_dns_aaaa_record_on_launch = false + id = (known after apply) + ipv6_cidr_block = "2600:1f16:7c3:6101::/64" + ipv6_cidr_block_association_id = (known after apply) + ipv6_native = false + map_public_ip_on_launch = false + owner_id = (known after apply) + private_dns_hostname_type_on_launch = (known after apply) + tags = { + "Name" = "us-east-2b-tf-public-subnet" } + tags_all = { + "Environment" = "Lab" + "Name" = "us-east-2b-tf-public-subnet" + "Terraform" = "yes" } + vpc_id = "vpc-0d4c4f7874d204897" } Plan: 2 to add, 0 to change, 0 to destroy. ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.
$ terraform apply data.aws_availability_zones.available: Reading... aws_vpc.us-east-tf-vpc: Refreshing state... [id=vpc-0d4c4f7874d204897] data.aws_availability_zones.available: Read complete after 1s [id=us-east-2] Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # aws_subnet.us-east-2a-tf-public-subnet will be created + resource "aws_subnet" "us-east-2a-tf-public-subnet" { + arn = (known after apply) + assign_ipv6_address_on_creation = false + availability_zone = (known after apply) + availability_zone_id = "use2-az1" + cidr_block = "10.88.160.0/20" + enable_dns64 = false + enable_resource_name_dns_a_record_on_launch = false + enable_resource_name_dns_aaaa_record_on_launch = false + id = (known after apply) + ipv6_cidr_block = "2600:1f16:7c3:6100::/64" + ipv6_cidr_block_association_id = (known after apply) + ipv6_native = false + map_public_ip_on_launch = false + owner_id = (known after apply) + private_dns_hostname_type_on_launch = (known after apply) + tags = { + "Name" = "us-east-2a-tf-public-subnet" } + tags_all = { + "Environment" = "Lab" + "Name" = "us-east-2a-tf-public-subnet" + "Terraform" = "yes" } + vpc_id = "vpc-0d4c4f7874d204897" } # aws_subnet.us-east-2b-tf-public-subnet will be created + resource "aws_subnet" "us-east-2b-tf-public-subnet" { + arn = (known after apply) + assign_ipv6_address_on_creation = false + availability_zone = (known after apply) + availability_zone_id = "use2-az2" + cidr_block = "10.88.176.0/20" + enable_dns64 = false + enable_resource_name_dns_a_record_on_launch = false + enable_resource_name_dns_aaaa_record_on_launch = false + id = (known after apply) + ipv6_cidr_block = "2600:1f16:7c3:6101::/64" + ipv6_cidr_block_association_id = (known after apply) + ipv6_native = false + map_public_ip_on_launch = false + owner_id = (known after apply) + private_dns_hostname_type_on_launch = (known after apply) + tags = { + "Name" = "us-east-2b-tf-public-subnet" } + tags_all = { + "Environment" = "Lab" + "Name" = "us-east-2b-tf-public-subnet" + "Terraform" = "yes" } + vpc_id = "vpc-0d4c4f7874d204897" } Plan: 2 to add, 0 to change, 0 to destroy. Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: yes aws_subnet.us-east-2a-tf-public-subnet: Creating... aws_subnet.us-east-2b-tf-public-subnet: Creating... aws_subnet.us-east-2a-tf-public-subnet: Creation complete after 2s [id=subnet-0376d087cc74fa5da] aws_subnet.us-east-2b-tf-public-subnet: Creation complete after 2s [id=subnet-046b9ee429ae0030e] Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
$ terraform state show data.aws_availability_zones.available # data.aws_availability_zones.available: data "aws_availability_zones" "available" { group_names = [ "us-east-2", ] id = "us-east-2" names = [ "us-east-2a", "us-east-2b", "us-east-2c", ] state = "available" zone_ids = [ "use2-az1", "use2-az2", "use2-az3", ] }
$ terraform state show aws_subnet.us-east-2a-tf-public-subnet # aws_subnet.us-east-2a-tf-public-subnet: resource "aws_subnet" "us-east-2a-tf-public-subnet" { arn = "arn:aws:ec2:us-east-2:662644875436:subnet/subnet-0376d087cc74fa5da" assign_ipv6_address_on_creation = false availability_zone = "us-east-2a" availability_zone_id = "use2-az1" cidr_block = "10.88.160.0/20" enable_dns64 = false enable_lni_at_device_index = 0 enable_resource_name_dns_a_record_on_launch = false enable_resource_name_dns_aaaa_record_on_launch = false id = "subnet-0376d087cc74fa5da" ipv6_cidr_block = "2600:1f16:7c3:6100::/64" ipv6_cidr_block_association_id = "subnet-cidr-assoc-00c0d042029092f83" ipv6_native = false map_customer_owned_ip_on_launch = false map_public_ip_on_launch = false owner_id = "662644875436" private_dns_hostname_type_on_launch = "ip-name" tags = { "Name" = "us-east-2a-tf-public-subnet" } tags_all = { "Environment" = "Lab" "Name" = "us-east-2a-tf-public-subnet" "Terraform" = "yes" } vpc_id = "vpc-0d4c4f7874d204897" }
$ terraform state show aws_subnet.us-east-2b-tf-public-subnet # aws_subnet.us-east-2b-tf-public-subnet: resource "aws_subnet" "us-east-2b-tf-public-subnet" { arn = "arn:aws:ec2:us-east-2:662644875436:subnet/subnet-046b9ee429ae0030e" assign_ipv6_address_on_creation = false availability_zone = "us-east-2b" availability_zone_id = "use2-az2" cidr_block = "10.88.176.0/20" enable_dns64 = false enable_lni_at_device_index = 0 enable_resource_name_dns_a_record_on_launch = false enable_resource_name_dns_aaaa_record_on_launch = false id = "subnet-046b9ee429ae0030e" ipv6_cidr_block = "2600:1f16:7c3:6101::/64" ipv6_cidr_block_association_id = "subnet-cidr-assoc-0bc6bb8943283fd74" ipv6_native = false map_customer_owned_ip_on_launch = false map_public_ip_on_launch = false owner_id = "662644875436" private_dns_hostname_type_on_launch = "ip-name" tags = { "Name" = "us-east-2b-tf-public-subnet" } tags_all = { "Environment" = "Lab" "Name" = "us-east-2b-tf-public-subnet" "Terraform" = "yes" } vpc_id = "vpc-0d4c4f7874d204897" }
Referências
wikiv2/tf_aws_ipv6.txt · Last modified: by 127.0.0.1
