-
Notifications
You must be signed in to change notification settings - Fork 66
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
local_file creates / overwrites file if content changes; does not follow ignore
lifecycle.
#262
Comments
ignore
lifecycle.
Updated title cause it was quite awful... sorry bout that. |
This resource type has an interesting rule in its "read" implementation where it checks if the file contents have changed and pretends that the file has been deleted if so: terraform-provider-local/internal/provider/resource_local_file.go Lines 255 to 272 in f55a842
I have a faint memory that this was working around some quirk of a very old version of Terraform that was current when originally writing this provider, but I don't think this approach should be needed anymore. With more modern Terraform we could take the following approach instead:
Terraform Core should then notice that the attributes in the plan have different values than the corresponding attributes in the desired state (updated by the read step) and so propose to update the file in-place. I don't think it's necessary to delete the file first, but if we identify a reason why we need to do that then the existing plan modifier that marks changes to the content attribute as requiring replacement could be preserved and would then cause Terraform to report that it's going to replace the file rather than updating it in-place. |
Terraform CLI and Provider Versions
Terraform v1.6.2
on darwin_amd64
Terraform Configuration
Expected Behavior
When the file is not in state, it correctly creates the file. If I change the content in
test.txt
, because ofignore_changes
, it should not update the contents of the file.Actual Behavior
If I change the content of
test.txt
after it's been created, it will simply overwrite the file doing acreate
. This ignores the lifecycle rule.Steps to Reproduce
terraform apply
terraform plan
How much impact is this issue causing?
High
Logs
https://gist.github.com/craigmonson/1a54c16e50e85e2fe78cafb20891dadf
Additional Information
The context: I've created a boilerplate module that can generate files for me. A prime example of this would be outputting a
README.md
file that's got a simple:# project name
at the top. Once I've created the file the first time, I should be able to go in and fill in the readme, without it being overwritten by using ignore_changes.Code of Conduct
The text was updated successfully, but these errors were encountered: