如何在terraform中的同一文件中运行多个PUL模块?

如何在terraform中的同一文件中运行多个PUL模块?,terraform,terraform-aws-modules,Terraform,Terraform Aws Modules,我正在使用https://github.com/cloudposse/terraform-aws-acm-request-certificate使用terraform和aws生成证书 如何在terraform中的同一文件中运行多个PUL域?(非子域) 我尝试此操作,但出现错误错误:重复模块调用: module "acm_request_certificate" { source = "git::https:/

我正在使用
https://github.com/cloudposse/terraform-aws-acm-request-certificate
使用terraform和aws生成证书

如何在terraform中的同一文件中运行多个PUL域?(非子域)

我尝试此操作,但出现错误
错误:重复模块调用

module "acm_request_certificate" {
  source                            = "git::https://github.com/cloudposse/terraform-aws-acm-request-certificate.git?ref=master"
  domain_name                       = "example.com"
  process_domain_validation_options = true
  ttl                               = "300"
}

module "acm_request_certificate" {
  source                            = "git::https://github.com/cloudposse/terraform-aws-acm-request-certificate.git?ref=master"
  domain_name                       = "otherexample.com"
  process_domain_validation_options = true
  ttl                               = "300"
}
我正在寻找以下解决方案:

const domains = ["example.com", "otherexample.com"]

foreach(domain of domains) {
 module "acm_request_certificate" {
  source                            = "git::https://github.com/cloudposse/terraform-aws-acm-request-certificate.git?ref=master"
  domain_name                       = domain
  process_domain_validation_options = true
  ttl                               = "300"
 }
}

首先,两个模块使用相同的名称。 它们应该不同,例如:

module "acm_request_certificate_example" {
  source                            = "git::https://github.com/cloudposse/terraform-aws-acm-request-certificate.git?ref=master"
  domain_name                       = "otherexample.com"
  process_domain_validation_options = true
  ttl                               = "300"
}

module "acm_request_certificate_other_example" {
  source                            = "git::https://github.com/cloudposse/terraform-aws-acm-request-certificate.git?ref=master"
  domain_name                       = "otherexample.com"
  process_domain_validation_options = true
  ttl                               = "300"
}
此外,在terraform 0.13中,您可以将foreach用于模块

# my_buckets.tf
module "bucket" {
  for_each = toset(["assets", "media"])
  source   = "./publish_bucket"
  name     = "${each.key}_bucket"
}

请参阅中的详细信息。

首先,两个模块使用相同的名称。 它们应该不同,例如:

module "acm_request_certificate_example" {
  source                            = "git::https://github.com/cloudposse/terraform-aws-acm-request-certificate.git?ref=master"
  domain_name                       = "otherexample.com"
  process_domain_validation_options = true
  ttl                               = "300"
}

module "acm_request_certificate_other_example" {
  source                            = "git::https://github.com/cloudposse/terraform-aws-acm-request-certificate.git?ref=master"
  domain_name                       = "otherexample.com"
  process_domain_validation_options = true
  ttl                               = "300"
}
此外,在terraform 0.13中,您可以将foreach用于模块

# my_buckets.tf
module "bucket" {
  for_each = toset(["assets", "media"])
  source   = "./publish_bucket"
  name     = "${each.key}_bucket"
}
请参阅中的详细信息