Terraform: depends_on broken for Data template_file

Created on 27 Sep 2016  ยท  5Comments  ยท  Source: hashicorp/terraform

Terraform Version

v0.7.4

Affected Resource(s)

  • data template_file

    Terraform Configuration Files

resource "null_resource" "discovery_token" {
  provisioner "local-exec" {
    command = "curl https://discovery.etcd.io/new?size=${var.node_count} > ${path.module}/.token"
  }
}
data "template_file" "cloud_config" {
  depends_on = ["null_resource.discovery_token"]
  template = "${file("${path.module}/templates/cloud-config.yaml")}"
  vars {
    discovery_token = "${file("${path.module}/.token")}"
  }
}

Debug Output

https://gist.github.com/stongo/1c4c16773d8b8189215c3fd48054c729

Expected Behavior

The depends_on directive should still be obeyed or else panic if it's not allowed. In this case the null_resource.discovery_token should complete before data template is updated.
If not allowed, please restore it's functionality as templating becomes very limited without any control structure.

Actual Behavior

The template data is updated before null_resource.discovery_token executes

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply
bug core

Most helpful comment

The actual issue is not in depends_on, but rather in the file interpolation function. It reads the file during validation, not during rendering the template. Just for anybody looking here is a related ticket #8406

All 5 comments

I am having the same issue on v0.7.7.

I'm unable to reproduce this. The ordering happens properly for me. If you have any additional reproduction info please let me know!

The actual issue is not in depends_on, but rather in the file interpolation function. It reads the file during validation, not during rendering the template. Just for anybody looking here is a related ticket #8406

Just encountered this one too. Heres to recreate:

resource "null_resource" "hello" {
  provisioner "local-exec" {
    command = "bash hello > ${path.module}/hello.txt"
  }
}

data "template_file" "init" {
  depends_on = ["null_resource.hello"]
  template   = "${file("${path.module}/hello.txt")}"
}

The data.template_file will fail as it will say ${path.module}/hello.txt doesn't exist despite the depends_on being stated.

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