我想将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
}
}
您可以使用map
和for_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
}
}
有关循环和条件的详细信息,请参阅此博客文章。