简体   繁体   English

Terraform:远程模块未遵循提供程序块 - 警告:引用未定义的提供程序

[英]Terraform: remote module not following providers block - Warning: Reference to undefined provider

I'm trying to use a (private) remote terraform module, and trying to pass a different provider to it.我正在尝试使用(私有)远程 terraform 模块,并尝试将不同的提供程序传递给它。 For the remote module, there are no providers defined and to my understanding, it will use a the local provider instead.对于远程模块,没有定义提供程序,据我了解,它将使用本地提供程序。

I can't seem to be able to get it to use a provider alias - there are a few files at play here:我似乎无法让它使用提供者别名 - 这里有一些文件在起作用:

# main.tf
provider "aws" {
  region = var.aws_region

}

provider "aws" {
  alias  = "replica_region"
  region = var.replica_region
}

terraform {
  backend "s3" {
  }
}
# s3.tf
module "some-remote-module" {
  source = 'git::ssh.......'
  providers = {
    aws = aws.replica_region
  }
}

Whenever I plan (with terragrunt), The region is that of the primary aws provider config.每当我计划(使用 terragrunt)时,该区域就是主要 aws 提供程序配置的区域。 I get the following warning, too:我也收到以下警告:

│ Warning: Reference to undefined provider
│
│   on s3.tf line 12, in module "some-remote-module":
│   12:     aws = aws.replica_region
│
│ There is no explicit declaration for local provider name "aws" in
│ module.some-remote-module, so Terraform is assuming you
│ mean to pass a configuration for "hashicorp/aws".
│
│ If you also control the child module, add a required_providers entry named
│ "aws" with the source address "hashicorp/aws".
╵

Am I passing the providers in incorrectly?我是否错误地传递了提供程序? Is this even something that terraform is capable of?这甚至是 terraform 能够做到的吗? I'm using terraform 1.3.我正在使用 terraform 1.3。 The remote module doesn't have any provider config.远程模块没有任何提供者配置。

The last paragraph of this message is suggesting that you modify the child module to include the following declaration so that it's explicit that when you say "aws" it means hashicorp/aws rather than a provider in some other namespace that might coincidentally also be called "aws":此消息的最后一段建议您修改子模块以包含以下声明,以便明确表示当您说“aws”时,它表示hashicorp/aws而不是某个其他命名空间中的提供者,可能巧合地也称为“ aws”:

terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
    }
  }
}

This is what the error message means by a required_providers entry named "aws" with the source address "hashicorp/aws" .这就是错误消息的含义, a required_providers entry named "aws" with the source address "hashicorp/aws"

This allows Terraform to see for certain (rather than guessing) that the short name "aws" refers to the same provider in both the calling module and the called module.这使得 Terraform 可以确定(而不是猜测)短名称“aws”指的是调用模块和被调用模块中的同一提供程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM