Skip to content

fix: unused config's create_before_destroy on resource change with no refresh#2248

Merged
ollevche merged 8 commits intomainfrom
fix-create-bef-destroy-refresh
Dec 20, 2024
Merged

fix: unused config's create_before_destroy on resource change with no refresh#2248
ollevche merged 8 commits intomainfrom
fix-create-bef-destroy-refresh

Conversation

@ollevche
Copy link
Copy Markdown
Contributor

@ollevche ollevche commented Dec 4, 2024

In this PR I add an additional refresh state write on planning even when refresh=false is used, since this is the place where we synchronize configuration create_before_destroy value with the state itself. As discussed in the issue, we only write to the refreshed state for this specific use case (refresh=false + configuration value present + state value differs).

Note: I didn't alter the logic of create_before_destroy itself, however I suspect there could be a problem for cases when OpenTofu needs to use state's value (inherited) when replacing a resource even if the configuration doesn't force cbd anymore. Not sure if that's a practical problem though.

Also, I removed a few unused params, which I encountered during debugging. This is irrelevant to the PR, however those are pretty small changes.

Resolves #1806

Target Release

1.9.0

Checklist

  • I have read the contribution guide.
  • I have not used an AI coding assistant to create this PR.
  • I have written all code in this PR myself OR I have marked all code I have not written myself (including modified code, e.g. copied from other places and then modified) with a comment indicating where it came from.
  • I (and other contributors to this PR) have not looked at the Terraform source code while implementing this PR.

Go checklist

  • I have run golangci-lint on my change and receive no errors relevant to my code.
  • I have run existing tests to ensure my code doesn't break anything.
  • I have added tests for all relevant use cases of my code, and those tests are passing.
  • I have only exported functions, variables and structs that should be used from other packages.
  • I have added meaningful comments to all exported functions, variables, and structs.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Dec 4, 2024

Reminder for the PR assignee: If this is a user-visible change, please update the changelog as part of the PR.

@ollevche ollevche force-pushed the fix-create-bef-destroy-refresh branch from 1fed782 to dffe0d5 Compare December 16, 2024 13:10
@ollevche ollevche marked this pull request as ready for review December 16, 2024 17:51
@ollevche ollevche requested a review from a team as a code owner December 16, 2024 17:51
… refresh

Signed-off-by: ollevche <ollevche@gmail.com>
Signed-off-by: ollevche <ollevche@gmail.com>
Signed-off-by: ollevche <ollevche@gmail.com>
Signed-off-by: ollevche <ollevche@gmail.com>
Signed-off-by: ollevche <ollevche@gmail.com>
Signed-off-by: ollevche <ollevche@gmail.com>
Signed-off-by: ollevche <ollevche@gmail.com>
Signed-off-by: ollevche <ollevche@gmail.com>
@ollevche ollevche force-pushed the fix-create-bef-destroy-refresh branch from 0eb2dc6 to 0f64413 Compare December 17, 2024 13:17
Copy link
Copy Markdown
Contributor

@apparentlymart apparentlymart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems plausible! 👍

Having another weird special case makes me a little nervous, but it's at least relatively self-contained and I don't really have a better idea for how to do this with how the code is currently structured.

@ollevche ollevche merged commit c5b43b9 into main Dec 20, 2024
@ollevche ollevche deleted the fix-create-bef-destroy-refresh branch December 20, 2024 08:47
ollevche added a commit that referenced this pull request Dec 20, 2024
… refresh (#2248)

Signed-off-by: ollevche <ollevche@gmail.com>
ollevche added a commit that referenced this pull request Dec 20, 2024
…e change with no refresh (#2248) (#2310)

Signed-off-by: ollevche <ollevche@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Changing create_before_destroy and using -refresh=false could keep resources detached from state

2 participants