amazon-web-services - 地形错误: Incorrect attribute value type for subnet_ids vpc modules

标签 amazon-web-services syntax-error terraform terraform-provider-aws terraform-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]
}

关于amazon-web-services - 地形错误: Incorrect attribute value type for subnet_ids vpc modules,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64147194/

相关文章:

iphone - Amazon DynamoDB ProvisionedThroughputExceededException (iOS 开发工具包)

c++ - 是什么导致我在套接字代码上出现编译错误,我该如何解决?

terraform - 不使用 Terraform 文件配置器将本地文件部署到实例

要使用函数分配的 Terraform 变量

amazon-web-services - 在 Cloudformation 中管理 Lambda 处理程序凭证

amazon-web-services - Elastic Beanstalk Auto Scaling - 我应该使用哪个指标?

jquery - 无法通过Ajax请求获取CSV文本

javascript - 调用函数时在我的JS代码中未捕获到SyntaxError

amazon-web-services - 如何使用来自 terraform 同级目录的代码

json - 创建堆栈中的 Cloudformation 错误 : "ELB cannot be attached to multiple subnets in the same AZ"