我正在使用terraform创建RDS实例,为此,我需要拥有一个 aws_db_subnet_group 资源。我可以使用由亚马逊网站创建的aws_db_subnet_group创建RDS,但是当我尝试从Terraform脚本创建aws_db_subnet_group时,会收到错误InvalidParameterValue。
这是terraform脚本:
resource "aws_db_subnet_group" "default" {
name = "cse-cr"
description = "Private subnets for RDS instance"
subnet_ids = ["subnet-0c8764fcb28b04c8c", "subnet-0ca53ff9b621e2c89"]
}
这是错误:
Error: Error applying plan:
1 error(s) occurred:
* aws_db_subnet_group.default: 1 error(s) occurred:
* aws_db_subnet_group.default: Error creating DB Subnet Group: InvalidParameterValue: Some input subnets in :[subnet-0ca53ff9b621e2c89, subnet-0c8764fcb28b04c8c] are invalid.
status code: 400, request id: 66166ec8-9b79-41d3-bdf7-a5cdb66f5f95
Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
我在互联网上看到了多个示例,唯一的区别是我使用的是2个由其他人而不是从Terraform脚本创建的现有子网。
命令结果:
aws ec2 describe-subnets --subnet-ids subnet-0ca53ff9b621e2c89 subnet-0c8764fcb28b04c8c
{
"Subnets": [
{
"AvailabilityZone": "us-east-1a",
"AvailableIpAddressCount": 250,
"CidrBlock": "10.112.173.0/24",
"DefaultForAz": false,
"MapPublicIpOnLaunch": false,
"State": "available",
"SubnetId": "subnet-0ca53ff9b621e2c89",
"VpcId": "vpc-0ec46ccebc8108670",
"AssignIpv6AddressOnCreation": false,
"Ipv6CidrBlockAssociationSet": [],
"Tags": [
]
},
{
"AvailabilityZone": "us-east-1b",
"AvailableIpAddressCount": 251,
"CidrBlock": "10.112.174.0/24",
"DefaultForAz": false,
"MapPublicIpOnLaunch": false,
"State": "available",
"SubnetId": "subnet-0c8764fcb28b04c8c",
"VpcId": "vpc-0ec46ccebc8108670",
"AssignIpv6AddressOnCreation": false,
"Ipv6CidrBlockAssociationSet": [],
"Tags": [
]
}
]
}
答案 0 :(得分:0)
尝试像这样首先使用aws_vpc数据源:
data "aws_subnet" "subnet1" {
id = "subnet-0c8764fcb28b04c8c"
}
data "aws_subnet" "subnet2" {
id = "subnet-0ca53ff9b621e2c89"
}
resource "aws_db_subnet_group" "default" {
name = "cse-cr"
description = "Private subnets for RDS instance"
subnet_ids = [data.aws_subnet.subnet1.id, data.aws_subnet.subnet2.id]
}
答案 1 :(得分:0)
您可能想要检查您的 terraform 默认所在的区域,因为如果代码针对错误的区域执行,它可能会出错。