[英]Using Terraform Provider in aws module
I am going through the terraform documentation, and it seems unclear to me.我正在浏览 terraform 文档,但我似乎不清楚。 I'm quite new to Terraform so no doubt i'm misunderstanding something here: https://developer.hashicorp.com/terraform/language/modules/develop/providers
我对 Terraform 很陌生,所以毫无疑问我在这里误解了一些东西: https://developer.hashicorp.com/terraform/language/modules/develop/providers
Problem:问题:
My terraform pipeline is returning the following warning:我的 terraform 管道返回以下警告:
│
│ on waf-cdn.tf line 9, in module "waf_cdn":
│ 9: aws = aws.useastone
│
│ Module module.waf_cdn does not declare a provider named aws.
│ If you wish to specify a provider configuration for the module, add an entry for aws in the required_providers block within the module.
My root module is calling a child waf module.我的根模块正在调用一个子 waf 模块。 I understand that i need to configure my provider within my root module.
我知道我需要在我的根模块中配置我的提供者。 There are 2 files within my root module:
我的根模块中有 2 个文件:
...terraform.tf... ...terraform.tf...
terraform {
backend "s3" {}
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.33.0"
}
random = {
source = "hashicorp/random"
version = "3.1.0"
}
local = {
source = "hashicorp/local"
version = "2.1.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.0.1"
}
}
}
...and providers.tf... ...和提供者.tf ...
provider "aws" {
region = var.region
assume_role {
role_arn = "arn:aws:iam::${var.account_id}:role/${local.role_name}"
}
}
provider "aws" {
region = "us-east-1"
alias = "useastone"
assume_role {
role_arn = "arn:aws:iam::${var.account_id}:role/${local.role_name}"
}
}
provider "aws" {
region = var.region
alias = "master"
assume_role {
role_arn = replace(
"arn:aws:iam::${var.master_account_id}:role/${local.role_name}",
local.app_region,
"master"
)
}
}
When calling the child module, the SCOPE attribute of the waf needs to specify the region as us-east-1 for CLOUDFRONT as it is a global service in AWS.在调用子模块时,waf的SCOPE属性需要指定区域为us-east-1,因为CLOUDFRONT是AWS的全球服务。 Therefore, i need to pass the useastone provider when calling the child waf module as seen below:
因此,我需要在调用子 waf 模块时传递 useastone 提供程序,如下所示:
module "waf_cdn" {
source = "../modules/qa-aws-waf-common"
name = "${local.waf_prefix}-cdn"
logging_arn = aws_kinesis_firehose_delivery_stream.log_stream_cdn.arn
scope = "CLOUDFRONT"
tags = merge(module.tags.tags, { name = "${local.name_prefix}-qa-waf-cdn" })
providers = {
aws = aws.useastone
}
}
With this code i'm getting the error show above.使用此代码,我得到上面的错误显示。
I'm banging my head against the documentation here so any help guys would be really appreciated.我在这里反对文档,所以非常感谢任何帮助的人。
Here's hoping, thanks!在此希望,谢谢!
As per the documentation you linked, here is the passage you are interested in [1]:根据您链接的文档,这是您对 [1] 感兴趣的段落:
Additional provider configurations (those with the
alias
argument set) are never inherited automatically by child modules, and so must always be passed explicitly using the providers map.额外的提供者配置(带有
alias
参数集的那些)永远不会被子模块自动继承,因此必须始终使用提供者 map 显式传递。
Since that is the case, you need to define the provider(s) on the module level as well:由于是这种情况,您还需要在模块级别定义提供者:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.33.0"
configuration_aliases = [ aws.useastone ]
}
}
}
That would probably be an additional providers.tf
file in ../modules/qa-aws-waf-common
.这可能是
../modules/qa-aws-waf-common
中的一个额外的providers.tf
文件。
[1] https://developer.hashicorp.com/terraform/language/modules/develop/providers#passing-providers-explicitly [1] https://developer.hashicorp.com/terraform/language/modules/develop/providers#passing-providers-explicitly
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.