Skip to content

Conversation

@radeksimko
Copy link
Member

@radeksimko radeksimko commented Dec 30, 2025

This updates the http backend's behaviour such that it refreshes state prior to returning the StateMgr. 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 http backend is not actually impacted by the crash reported in #38027

Some backends (azure, gcs, kubernetes) are assumed to be impacted as they implement the exact same behaviour I'm trying to mimic here:

// Grab the value
if err := stateMgr.RefreshState(); err != nil {
return nil, diags.Append(err)
}

// Grab the value
if err := st.RefreshState(); err != nil {
return nil, diags.Append(err)
}

// Grab the value
if err := stateMgr.RefreshState(); err != nil {
return nil, diags.Append(err)
}

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:

// Grab the value
if err := stateMgr.RefreshState(); err != nil {
err = lockUnlock(err)
return nil, diags.Append(err)
}

// Grab the value
if err := stateMgr.RefreshState(); err != nil {
err = lockUnlock(err)
return nil, diags.Append(err)
}

if err := stateMgr.RefreshState(); err != nil {
err = lockUnlock(err)
return nil, diags.Append(err)
}

// Grab the value
if err := stateMgr.RefreshState(); err != nil {
err = lockUnlock(err)
return nil, diags.Append(err)
}

if err := stateMgr.RefreshState(); err != nil {
err = lockUnlock(err)
return nil, diags.Append(err)
}


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.

This aligns the http backend with the implementation of StateMgr in other remote backends, which in turn enables easier testing of higher level logic that relies on certain backend behaviours.
@radeksimko radeksimko requested a review from a team as a code owner December 30, 2025 14:10
@radeksimko radeksimko added backend/http tests Issues with Terraform's own tests (not "terraform test" or other testing functionality) no-changelog-needed Add this to your PR if the change does not require a changelog entry labels Dec 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend/http no-changelog-needed Add this to your PR if the change does not require a changelog entry tests Issues with Terraform's own tests (not "terraform test" or other testing functionality)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant