【问题标题】:vpc_zone_identifier should be a listvpc_zone_identifier 应该是一个列表
【发布时间】:2017-08-29 14:39:20
【问题描述】:

我不明白这一点。在执行 terraform 计划时,它抱怨该值应该是一个列表。很公平。让我们逐步分解。

错误

1 error(s) occurred:

* module.instance-layer.aws_autoscaling_group.mariadb-asg: vpc_zone_identifier: should be a list

设置

VPC 和子网是在另一个模块中使用 terraform 创建的。 该模块的输出如下:

"subnets_private": {
                    "sensitive": false,
                    "type": "string",
                    "value": "subnet-1234aec7,subnet-1234c8a7"
                },

在我的 main.tf 中,我使用所述模块的输出将其输入到我的模块的变量中,该变量负责处理自动缩放组:

  subnets_private                         = "${module.static-layer.subnets_private}"

这在模块中用于要求变量:

variable "subnets_private" {}

这是我配置 vpc_zone_identifier 的部分:

尝试:拆分

resource "aws_autoscaling_group" "mariadb-asg" {
  vpc_zone_identifier  = "${split(",",var.subnets_private)}"

尝试:列表

resource "aws_autoscaling_group" "mariadb-asg" {
  vpc_zone_identifier  = "${list(split(",",var.subnets_private))}"

问题

上述对 list(split( 的尝试理论上应该有效。由于 terraform 会抱怨但不打印实际值,因此很难调试。任何建议都值得赞赏。

手动填写值。

【问题讨论】:

    标签: terraform


    【解决方案1】:

    当仔细阅读文档时,似乎拆分不会吐出干净的元素,然后可以将其放入列表中。 他们建议将括号括在字符串 ([" xxxxxxx "]) 周围,以便 terraform 将其作为列表选择。

    如果我的逻辑是正确的,那意味着 subnet-1234aec7,subnet-1234c8a7 输出为subnet-1234aec7","subnet-1234c8a7(注意引号),假设 split 命令的分隔符周围的引号与此无关。

    这是可行的解决方案

    vpc_zone_identifier  = ["${split(",",var.subnets_private)}"]
    

    【讨论】:

      【解决方案2】:

      以下帮助:

      vpc_zone_identifier  = ["${data.aws_subnet_ids.all.ids}"]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-04-17
        • 1970-01-01
        • 1970-01-01
        • 2016-05-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多