https://dev.classmethod.jp/articles/expanding-vpc-cidr/
https://dev.classmethod.jp/articles/i-tried-to-add-and-remove-secondary-cidr-in-an-existing-amazon-vpc/
https://docs.aws.amazon.com/cli/latest/reference/ec2/associate-vpc-cidr-block.html
セカンダリCIDRを追加可能
cat <<-'EOF' > main.tf
provider "aws" {
region = "ap-northeast-1"
}
resource "aws_vpc" "vpc01" {
cidr_block = "10.0.0.0/16"
enable_dns_support = true
enable_dns_hostnames = true
tags = {
Name = "vpc01"
}
}
resource "aws_subnet" "subnet01" {
vpc_id = aws_vpc.vpc01.id
availability_zone = "ap-northeast-1a"
cidr_block = "10.0.0.0/24"
tags = {
Name = "subnet01"
}
}
resource "aws_internet_gateway" "igw01" {
vpc_id = aws_vpc.vpc01.id
tags = {
Name = "igw01"
}
}
resource "aws_route_table" "rt01" {
vpc_id = aws_vpc.vpc01.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.igw01.id
}
tags = {
Name = "rt01"
}
}
resource "aws_route_table_association" "rt01_subnet01" {
route_table_id = aws_route_table.rt01.id
subnet_id = aws_subnet.subnet01.id
}
resource "aws_security_group" "sg01" {
name ="sg01"
vpc_id = aws_vpc.vpc01.id
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["10.1.0.0/24"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_instance" "vm01"{
ami = "ami-0404778e217f54308"
instance_type = "t3.nano"
key_name = "key1"
tags = {
Name = "vm01"
}
subnet_id = aws_subnet.subnet01.id
instance_market_options {
market_type = "spot"
spot_options {
spot_instance_type = "one-time"
}
}
vpc_security_group_ids =[aws_security_group.sg01.id]
associate_public_ip_address = true
}
EOF
terraform init
terraform fmt
terraform -version
terraform plan
terraform apply -auto-approve
# terraform destroy -auto-approve
-- 2. セカンダリCIDRを追加
aws ec2 associate-vpc-cidr-block \
--vpc-id vpc-11111111111111111 \
--cidr-block 10.1.0.0/16
aws ec2 describe-vpcs