11package deployment
22
33import (
4- "context"
5- "encoding/json"
64 "errors"
75 "fmt"
8- "os"
96
10- "github.com/databricks/cli/bundle"
117 "github.com/databricks/cli/bundle/deploy/terraform"
128 "github.com/databricks/cli/bundle/direct"
139 "github.com/databricks/cli/bundle/direct/dstate"
@@ -19,13 +15,6 @@ import (
1915 "github.com/spf13/cobra"
2016)
2117
22- // terraformState represents the minimal terraform state structure we need
23- type terraformState struct {
24- Version int `json:"version"`
25- Serial int64 `json:"serial"`
26- Lineage string `json:"lineage"`
27- }
28-
2918func newMigrateCommand () * cobra.Command {
3019 cmd := & cobra.Command {
3120 Use : "migrate" ,
@@ -177,37 +166,13 @@ proper state management as it may cause resource conflicts.`,
177166 Path : localDirectPath ,
178167 Data : directDB ,
179168 }
180- deploymentState .Finalize ()
169+ err = deploymentState .Finalize ()
170+ if err != nil {
171+ return err
172+ }
181173 cmdio .LogString (ctx , fmt .Sprintf ("Migrated %d resources to direct engine state file: %s" , len (directDB .State ), localDirectPath ))
182174 return nil
183175 }
184176
185177 return cmd
186178}
187-
188- func readTerraformState (ctx context.Context , b * bundle.Bundle ) (terraform.ExportedResourcesMap , * terraformState , error ) {
189- // Read terraform state file to get resources
190- terraformResources , err := terraform .ParseResourcesState (ctx , b )
191- if err != nil {
192- return nil , nil , fmt .Errorf ("failed to parse terraform state: %w" , err )
193- }
194-
195- // Read raw terraform state file to get lineage and serial
196- _ , localTerraformPath := b .StateFilenameTerraform (ctx )
197- stateData , err := os .ReadFile (localTerraformPath )
198- if err != nil {
199- return nil , nil , fmt .Errorf ("failed to read terraform state file: %w" , err )
200- }
201-
202- var tfState terraformState
203- err = json .Unmarshal (stateData , & tfState )
204- if err != nil {
205- return nil , nil , fmt .Errorf ("failed to parse terraform state file: %w" , err )
206- }
207-
208- if tfState .Lineage == "" {
209- return nil , nil , fmt .Errorf ("terraform state file missing lineage" )
210- }
211-
212- return terraformResources , & tfState , nil
213- }
0 commit comments