Skip to content

Commit a91c8bc

Browse files
committed
WIP
1 parent 41cb7e8 commit a91c8bc

7 files changed

Lines changed: 94 additions & 1 deletion

File tree

internal/command/state_migrate.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,67 @@ func (c *StateMigrateCommand) Run(rawArgs []string) int {
112112
return 1
113113
}
114114

115+
// func (c *StateMigrateCommand) srcBackendFromStateMigrationInstructions(root *configs.Module, locks *depsfile.Locks, viewType arguments.ViewType) (backendrun.OperationsBackend, tfdiags.Diagnostics) {
116+
// var diags tfdiags.Diagnostics
117+
118+
// sm := root.StateMigrationInstructions
119+
120+
// var opts *BackendOpts
121+
// switch {
122+
// case sm.Backend != nil:
123+
// opts = &BackendOpts{
124+
// BackendConfig: sm.Backend,
125+
// Locks: locks,
126+
// ViewType: viewType,
127+
// }
128+
// case sm.StateStore != nil:
129+
// // Annotate state_store config representation with info about how the provider
130+
// // is supplied to Terraform.
131+
// isReattached, err := reattach.IsProviderReattached(sm.StateStore.ProviderAddr, os.Getenv("TF_REATTACH_PROVIDERS"))
132+
// if err != nil {
133+
// panic(fmt.Sprintf("Unable to determine if provider %s is reattached while initializing the state store. This is a bug in Terraform and should be reported: %v", sm.StateStore.ProviderAddr.ForDisplay(), err))
134+
// }
135+
// sm.StateStore.ProviderSupplyMode = getproviders.DetermineProviderSupplyMode(c.Meta.isProviderDevOverride(sm.StateStore.ProviderAddr), isReattached, sm.StateStore.ProviderAddr.IsBuiltIn())
136+
137+
// // Check the provider for state storage is present, either via the dependency lock file or
138+
// // supplied via developer overrides, reattach config, or being built-in.
139+
// //
140+
// // Remember, the (Meta).backend method is used for non-init commands, so we expect dependency locks
141+
// // to be present or for the provider to be otherwise available, e.g. via reattach config.
142+
// depsDiags := sm.StateStore.VerifyDependencySelection(locks, root.ProviderRequirements, sm.StateStore.ProviderSupplyMode)
143+
// diags = diags.Append(depsDiags)
144+
// if depsDiags.HasErrors() {
145+
// return nil, diags
146+
// }
147+
148+
// opts = &BackendOpts{
149+
// StateStoreConfig: sm.StateStore,
150+
// Locks: locks,
151+
// ViewType: viewType,
152+
// }
153+
// default:
154+
// diags = diags.Append(tfdiags.Sourceless(
155+
// tfdiags.Error,
156+
// "Missing state migration configuration",
157+
// "One of 'backend' or 'state_store' blocks must be present in the state migration instructions.",
158+
// ))
159+
// return nil, diags
160+
// }
161+
162+
// // This method should not be used for init commands,
163+
// // so we always set this value as false.
164+
// opts.Init = false
165+
166+
// // Load the backend
167+
// be, beDiags := c.Meta.Backend(opts)
168+
// diags = diags.Append(beDiags)
169+
// if beDiags.HasErrors() {
170+
// return nil, diags
171+
// }
172+
173+
// return be, diags
174+
// }
175+
115176
func (c *StateMigrateCommand) Help() string {
116177
helpText := `
117178
Usage: terraform [global options] state migrate [options]

internal/command/state_migrate_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/hashicorp/cli"
1313
)
1414

15-
func TestStateMigrate_basic(t *testing.T) {
15+
func TestStateMigrate_fromBackendToBackend(t *testing.T) {
1616
ui := cli.NewMockUi()
1717
view, done := testView(t)
1818
c := &StateMigrateCommand{
@@ -48,6 +48,18 @@ func TestStateMigrate_basic(t *testing.T) {
4848
}
4949
}
5050

51+
func TestStateMigrate_fromBackendToStateStore(t *testing.T) {
52+
t.Fatal("TODO")
53+
}
54+
55+
func TestStateMigrate_fromStateStoreToStateStore(t *testing.T) {
56+
t.Fatal("TODO")
57+
}
58+
59+
func TestStateMigrate_fromStateStoreToBackend(t *testing.T) {
60+
t.Fatal("TODO")
61+
}
62+
5163
func TestStateMigrate_nonExistentLockFiles(t *testing.T) {
5264
ui := cli.NewMockUi()
5365
view, done := testView(t)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from {
2+
backend {
3+
type = "local"
4+
config {
5+
path = "terraform.tfstate"
6+
}
7+
}
8+
}

internal/command/testdata/state-store-to-backend/.terraform.lock.hcl renamed to internal/command/testdata/state-migrate-state-store-to-backend/.terraform.lock.hcl

File renamed without changes.

internal/command/testdata/state-store-to-backend/.terraform/terraform.tfstate renamed to internal/command/testdata/state-migrate-state-store-to-backend/.terraform/terraform.tfstate

File renamed without changes.

internal/command/testdata/state-store-to-backend/main.tf renamed to internal/command/testdata/state-migrate-state-store-to-backend/main.tf

File renamed without changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
state_store_required_provider {
2+
test = {
3+
source = "hashicorp/test"
4+
version = "1.2.3"
5+
}
6+
}
7+
8+
from {
9+
state_store "test_store" {
10+
path = "terraform.tfstate"
11+
}
12+
}

0 commit comments

Comments
 (0)