-
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
fix error when writing file with empty content #26
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind attaching a test case which reproduces this behaviour (i.e. fails without a patch)?
Side note: We have @terraform-providers/enablement alias that can be used when requesting reviews from the whole team 😉
Thanks @radeksimko! Apologies for the premature review request - I'll fix the tests and add a new case for this. |
local/resource_local_file.go
Outdated
d.SetId(hex.EncodeToString(checksum[:])) | ||
filenameChecksum := sha1.Sum([]byte(destination)) | ||
contentChecksum := sha1.Sum([]byte(content)) | ||
d.SetId(hex.EncodeToString(append(filenameChecksum[:], contentChecksum[:]...))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The id isn't really meaningful for this resource type (it gets all of its required information from the other attributes) so if we're going to change it anyway, maybe more straightforward to just set it to some constant value like "-"
to make it clearer that it's not significant, and then we can remove it altogether once a later SDK version removes the requirement for having an id
attribute. (This requirement is now an SDK-only thing; Terraform Core just treats it the same as any other attribute.)
I'm not sure if this is important, but note that anyone that was referencing local_file.example.id
and expecting to get a SHA1 checksum will see this as a breaking change. I think we never documented this as possible, so probably not a big deal, but probably worth mentioning in the changelog once this is merged just in case.
fdefcf1
to
c507fd8
Compare
It turns out the issue in #15 no longer causes a problem for the user as of Terraform 0.12: #15 (comment) Instead, a warning is logged because the plan ends up with a FixI've fixed this issue in c507fd8, and manual tests pass for Terraform 0.11.13 and 0.12 latest. With this patch, no warning is logged, and the contents of the final state file are valid ( TestsI haven't managed to make an acceptance test case that fails before this patch. Since this provider is already using the 0.12 SDK, the code path followed when running However, the code path followed when running In the meantime I've added an acceptance test inhttps://github.com//pull/26/commits/c507fd81316fa8ea99ec9d4498522e3b004c6853 which doesn't currently fail before the patch. I'll update this or at least add a comment after discussion. |
The test framework calls in to Terraform through I wonder if some other detail about the test framework is changing the outcome here. The testing process is implemented in |
A point here, there are scenarios wherein one may want to create a file but not care if its edited in the future. With the current implementation it is not possible to do this even with |
Previously, attempting to write a local file with content of "" would set the resource Id to "", since the Id is based on a SHA1 of the content. This caused the file to be deleted during the apply step. The Id is now set to a constant "-" to make it clear that it is not significant. The ForceNew behaviour for content has been replaced with an Update function for more appropriate semantics.
202d605
to
6a50f78
Compare
Fixes #15
Previously, attempting to write a local file with content of
""
would set the resourceId
to""
, since theId
is based on a SHA1 of the content. This caused the file to be deleted during the apply step.The resource
Id
of an empty file is now the SHA1 of the filename concatenated with the SHA1 of the content, so it will never be""
.