Terraform: Terraform should fail when interpolating nonexistent template vars in output variable

Created on 3 Mar 2017  ยท  4Comments  ยท  Source: hashicorp/terraform

Terraform Version

0.8.8

Affected Resource(s)

  • data template_file
  • output variables
  • probably more resources that depend on the output variable

Terraform Configuration Files

in main.tf

module "test" {
  source = "module1/"
}

module "test2" {
  source = "module2/"
  input_var = "${module.test.my_output}"
}

in module1/test.tf

data "template_file" "tpl" {
  template = "whatever"
  vars = {
  }
}

output "my_output" {
  value = "${data.template_file.tpl.vars.doesntexist}"
}

in module2/test.tf

variable "input_var" { }

data "template_file" "tpl2" {
  template = "$${OtherVariable}"
  vars = {
    OtherVariable = "test"
    Variable = "${var.input_var}"
  }
}

Expected Behavior

Referencing the nonexistent variable in the output variable should have failed with an error.

Actual Behavior

Apply fails with: * data.template_file.tpl2: failed to render : 1:3: unknown variable accessed: OtherVariable

Note that it's failing on the "wrong" variable, which caused some head-scratching.

Steps to Reproduce

  1. terraform get
  2. terraform apply
bug config

Most helpful comment

Thanks @ketzacoatl, this also should have been closed.
The next release will have even more type information, and can present an error even earlier.

You would see something along the lines of:

Error: Missing map element

  on module1/main.tf line 9, in output "my_output":
   9:   value = data.template_file.tpl.vars.doesntexist
    |----------------
    | data.template_file.tpl.vars is map of string with 0 elements

This map does not have an element with the key "doesntexist".

All 4 comments

Related to #12403. Once outputs can produce errors, this may take care of itself.

Bump, silent failures like this lead to really bad problems down the pipeline.

EDIT, the related tickets have been closed, so maybe this is also resolved?

EDIT: #12403 was a dupe of #9080.

Thanks @ketzacoatl, this also should have been closed.
The next release will have even more type information, and can present an error even earlier.

You would see something along the lines of:

Error: Missing map element

  on module1/main.tf line 9, in output "my_output":
   9:   value = data.template_file.tpl.vars.doesntexist
    |----------------
    | data.template_file.tpl.vars is map of string with 0 elements

This map does not have an element with the key "doesntexist".

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings