Amazon web services 地形模块和提供者

Amazon web services 地形模块和提供者,amazon-web-services,terraform,Amazon Web Services,Terraform,我有一个模块,它定义了一个提供者,如下所示 provider "aws" { region = "${var.region}" shared_credentials_file = "${module.global_variables.shared_credentials_file}" profile = "${var.profile}" } resource "aws_instance" "node" {

我有一个模块,它定义了一个提供者,如下所示

provider "aws" {
    region                  = "${var.region}"
    shared_credentials_file = "${module.global_variables.shared_credentials_file}"
    profile                 = "${var.profile}"
}
resource "aws_instance" "node" {
    ami = "${lookup(var.ami, var.region)}"
    key_name   = "ib-us-east-2-production"
    instance_type = "${var.instance_type}"
    count = "${var.count}"
    security_groups = "${var.security_groups}"
    tags {
        Name = "${var.name}"
    }
    root_block_device {
        volume_size = 100
    }
下面是一个EC实例

provider "aws" {
    region                  = "${var.region}"
    shared_credentials_file = "${module.global_variables.shared_credentials_file}"
    profile                 = "${var.profile}"
}
resource "aws_instance" "node" {
    ami = "${lookup(var.ami, var.region)}"
    key_name   = "ib-us-east-2-production"
    instance_type = "${var.instance_type}"
    count = "${var.count}"
    security_groups = "${var.security_groups}"
    tags {
        Name = "${var.name}"
    }
    root_block_device {
        volume_size = 100
    }
在调用此模块的terraform脚本中,我现在想创建一个ELB,并将其附加到实例上,并使用以下内容将其指向实例:

resource "aws_elb" "node_elb" {
    name               = "${var.name}-elb"
    .........
但是terraform不断提示我模块中已经定义的aws区域。唯一的解决方法是将provider块复制到调用模块的文件中。有没有更干净的方法

唯一的解决方法是将provider块复制到调用模块的文件中

提供程序块实际上应该在调用模块的文件中,您可以将其从模块中删除

从文档中:

为方便进行简单配置,子模块会自动从其父模块继承默认(无别名)提供程序配置。这意味着显式提供程序块仅出现在根模块中,而下游模块可以简单地为该提供程序声明资源,并使其自动与根提供程序配置关联