Terraform Error: Incorrect attribute value type for subnet_ids vpc modules
Terraform Error: Incorrect attribute value type for subnet_ids vpc modules
当我在版本 12.24 中 运行 terraform plan 时,我收到错误:不正确的属性值类型。
Error: Incorrect attribute value type
on .terraform/modules/app/main.tf line 134, in resource "aws_db_subnet_group" "db_subnet_group":
134: subnet_ids = var.subnets
|----------------
| var.subnets is list of tuple with 1 element
Inappropriate value for attribute "subnet_ids": incorrect set element type:
string required.
tf 文件中的代码:
resource "aws_db_subnet_group" "db_subnet_group" {
count = "${var.create_subnet_group ? 1 : 0}"
name_prefix = "${var.name}-"
description = "Database subnet group for ${var.name}"
subnet_ids = var.subnets
variables.tf 文件:
variable "subnets" {
description = "Subnets for RDS Instances"
type = "list"
}
我该如何解决这个问题?
错误消息说您有 list of tuple with 1 element
,这意味着 var.subnets
的形式为:
variable "subnets" {
description = "Subnets for RDS Instances"
type = "list"
default = [["subnet-070db0eee8c5f3bb1", "subnet-01e76559b44d06aa3"]]
}
因此,要使用内部列表(即元组),您必须这样做:
resource "aws_db_subnet_group" "db_subnet_group" {
# other attributes not shown
subnet_ids = var.subnets[0]
}
当我在版本 12.24 中 运行 terraform plan 时,我收到错误:不正确的属性值类型。
Error: Incorrect attribute value type
on .terraform/modules/app/main.tf line 134, in resource "aws_db_subnet_group" "db_subnet_group":
134: subnet_ids = var.subnets
|----------------
| var.subnets is list of tuple with 1 element
Inappropriate value for attribute "subnet_ids": incorrect set element type:
string required.
tf 文件中的代码:
resource "aws_db_subnet_group" "db_subnet_group" {
count = "${var.create_subnet_group ? 1 : 0}"
name_prefix = "${var.name}-"
description = "Database subnet group for ${var.name}"
subnet_ids = var.subnets
variables.tf 文件:
variable "subnets" {
description = "Subnets for RDS Instances"
type = "list"
}
我该如何解决这个问题?
错误消息说您有 list of tuple with 1 element
,这意味着 var.subnets
的形式为:
variable "subnets" {
description = "Subnets for RDS Instances"
type = "list"
default = [["subnet-070db0eee8c5f3bb1", "subnet-01e76559b44d06aa3"]]
}
因此,要使用内部列表(即元组),您必须这样做:
resource "aws_db_subnet_group" "db_subnet_group" {
# other attributes not shown
subnet_ids = var.subnets[0]
}