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

user-data forces new resource when you move from windows to linux #8467

Closed
davyt10 opened this issue Aug 25, 2016 · 11 comments
Closed

user-data forces new resource when you move from windows to linux #8467

davyt10 opened this issue Aug 25, 2016 · 11 comments

Comments

@davyt10
Copy link

davyt10 commented Aug 25, 2016

Terraform v0.7.1

user-data forces new resource when you move terraform apply from windows to linux and vice versa

When I launch infrastructure on a windows platform and commit to code commit and a colleague on a linux platform pulls down down latest commit, user_data will want to force a new resource. I have verified this also happens from Linux to windows when the apply is done from the linux OS and latest commit pulled down from to windows.

I have ensured the file line endings are CRLF when running in windows and LF in in Linux as I had seen this mentioned as a potential issue.

This is a hindrance as I have to comment out user-data once an environment is launched to allow users on linux platforms platforms to manage the infrastructure without destroying the entire infrastructure with a terraform apply. This has obvious consequences if I ever want to increase the count of my instances since user-data is then commented out.

Anyone seeing this?

@levenaux
Copy link

My team is having this issue as well. Passing modules with user-data between MacBooks will cause the SHA to change. To stop this, we just add:
lifecycle { ignore_changes = [ "user_data" ] }

@davyt10
Copy link
Author

davyt10 commented Aug 30, 2016

Tested and working, thanks!

@mitchellh
Copy link
Contributor

Are you specifying user data as a direct string or via the file function call?

@mitchellh mitchellh added bug waiting-response An issue/pull request is waiting for a response from the community provider/aws labels Aug 30, 2016
@davyt10
Copy link
Author

davyt10 commented Aug 31, 2016

I am using the file function call.

On Aug 30, 2016, at 22:50, Mitchell Hashimoto notifications@github.com wrote:

Are you specifying user data as a direct string or via the file function call?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

@Dchamard
Copy link

Dchamard commented Sep 2, 2016

Having the same problem here in 7.0.1 using template_file resource in userdata.

@PeteGoo
Copy link
Contributor

PeteGoo commented Nov 14, 2016

Same thing using template_file on 0.7.10. Windows users are getting a forced change to e.g. policies. Probably due to git autocrlf.

@mitchellh mitchellh added core and removed waiting-response An issue/pull request is waiting for a response from the community provider/aws labels Dec 1, 2016
@jgeorgeson
Copy link

Still seeing this in 0.9.2. @PeteGoo I think it's definitely line endings. When I flip the script file's line endings the checksum once again matches the before side of the terraform plan output. But instead of saying nothing to do plan now says it has to deploy everything new. ☹️

@jgeorgeson
Copy link

I was able to recover by running terraform list and then running terraform state refresh -target=... on every resource after fixing the eol on the userdata script. So it wasn't just the eol but that was definitely the instigator.

@apparentlymart apparentlymart added config and removed core labels Nov 7, 2018
@dtelaroli
Copy link

dtelaroli commented Jan 25, 2019

Same problem with terraform 1.11.11
It's not about new line char, because I use LF in both with vscode.

@teamterraform
Copy link
Contributor

Hi all,

Terraform explicitly does not normalize line endings by platform, so you must ensure that nothing else in your workflow is causing line endings to be different by platform. Terraform does not automatically normalize line endings specifically because files loaded in to Terraform are often intended to be submitted to a remote system that may be running a different operating system and thus Terraform cannot predict with certainty which line ending convention would be appropriate.

In particular, it's important to ensure that your version control system is not rewriting line endings when pushing and pulling changes between platforms. For Git, one way to force that is to tell Git to treat the files in question as binary by placing a file called .gitattributes in the root of the repository, with content like the following:

*.tmpl binary
*.sh binary

You can find more details on this in GitHub's guide to line endings in Git.

We're going to close this now because unfortunately Terraform is working as expected here and the problem is with some other system (often Git) making unexpected changes to the files. Terraform itself cannot detect that this has happened or prevent it, so there's unfortunately nothing we can do within Terraform itself to avoid this problem.

Sorry for the long delay in responding. Hopefully the above is helpful to those who have encountered this problem.

@ghost
Copy link

ghost commented Aug 17, 2019

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 Aug 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants