Skip to content
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 bug for force push for backends besides the remote backend #26190

Merged
merged 1 commit into from
Sep 10, 2020

Conversation

pselle
Copy link
Contributor

@pselle pselle commented Sep 9, 2020

In refactoring the state push -force code when implementing force push for the Terraform remote backend, a bug was introduced that meant that backends that don't implement the EnableForcePush method would still have their state validated, despite having -force set.

This commit fixes that, and adds test coverage such that there is a separate mockRemoteClient that has this method implemented. I had trouble thinking of a way to simplify the tests that doesn't make it needlessly complicated. The tests fail without the change in state.go.

Closes #25761

I nominate this change to go to v0.13 as well, as it is a bug fix for existing versions worthy of cherry-picking.

states/remote/remote_test.go Outdated Show resolved Hide resolved
@@ -302,6 +302,168 @@ func TestWriteStateForMigration(t *testing.T) {
},
}

testCases := []migrationTestCase{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The diff implies this is the new section, however, it is the previous set of test cases with the EnableForcePush-specific code removed. The test TestWriteStateForMigrationWithForcePushClient is the new test.

@codecov
Copy link

codecov bot commented Sep 9, 2020

Codecov Report

Merging #26190 into master will increase coverage by 0.09%.
The diff coverage is 75.58%.

Impacted Files Coverage Δ
backend/local/backend_local.go 41.23% <ø> (ø)
internal/getproviders/types.go 37.90% <0.00%> (-0.94%) ⬇️
terraform/eval_provider.go 83.33% <50.00%> (-4.17%) ⬇️
internal/depsfile/locks.go 67.74% <67.74%> (ø)
internal/depsfile/locks_file.go 75.39% <75.39%> (ø)
terraform/node_data_refresh.go 87.14% <78.94%> (-7.69%) ⬇️
terraform/node_output.go 68.24% <79.66%> (+2.22%) ⬆️
states/remote/state.go 67.30% <100.00%> (ø)
terraform/node_data_destroy.go 100.00% <100.00%> (ø)
terraform/node_resource_refresh.go 89.07% <100.00%> (+0.12%) ⬆️
... and 5 more

@pselle pselle requested a review from a team September 9, 2020 19:41
Copy link
Contributor

@alisdair alisdair left a comment

Choose a reason for hiding this comment

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

👏 Good catch in the force logic, that was subtle! Thanks for making the test changes easy to follow.

Edit: I agree with cherry-picking to 0.13, too.

states/remote/remote_test.go Show resolved Hide resolved
states/remote/state_test.go Outdated Show resolved Hide resolved
In refactoring the force push code when implementing force push
for the Terraform remote backend, a bug was introduced that
meant that backends that don't implement the EnableForcePush
method would still have their state validated. This commit
fixes that, and adds test coverage such that there is a separate
mockRemoteClient that has this method implemented.
@ghost
Copy link

ghost commented Oct 13, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators Oct 13, 2020
@pselle pselle deleted the pselle/force-push-fix branch October 19, 2020 21:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Terraform remote state push -force fails lineage check for S3 backend
3 participants