Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data source template_file fails with "read /: is a directory" when template attribute interpolation or literal returns a "/" #8660

Closed
martin-cossy-atwork opened this issue Sep 5, 2016 · 5 comments · Fixed by #10297

Comments

@martin-cossy-atwork
Copy link

Cannot see this in the documentation, so here I go.

terraform plan fails with read /: is a directory when the value assigned to the template attribute of the template_file data source equals /.

Terraform Version

Terraform v0.7.2

Affected Resource(s)

  • template_file

Terraform Configuration Files

variable "ping_path_separator" {
  default = {
    HTTP = "/"
    HTTPS = "/"
    TCP = ""
    SSL = ""
  }
}

data "template_file" "ping_path_separator" { template = "${lookup(var.ping_path_separator, "HTTP")}" }

or simply

data "template_file" "broken" { template = "/" }

Expected Behavior

It should not fail an rendered should return /

Actual Behavior

It fails as described :)

Steps to Reproduce

terraform apply

@levenaux
Copy link

levenaux commented Sep 5, 2016

I think you're meant to structure it like this:

variable "ping_path_separator" {
  default = {
    HTTP = "/"
    HTTPS = "/"
    TCP = ""
    SSL = ""
  }
}

data "template_file" "ping_path_separator" {
  template = "${ping_path_separator}"

  vars {
    ping_path_separator = "${lookup(var.ping_path_separator, "HTTP")}"
  }
}

the docs are here and here

@martin-cossy-atwork
Copy link
Author

@jamielennox1 that works indeed. Thanks. Will use that workaround.

But I still fail to understand why this specific case fails.

I normally do interpolations directly in the template argument because according to the docs it is not forbidden to do so and it keep the descriptive code slim.

@levenaux
Copy link

levenaux commented Sep 5, 2016

Filename was deprecated for template. This means we can specify both inline templates and reference template files. / is a directory inside UNIX. So, it's going to assume you're trying to load a file instead of inline.

to prove that this is the case:

variable "ping_path_separator" {
  default = {
    HTTP = "Test /"
    HTTPS = "/"
    TCP = ""
    SSL = ""
  }
}

data "template_file" "ping_path_separator" {
  template = "${lookup(var.ping_path_separator, "HTTP")}"
}

This should pass absolutely fine.

It's still a bug but hopefully, that helps you to understand why it's behaving the way it is.

@martin-cossy-atwork
Copy link
Author

Yeah. Actually I suspected something like that, but then to reproduce the error by using something like this

data "template_file" "broken" { template = "/test/" }

or

data "template_file" "broken" { template = "/test" }

or

data "template_file" "broken" { template = "test/" }

or this

data "template_file" "broken" { template = "/test/file.txt" }

but none of those failed, only this one

data "template_file" "broken" { template = "/" }

that got me wondering and opened the ticket.

Feel free to close the ticket if this behavior is expected. And thanks again for saving the day :)

mitchellh added a commit that referenced this issue Nov 22, 2016
Fixes #8660

This disallows file paths in `template`. This already had a deprecation
warning so we're just removing that.
@mitchellh mitchellh self-assigned this Nov 22, 2016
gusmat pushed a commit to gusmat/terraform that referenced this issue Dec 6, 2016
Fixes hashicorp#8660

This disallows file paths in `template`. This already had a deprecation
warning so we're just removing that.
fatmcgav pushed a commit to fatmcgav/terraform that referenced this issue Feb 27, 2017
Fixes hashicorp#8660

This disallows file paths in `template`. This already had a deprecation
warning so we're just removing that.
@ghost
Copy link

ghost commented Apr 19, 2020

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.

@ghost ghost locked and limited conversation to collaborators Apr 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants