Make sure state blob is created before locking or snapshotting is attempted in azurerm backend #27797
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 fixes #27771
Current implementation attempts to create a new state blob in several different places:
-lock=false
CLI option.GetProperties
and let the new blob to be created, but if you configure your azurerm backend withsnapshot=true
it may try to snapshot a blob that doesn't exist yet.One question I have is how to indicate a condition that should never happen in the
RemoteClient.Lock()
function. Basically if a blob doesn't exist at this point, something went really wrong or someone deleted the blob manually. Right now I just return an emptylockId
and theerr
, but may be there is a better way to handle such conditions?I'd like to make this solution better aligned with other backend implementations, notable S3 and PostgreSQL. Those implementations use
Backend.Workspaces()
function to get a list of existing states and then proceed to create new empty statesif there is no existing one. With azurerm implementation the
Workspaces()
function doesn't seem to return an existing state because of some strangeness in how it constructs a prefix. This function probably needs to be refactored as well, but I think that would be a separate PR since I haven't spent any time understanding the workspaces related code base.