Repository navigation
Conversation
When the content of a file managed by local_file or local_sensitive_file is changed outside of Terraform, Read compares the SHA1 of the file with the id in the state and removes the resource from the state. The plan then shows the resource as deleted and proposes to create it again, so the next apply overwrites the external change. ignore_changes does not help, because the resource is planned for creation. Changes to the file mode are not detected at all. The docs only mention the case where the file is missing. Add a note about the content and permission cases to both resources, in the templates and in the generated pages. Related: hashicorp#262, hashicorp#87 Assisted-by: Claude Opus 5.5 Signed-off-by: YoungjuKim <[email protected]>
|
Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement Learn more about why HashiCorp requires a CLA and what the CLA includes Have you signed the CLA already but the status is still pending? Recheck it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
Relates to #262 and #87 (documentation only, does not fix them)
Description
The
local_fileandlocal_sensitive_filepages have a "Note about resource behaviour" that covers one case: the file is missing, so Terraform reports the resource as deleted and creates it again.The same thing happens when the file still exists but its content was changed outside of Terraform.
Readcompares the SHA1 of the file with theidin the state and callsRemoveResourcewhen they differ (resource_local_file.go, same code inresource_local_sensitive_file.go). As a result:lifecycle { ignore_changes = ... }does not help, because the resource is planned for creation, not for an update. This is the behavior reported in local_file creates / overwrites file if content changes; does not followignorelifecycle. #262, and @SBGoods explained in that issue why the provider keeps it;terraform refreshfor local_file does not detect changes to file permissions #87).People who use
local_filefor files that others may edit (the case in #262) only find this out after their edit is overwritten. This PR adds a second note with these three points to both resources, in the templates and in the generateddocs/pages. The text indocs/is the same as in the templates, somake generateshould give the same result.How I checked it (OpenTofu v1.9.0, provider
hashicorp/localv2.9.1, linux_amd64; the behavior is in the provider'sRead, so it should be the same with Terraform, which I did not run):After
apply:echo edited >> out/plain.txt, thenplan -refresh-onlyNote: Objects have changed outside of OpenTofu/# local_file.plain has been deletedplan# local_file.plain will be created,Plan: 1 to addecho edited >> out/ignored.txt(hasignore_changes = [content]), thenplan# local_file.ignored will be created;applywritesv1backchmod 0600 out/perm.txt, thenplan -detailed-exitcodeNo changes, exit code 0local_sensitive_filewithignore_changes = all, content editedhas been deleted, thenwill be createdNo changelog entry, since this is a documentation change.
This change was drafted with AI assistance and reviewed by me. The AI tool drafted the note and this description; I ran the commands above and checked the result against the provider source.
Rollback Plan
Changes to Security Controls
Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.
No. Documentation only.
🤖 Generated with Claude Code