Terraform 在创建时不会为 EC2 实例分配公共 IP 地址
通过 EC2 控制台手动创建时会分配公共 IP 地址
子网仅在公共网络中,请帮忙
创建子网时,请在 terraform 文件中添加此行。
map_public_ip_on_launch = true
# AWS VPC
resource "aws_vpc" "my_vpc" {
cidr_block = "172.16.0.0/16"
tags = {
Name = "tf-example"
}
}
# AWS SUBNET ATTACHED TO THE AWS VPC
resource "aws_subnet" "my_subnet" {
vpc_id = aws_vpc.my_vpc.id
cidr_block = "172.16.10.0/24"
availability_zone = "af-south-1a"
# this line give you a public IP address
map_public_ip_on_launch = true
tags = {
Name = "tf-example"
}
}
这不再准确。现在是:associate_public_ip_address = true