0
votes

please help to understand how I can import variables files from a different location? I have tried to do this from the module system, but it's not working for me.

My structure :

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

How I can import variables from root folder? Need to specify it somehow on main.tf

My /my_ec2/main.tf

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

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

my /variables.tf

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

How can I do this? P.S. Did the same with "${var.region_aws}", but same result

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
When you say it's not working for you do you get an error or just behaviour you weren't expecting? If you get an error can you edit your question to include the full error output?ydaetskcoR

1 Answers

1
votes

Maybe use :

"${module.global_vars.region_aws}"

Instead of

"module.global_vars.region_aws"