简体   繁体   English

在 aws 模块中使用 Terraform Provider

[英]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.

相关问题 使用 Terraform 模块导入现有 AWS 资源 - Importing existing AWS Resources using Terraform Module 无法使用 terraform 云上的 terraform 模块更新 AWS 中 su.net 的名称 - Unable to update name of subnet in AWS using terraform module on terraform cloud 可以使用 Terraform 更新 AWS ECS 容量提供程序吗? - Can AWS ECS capacity provider be updated using Terraform? Terraform AWS | 错误:配置 Terraform AWS 提供商时出错:找不到 Terraform AWS 提供商的有效凭证源 - Terraform AWS | Error: error configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found Terraform RDS 的 AWS 供应商升级问题 - Terraform AWS provider upgrade issue with RDS AWS Terraform:│ 错误:配置 Terraform AWS 提供商时出错:验证提供商凭证时出错:调用 sts:GetCallerIdentity 时出错: - AWS Terraform: │ Error: error configuring Terraform AWS Provider: error validating provider credentials: error calling sts:GetCallerIdentity: 无法通过 terraform AWS 提供商访问 AWS 帐户——无效的 AMI - Unable to access AWS account through terraform AWS provider -- invalid AMI 无法通过 terraform AWS 供应商访问 AWS 账户—— - Unable to access AWS account through terraform AWS provider -- 在所有 AWS 区域部署 terraform 模块 - deploy terraform module all AWS regions AWS Codepipeline 在 Terraform 中使用命名空间 - AWS Codepipeline using namespaces in Terraform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM