gpt4 book ai didi

terraform - 构建具有多个级别的 map 列表

转载 作者:行者123 更新时间:2023-12-03 01:48:27 25 4
gpt4 key购买 nike

这个snippet几乎完全显示了我正在尝试构建的内容。除了我的情况之外,我没有设置 aws_lb 的subnet_mapping 列表,而是设置 aws_cloudfront_distribution 的来源列表。具体来说,请注意 origin 包含 custom_origin_config,因此它是一个 map 列表,其中 map 的值是另一个 map 的键。

我尝试这样做:

resource "aws_cloudfront_distribution" "foo" { 
...
origin = "${null_resource.origins.*.triggers}"
...
}

resource "null_resource" "origins" {
count = "${length(var.origin_ids)}"
triggers {
domain_name = "${element(var.origin_domains, count.index)}"
origin_id = "${element(var.origin_ids, count.index)}"

custom_origin_config {
http_port = "${local.http_port}"
https_port = "${local.https_port}"
origin_protocol_policy = "http-only"
origin_ssl_protocols = "${local.origin_ssl_protocols}"
}
}

但我遇到错误:

... got unconvertible type '[]map[string]interface {}'

最佳答案

null_resource 触发器仅排除任意字符串,因此 map 将被拒绝。似乎 null_resource 太过分了,因为您的 custom_origin_config 并不依赖于 count.index

有什么理由不能简单地这样做吗?

resource "aws_cloudfront_distribution" "foo" {
count = length(local.origin_ids)

origin {
domain_name = var.origin_domains[count.index]
origin_id = var.origin_ids[count.index]

custom_origin_config {
http_port = local.http_port
https_port = local.https_port

origin_protocol_policy = "http-only"
origin_ssl_protocols = local.origin_ssl_protocols
}
}
}

关于terraform - 构建具有多个级别的 map 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52939636/

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