此snippet几乎完全显示了我要构建的内容。除了我的情况,我没有设置aws_lb的subnet_mapping列表,而是设置aws_cloudfront_distribution的来源列表。具体来说,请注意origin包含custom_origin_config,因此它是地图列表,其中地图的值是另一张地图的键。
我尝试这样做:
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}"
}
}
但是我遇到了以下错误:
...不可转换类型'[] map [string] interface {}'
答案 0 :(得分:0)
null_resource
triggers
仅排除任意字符串,因此将拒绝映射。由于您的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
}
}
}