terraform - 从 Terraform 创建 AWS_ALB
问题描述
我正在尝试通过 terraform 创建一个简单的 AWS_ALB,我创建了一个带有公共子网和私有子网的单独 VPC,但是 ALB 创建给了我 invalidSubnet 错误
resource "aws_alb" "test" {
name = "test-alb-tf"
internal = false
security_groups = ["sg-0385b126e18d3ca67"]
subnets = ["192.168.11.0/24"]
}
公共子网创建如下
{
"MapPublicIpOnLaunch": true,
"AvailabilityZoneId": "use1-az2",
"Tags": [
{
"Value": "staging",
"Key": "Environment"
},
{
"Value": "secure-public-us-east-1a",
"Key": "Name"
},
{
"Value": "true",
"Key": "Terraform"
}
],
"AvailableIpAddressCount": 250,
"DefaultForAz": false,
"SubnetArn": "arn:aws:ec2:us-east-1:041840987519:subnet/subnet-03757baf0df052c07",
"Ipv6CidrBlockAssociationSet": [],
"VpcId": "vpc-00689d5ff034a0c99",
"State": "available",
"AvailabilityZone": "us-east-1a",
"SubnetId": "subnet-03757baf0df052c07",
"OwnerId": "041840987519",
"CidrBlock": "192.168.11.0/24",
"AssignIpv6AddressOnCreation": false
},
这就是 terraform 计划显示的内容
# aws_alb.test will be created
+ resource "aws_alb" "test" {
+ arn = (known after apply)
+ arn_suffix = (known after apply)
+ dns_name = (known after apply)
+ enable_deletion_protection = false
+ enable_http2 = true
+ id = (known after apply)
+ idle_timeout = 60
+ internal = false
+ ip_address_type = (known after apply)
+ load_balancer_type = "application"
+ name = "test-alb-tf"
+ security_groups = [
+ "sg-0385b126e18d3ca67",
]
+ subnets = [
+ "192.168.11.0/24",
]
+ vpc_id = (known after apply)
+ zone_id = (known after apply)
+ subnet_mapping {
+ allocation_id = (known after apply)
+ subnet_id = (known after apply)
}
}
这是我得到的错误
Error: Error creating application Load Balancer: InvalidSubnet: The subnet ID '192.168.11.0/24' is not valid
status code: 400, request id: 5521ae30-dc0b-4f4c-ae89-47eb729126c7
任何人都知道我错过了什么
解决方案
所以错误清楚地表明了问题。
The subnet ID '192.168.11.0/24' is not valid
您是否登录了 aws 控制台并检查了要分配给此 ALB 的子网?它的 id 为subnet-xxxxxxxx
推荐阅读
- ios - 如何使用 Metal 绘制带纹理的矩形
- android - 用于运行反应原生地理定位应用程序的 Android 配置
- react-native - React 原生 Clevertap 推送通知集成
- javascript - Ajax 发布错误:已通过 HTTPS 加载,但请求了不安全的 XMLHttpRequest 端点
- android - Retrofit2 Api 调用错误未在 Recycler 视图中显示结果
- makefile - 使用 Makefile 使用外部库编译 Fortran 77
- arrays - 在 mongodb 中查询深度嵌套的数组
- java - 计算 cardSum(字符串的手)
- php - 如何将数据导出到 Excel 模板,保留 VBA 代码和数据验证,使用 PHP?
- docker - 在集群/Docker-Swarm 中映射 Docker 卷