Open RLRabinowitz opened 4 months ago
Hi @RLRabinowitz, I've found a solution for this. Please can I be assigned to the issue?
Thank you for volunteering @eduzgun , I've assigned you. Please read the "I've been assigned an issue, now what?" section of the contribution guide before you begin working.
Thank you for volunteering @eduzgun , I've assigned you. Please read the "I've been assigned an issue, now what?" section of the contribution guide before you begin working.
Thank you. I will most likely complete it within 4 days.
I want to caution that the local_file
resource type in the hashicorp/local
provider has some slightly quirky behaviors that can make things more confusing when testing OpenTofu Core behaviors. I don't think any of this is actually a cause of the behavior this issue is describing, but I'm mentioning it in case someone encounters these while trying to test:
The ReadResource
behavior (which is what's disabled by -refresh=false
) checks both that the file tracked in filename
in the state is still present on disk and that the current content of the file has the same checksum that was captured in the id
attribute.
If the content doesn't match the checksum then the resource type behaves as if the file isn't present at all, rather than updating the state to match the new content, and so this causes OpenTofu to behave as if the file wasn't present and propose to create it. During apply the "create" overwrites the original file and so the end result still converges, but the plan is misleading.
This resource type has no implementation of update-in-place, so it treats all configuration changes as forcing replacement.
Since there can only be one file on disk for any given filename, this resource type isn't really create_before_destroy
compatible unless you make sure to always change the filename whenever you change anything else.
If you try to use create_before_destroy
without changing the filename then OpenTofu Core will first ask the provider to "create" the file -- which in practice really overwrites it -- and then will ask the provider to "delete" the file, which deletes the file that was just written and thus leaves you with no file at all.
As I say, I don't think anything I wrote above is actually the cause of this issue -- instead, it seems to be the fact that -refresh=false
prevents OpenTofu Core from updating the create_before_destroy
flag in the state before creating the plan -- but all of the above can potentially be confusing when trying to verify a fix using local_file
as the testing vehicle, because it behaves slightly oddly compared to "normal" resource types that work with network APIs instead of with the filesystem.
OpenTofu Version
OpenTofu Configuration Files
Configuration during the first
apply
Configuration during that second command
tofu apply -refresh=false
Debug Output
.
Expected Behavior
Apply should remove the file and create a new one
Actual Behavior
The plan actually claims it would destroy and recreate the file:
However, the actual apply only creates the file:
Steps to Reproduce
tofu init
tofu apply
tofu apply -refresh=false
Additional Context
No response
References