【发布时间】:2020-10-09 19:21:23
【问题描述】:
我们有一个相当复杂的环境,我们在多个区域拥有大量 AWS 账户,这些账户都通过 VPN 隧道连接到中转网络。
目前,我们通过“VPC”模块为区域中的每个 VPC 部署客户网关,但我们遇到的问题是部署第一个 VPC 很好,但随后的 VPC 部署会导致 CGW 已经存在的问题在那里,所以我们必须先导入它,然后才能继续,这不是一个理想的地方,而且我认为如果我们拆除 VPC,它可能会试图杀死其他 VPN 正在使用的 CGW .
我想要做的是将 CGW 与 VPC 分开部署,然后 VPC 为 CGW 进行数据查找。
我一直在想,也许我们可以使用我们的“基础”作业来配置变量文件中定义的 CGW,但到目前为止我没有尝试过任何工作。
变量定义为:
variable "region_data" {
type = list(object({
region = string
deploy_cgw = bool
gateways = any
}))
default = [
{
region = "eu-west-1"
deploy_cgw = true
gateways = [
{
name = "gateway1"
ip = "1.2.3.4"
},
{
name = "gateway2"
ip = "2.3.4.5"
}
]
},
{
region = "us-east-1"
deploy_cgw = true
gateways = [
{
name = "gateway1"
ip = "2.3.4.5"
},
{
name = "gateway2"
ip = "3.4.5.6"
}
]
}
]
}
我尝试了一些方法,例如:
locals {
regions = [for region in var.region_data : region if region.deploy_cgw]
cgws = flatten([
for region in local.regions : [
for gateway in region.gateways : {
region = region.region
name = gateway.name
ip = gateway.ip
}
]
])
}
provider "aws" {
region = "eu-west-1"
alias = "eu-west-1"
}
provider "aws" {
region = "us-east-1"
alias = "us-east-1"
}
module "cgw" {
source = "../../../modules/customer-gateway"
for_each = { for cgw in local.cgws: "${cgw.region}.${cgw.name}" => cgw }
name_tag = each.value.name
ip_address = each.value.ip
providers = {
aws = "aws.${each.value.region}"
}
}
但是有了这个我得到:
Error: Invalid provider configuration reference
on main.tf line 439, in module "cgw":
439: aws = "aws.${each.value.region}"
A provider configuration reference must not be given in quotes.
如果我将 AWS 提供商移动到模块中并将区域作为参数传递,我会得到以下信息:
Error: Module does not support for_each
on main.tf line 423, in module "cgw":
423: for_each = { for cgw in local.testing : "${cgw.region}.${cgw.name}" => cgw }
Module "cgw" cannot be used with for_each because it contains a nested
provider configuration for "aws", at
我已经做了很多研究,我了解的最后一个是 Terraform 采取强硬立场的东西。
我问的可能吗?
【问题讨论】:
标签: amazon-web-services terraform terraform-provider-aws