У меня есть модуль, который определяет провайдера следующим образом
provider "aws" {
region = "${var.region}"
shared_credentials_file = "${module.global_variables.shared_credentials_file}"
profile = "${var.profile}"
}
и экземпляр EC следующим образом
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, который уже определен в модуле. Единственный способ обойти это — скопировать блок провайдера в файл, вызывающий модуль. Есть ли более чистый способ приблизиться к этому?
The only way around this is to copy the provider block into the file calling the module.
Блок провайдера должен быть в вашем файле, вызывающем модуль, и вы можете удалить его из своего модуля.
Из документов:
For convenience in simple configurations, a child module automatically inherits default (un-aliased) provider configurations from its parent. This means that explicit provider blocks appear only in the root module, and downstream modules can simply declare resources for that provider and have them automatically associated with the root provider configurations.
https://www.terraform.io/docs/configuration/modules.html#implicit-provider-inheritance