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

template_file rendered differently on different platforms? #17005

Closed
borgilb opened this issue Dec 29, 2017 · 2 comments
Closed

template_file rendered differently on different platforms? #17005

borgilb opened this issue Dec 29, 2017 · 2 comments

Comments

@borgilb
Copy link

borgilb commented Dec 29, 2017

Terraform Version

Terraform v0.11.1
+ provider.google v1.4.0

Terraform Configuration Files

data "template_file" "startup_script" {
  template = "${file("templates/startup_script.txt.tpl")}"
  vars {
    instance_name = "blahblah"
  }
}

resource "google_compute_instance" "instance01" {
  ...
  metadata_startup_script = "${data.template_file.startup_script.rendered}"
}

Template file

echo ${instance_name } > /tmp/one.txt
echo ${instance_name } > /tmp/two.txt

Debug Output

metadata_startup_script: "" => "echo blahblah > /tmp/one.txt\r\necho blahblah > /tmp/two.txt\r\n"

Expected Behavior

Unix style file encoding? I found that for some reason, whenever I rendered my startup-script from a template GCE would not execute it. Not rendering it from a template and just passing in text did work. When I looked at the startup-script value for the GCE instance in the GCP console though it looked identical when doing it either way. I suspect its using windows style file encoding and GCE doesn't like that. I haven't confirmed this, but I bet if I ran terraform apply from a linux or mac it would work.

Actual Behavior

GCE isn't running my startup-script and I'm certain it has to do with the file encoding. Is there a way to set the file encoding?

Steps to Reproduce

Pass metadata_startup_script a multi-line template on a windows box

@borgilb
Copy link
Author

borgilb commented Dec 29, 2017

changing the file to have unix line endings works.

@borgilb borgilb closed this as completed Dec 29, 2017
@ghost
Copy link

ghost commented Apr 5, 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 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant