gpt4 book ai didi

terraform - vpc_zone_identifier 应该是一个列表

转载 作者:行者123 更新时间:2023-12-05 00:50:12 24 4
gpt4 key购买 nike

我不明白这一点。在执行 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 的部分:

尝试: split
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 提示但不打印实际值,因此很难调试。任何建议都值得赞赏。

手动填写值是可行的。

最佳答案

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

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

这是工作解决方案

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

关于terraform - vpc_zone_identifier 应该是一个列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45941983/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com