gpt4 book ai didi

terraform - 将多个提供程序别名传递给 terraform 0.12.13 中的模块

转载 作者:行者123 更新时间:2023-12-03 15:03:12 25 4
gpt4 key购买 nike

我正在构建需要与两个不同的 AWS 账户通信的代码,文档说这应该可以工作。这在 0.11.14 下工作

总的来说,在我的 providers.tf 文件中,我有:

provider "aws" {
alias = "ca-central-1"
region = "ca-central-1"
profile = var.aws_profile
}

provider "aws" {
alias = "other-ca-central-1"
region = "ca-central-1"
profile = var.aws_other_profile
}

(这些变量在我的凭证文件中设置了正确的配置文件。)

在根目录中,在调用模块的代码中,
module "obfuscated" {
source = "./modules/obfuscated"
providers = {
aws.main = "aws.ca-central-1"
aws.other = "aws.other-ca-central-1"
}
#other stuff
}

在 ./modules/obfuscated/main.tf 我有
provider "aws" {
alias = "main"
}
provider "aws" {
alias = "other"
}

文档说是占位符,只能为空或有别名。没有它,它会提示提供者不存在。
但是有了它,它提示我没有指定与文档冲突的区域。

当然文档不可能是错的,不,这不可能..帮助我obi-wan-overflow..

最佳答案

这是我如何处理问题的示例

#af-south-1
data aws_vpcs af-south-1 {
provider = aws.af-south-1
}

module af-south-1 {
source = "./modules/flow_log"
providers = {
aws = aws.af-south-1
}
iam_role_arn = aws_iam_role.vpc_flow_log.arn
log_destination = aws_s3_bucket.vpc_flow_log.arn
log_destination_type = "s3"
traffic_type = "REJECT"
aws_vpc_ids = data.aws_vpcs.af-south-1.ids
depends_on = [ aws_s3_bucket.vpc_flow_log ]
}

#ap-east-1
data aws_vpcs ap-east-1 {
provider = aws.ap-east-1
}

module ap-east-1 {
source = "./modules/flow_log"
providers = {
aws = aws.ap-east-1
}
iam_role_arn = aws_iam_role.vpc_flow_log.arn
log_destination = aws_s3_bucket.vpc_flow_log.arn
log_destination_type = "s3"
traffic_type = "REJECT"
depends_on = [ aws_s3_bucket.vpc_flow_log ]
aws_vpc_ids = data.aws_vpcs.ap-east-1.ids
}

#ap-northeast-1
data aws_vpcs ap-northeast-1 {
provider = aws.ap-northeast-1
}
....
在这个例子中,我正在创建一个数据源 aws_vpcs对于每个提供者区域。然后我将每个区域的 id 列表传递到模块中。此时您必须指定要使用的模块提供程序,除非您使用的是默认提供程序。

关于terraform - 将多个提供程序别名传递给 terraform 0.12.13 中的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58733449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com