PSS: Migration from a backend to a state store#38048
Conversation
9ce6880 to
bdd2faa
Compare
4af2b3b to
40f3b3a
Compare
124a22f to
3b7178b
Compare
3fff10b to
f0fbe0f
Compare
SarahFrench
left a comment
There was a problem hiding this comment.
Here are a few minor things from review.
Reading through your PR description:
I noticed that it can be difficult to tell what's actually happening during the migration purely from the UI messages. All that our messages recognise is that migration from X to Y is happening and was successful or not. I think ideally:
- we should print out the workspaces as they are migrated
- we should acknowledge in the UI when the destination already exists. This will be a common codepath for users migrating to state store versions of equivalent backends (e.g. s3 backend -> s3 state store).
Agreed! I think when we've discussed 'quality of life' changes like these in the past it's been in the context of wider improvements as part of a major release, but I guess these could be added in the context of PSS as that's new. However we'd be restricted as migrations use shared code across all types of migration, and we don't want to make breaking changes.
I cannot think of a good reason to do the same for the backend -> state store migration though. If the state is already stored in a backend, at least one successful init and apply must have run by then. If the default workspace is still missing, it may well be intention and so I don't think we should be intervening in any way there.
I mildly disagree in that a user could perform a first init with a backend, change the config to include a state_store and run a second init when they will be forced to choose between reconfigure/migrate. This can happen all while no state files exist, if default is the only workspace and no apply has happened. In that case the migration is pretty much equivalent to the user having the state_store present in config during the first init, which is when the default workspace would be created as things are currently implemented. So, I think the migration making a default workspace is reasonable in that case?
I agree that if the default workspace is missing and other workspaces exist in the backend before migration to a state store then after the migration the default workspace shouldn't be created. But I believe that's current behaviour?
You're right. While (IMO) rare, there is a real scenario we need to account for. I have copied the same logic here but think we should revisit it both here, at the source and maybe related logic in a few other places too. The part I'm specifically unsure about is whether respecting Even if we are fine with the behaviour, this detail is missing from the help text here, where we imply that the default workspace is always created: terraform/internal/command/init.go Lines 1483 to 1488 in ba5c4ac |
|
After discussion in a 1:1:
So for this PR the block handling workspaces can be removed, and in a following PR we'd remove -create-default-workspace etc. |
8e1d04a to
fd6f40d
Compare
- TestInit_backend_to_stateStore_singleWorkspace - TestInit_backend_to_stateStore_multipleWorkspaces - TestInit_cloud_to_stateStore
d323a3d to
c47380c
Compare
| args := []string{ | ||
| "-enable-pluggable-state-storage-experiment=true", | ||
| } |
There was a problem hiding this comment.
nit:
| args := []string{ | |
| "-enable-pluggable-state-storage-experiment=true", | |
| } | |
| args := []string{} |
Notes
Removing data after migration
There are reasons both for and against removing the data that was migrated. If we don't do it, it creates a split-brain situation. If we remove it and the migration somehow failed without us explicitly knowing, we cause dataloss. I'm leaning towards keeping it.
Our different migration paths are being somewhat pragmatic and usually avoid deleting anything remotely but we do remove local files after migrating them to a remote backend because we generally consider locally stored state files as bad practice and a risk. Many (first time) users start without any backend and then introduce it later.
AFAICT we do not remove local files after migrating to a state store, which I think we should:
terraform/internal/command/meta_backend.go
Lines 1920 to 2132 in 8a615f9
However, I think for the migration being implemented here in this PR (backend -> state store) we should keep it as is (i.e. NOT remove).
Multi-workspace migrations and transparency
I noticed that it can be difficult to tell what's actually happening during the migration purely from the UI messages. All that our messages recognise is that migration from X to Y is happening and was successful or not. I think ideally:
Selecting/creating workspace after migration
I noticed in our local -> state store migration codepath we attempt to create the default workspace if it doesn't exist. It makes sense in that context as zero workspaces may often exist if the "migration"
initis the very firstinitever and noapplyran yet.I cannot think of a good reason to do the same for the backend -> state store migration though. If the state is already stored in a backend, at least one successful
initandapplymust have run by then. If the default workspace is still missing, it may well be intention and so I don't think we should be intervening in any way there.Target Release
1.15.x
Rollback Plan
Changes to Security Controls
Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.
CHANGELOG entry