terraform

Variable definition


I have inherited a project with two files:

a.tf
dir_name/b.tf

and each contains:

variable "region" {
  default = "us-east-1"
}

Is there any reason why I can't delete the variable definition from dir_name/b.tf as it seems to be already defined?

UPDATE

a.tf contains a module definition that goes like this:

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

Solution

  • No, you can't remove one or the other. Terraform works on the module level, where each module has an explicit set of input variables and output attributes; variables can't be passed implicitly from one script to a module.

    If you're passing variables from one place to another, it does currently result in a lot of repetition, eg:

    module "dir_name" {
      source   = "./dir_name"
      region   = "${var.region}"
    }