如何在地形中对嵌套列表中的第一个元素进行切片



我想将var.domain_names作为list(list(string))传递,例如:

domain_names = [
["foo.com",".*foo-1.com",".*foo-2.com"],
["bar.com",".*bar-1.com"],
...
]

所以它应该为 foo.com 创建证书,bar.com...但是添加其他类似.*foo-1.com...到subject_alternative_names。

请帮我解决这个问题,使用地形 0.12.18

resource "aws_acm_certificate" "certificate" {
domain_name               = var.domain_names[count.index]
subject_alternative_names = slice(var.domain_names, 1, length(var.domain_names))
validation_method         = var.validation_method
tags = {
Name      = var.domain_names[count.index]
owner     = "xx"
terraform = "true"
}
lifecycle {
create_before_destroy = true
}
}

您可以使用mapfor_each循环来实现此目的。例如:

variable "domain_names" {
type = map(list(string))
default = {
"foo.com" = ["foo.com", ".*foo-1.com", ".*foo-2.com"]
"bar.com" = [".*bar-1.com"]
}
}
resource "aws_acm_certificate" "certificate" {
for_each                  = var.domain_names
domain_name               = each.key
subject_alternative_names = each.value
validation_method         = var.validation_method
tags = {
Name      = each.key
owner     = "xx"
terraform = "true"
}
lifecycle {
create_before_destroy = true
}
}

有关循环和条件的详细信息,请参阅此博客文章。

相关内容

  • 没有找到相关文章

最新更新