backend/http: Refresh state earlier (align with other backends) #38033
+140
−32
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.
This updates the
httpbackend's behaviour such that it refreshes state prior to returning theStateMgr. In practice this should not have any impact on the end user, perhaps just that errors will be raised a little bit earlier.This change however enables us to now use that backend to test edge cases and prevent bugs such as #38027
Prior to this patch, the
httpbackend is not actually impacted by the crash reported in #38027Some backends (azure, gcs, kubernetes) are assumed to be impacted as they implement the exact same behaviour I'm trying to mimic here:
terraform/internal/backend/remote-state/azure/backend_state.go
Lines 107 to 110 in 193867f
terraform/internal/backend/remote-state/gcs/backend_state.go
Lines 108 to 111 in 193867f
terraform/internal/backend/remote-state/kubernetes/backend_state.go
Lines 94 to 97 in 193867f
Other backends implement the same logic conditionally (only refresh once a previously not-existing state was auto-created) but the bug likely impacts them in a similar way anyway:
terraform/internal/backend/remote-state/consul/backend_state.go
Lines 120 to 124 in 193867f
terraform/internal/backend/remote-state/cos/backend_state.go
Lines 126 to 130 in 193867f
terraform/internal/backend/remote-state/oci/backend_state.go
Lines 88 to 91 in 193867f
terraform/internal/backend/remote-state/oss/backend_state.go
Lines 162 to 166 in 193867f
terraform/internal/backend/remote-state/s3/backend_state.go
Lines 231 to 234 in 193867f
I'm open to breaking away the last commit and reviewing it alongside #38028 - we cannot really merge this PR on its own without #38028 anyway but having it crash like this in isolation hopefully demonstrates the value.