从模块Terraform导入变量

时间:2020-03-12 16:20:42

标签: terraform terraform-provider-aws

请帮助了解如何从其他位置导入变量文件? 我已经尝试从模块系统执行此操作,但是它对我不起作用。

我的结构:

/
/variables.tf
/my_ec2/main.tf
/my_ec2/variables.tf

如何从根文件夹导入变量?需要在main.tf上以某种方式指定

我的/my_ec2/main.tf

module "global_vars" {
  source = "../../../"
}

provider "aws" {
  region = "module.global_vars.region_aws"
}

我的/variables.tf

variable "region_aws" {
  default = "eu-central-1"
}

我该怎么做? 附言与“ $ {var.region_aws}”相同,但结果相同

Error: Reference to undeclared input variable

  on ../my_ec2/main.tf line 10, in resource "aws_instance" "server":
  10:     region = "${var.region_aws}"

An input variable with the name "aws_instance" has not been declared. This
variable can be declared with a variable "environment" {} block.

1 个答案:

答案 0 :(得分:1)

也许使用:

"${module.global_vars.region_aws}"

代替

"module.global_vars.region_aws"