From ab85a7f992903066d908e284e3adb27ac47f4769 Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Tue, 17 Dec 2024 19:56:06 +0100 Subject: [PATCH] removed app id --- bundle/config/resources/apps.go | 9 ++------- bundle/deploy/terraform/convert.go | 7 ++++--- bundle/deploy/terraform/convert_test.go | 22 +++++++++++----------- bundle/deploy/terraform/util.go | 1 + bundle/deploy/terraform/util_test.go | 2 +- 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/bundle/config/resources/apps.go b/bundle/config/resources/apps.go index 00b7de4dd..ee3c40ad0 100644 --- a/bundle/config/resources/apps.go +++ b/bundle/config/resources/apps.go @@ -12,11 +12,6 @@ import ( ) type App struct { - // This represents the id which is the name of the app that can be used - // as a reference in other resources. This value is returned by terraform. - // This equals to app name and added for symmetry with other resources. - ID string `json:"id,omitempty" bundle:"readonly"` - // SourceCodePath is a required field used by DABs to point to Databricks app source code // on local disk and to the corresponding workspace path during app deployment. SourceCodePath string `json:"source_code_path"` @@ -56,10 +51,10 @@ func (a *App) TerraformResourceName() string { } func (a *App) InitializeURL(baseURL url.URL) { - if a.ID == "" { + if a.Name == "" { return } - baseURL.Path = fmt.Sprintf("apps/%s", a.ID) + baseURL.Path = fmt.Sprintf("apps/%s", a.Name) a.URL = baseURL.String() } diff --git a/bundle/deploy/terraform/convert.go b/bundle/deploy/terraform/convert.go index b47642697..cdae42b3e 100644 --- a/bundle/deploy/terraform/convert.go +++ b/bundle/deploy/terraform/convert.go @@ -9,6 +9,7 @@ import ( "github.com/databricks/cli/bundle/deploy/terraform/tfdyn" "github.com/databricks/cli/bundle/internal/tf/schema" "github.com/databricks/cli/libs/dyn" + "github.com/databricks/databricks-sdk-go/service/apps" tfjson "github.com/hashicorp/terraform-json" ) @@ -202,9 +203,9 @@ func TerraformToBundle(state *resourcesState, config *config.Root) error { } cur := config.Resources.Apps[resource.Name] if cur == nil { - cur = &resources.App{ModifiedStatus: resources.ModifiedStatusDeleted} + cur = &resources.App{ModifiedStatus: resources.ModifiedStatusDeleted, App: &apps.App{}} } - cur.ID = instance.Attributes.ID + cur.Name = instance.Attributes.Name config.Resources.Apps[resource.Name] = cur case "databricks_permissions": case "databricks_grants": @@ -271,7 +272,7 @@ func TerraformToBundle(state *resourcesState, config *config.Root) error { } } for _, src := range config.Resources.Apps { - if src.ModifiedStatus == "" && src.ID == "" { + if src.ModifiedStatus == "" && src.Name == "" { src.ModifiedStatus = resources.ModifiedStatusCreated } } diff --git a/bundle/deploy/terraform/convert_test.go b/bundle/deploy/terraform/convert_test.go index 440eea233..3da364f47 100644 --- a/bundle/deploy/terraform/convert_test.go +++ b/bundle/deploy/terraform/convert_test.go @@ -700,7 +700,7 @@ func TestTerraformToBundleEmptyLocalResources(t *testing.T) { Mode: "managed", Name: "test_app", Instances: []stateResourceInstance{ - {Attributes: stateInstanceAttributes{ID: "1"}}, + {Attributes: stateInstanceAttributes{Name: "app1"}}, }, }, }, @@ -741,7 +741,7 @@ func TestTerraformToBundleEmptyLocalResources(t *testing.T) { assert.Equal(t, "1", config.Resources.Dashboards["test_dashboard"].ID) assert.Equal(t, resources.ModifiedStatusDeleted, config.Resources.Dashboards["test_dashboard"].ModifiedStatus) - assert.Equal(t, "1", config.Resources.Apps["test_app"].ID) + assert.Equal(t, "app1", config.Resources.Apps["test_app"].Name) assert.Equal(t, resources.ModifiedStatusDeleted, config.Resources.Apps["test_app"].ModifiedStatus) AssertFullResourceCoverage(t, &config) @@ -830,7 +830,7 @@ func TestTerraformToBundleEmptyRemoteResources(t *testing.T) { Apps: map[string]*resources.App{ "test_app": { App: &apps.App{ - Name: "test_app", + Description: "test_app", }, }, }, @@ -875,7 +875,7 @@ func TestTerraformToBundleEmptyRemoteResources(t *testing.T) { assert.Equal(t, "", config.Resources.Dashboards["test_dashboard"].ID) assert.Equal(t, resources.ModifiedStatusCreated, config.Resources.Dashboards["test_dashboard"].ModifiedStatus) - assert.Equal(t, "", config.Resources.Apps["test_app"].ID) + assert.Equal(t, "", config.Resources.Apps["test_app"].Name) assert.Equal(t, resources.ModifiedStatusCreated, config.Resources.Apps["test_app"].ModifiedStatus) AssertFullResourceCoverage(t, &config) @@ -1019,12 +1019,12 @@ func TestTerraformToBundleModifiedResources(t *testing.T) { Apps: map[string]*resources.App{ "test_app": { App: &apps.App{ - Name: "test_app", + Description: "test_app", }, }, "test_app_new": { App: &apps.App{ - Name: "test_app_new", + Description: "test_app_new", }, }, }, @@ -1213,7 +1213,7 @@ func TestTerraformToBundleModifiedResources(t *testing.T) { Mode: "managed", Name: "test_app", Instances: []stateResourceInstance{ - {Attributes: stateInstanceAttributes{ID: "1"}}, + {Attributes: stateInstanceAttributes{Name: "app1"}}, }, }, { @@ -1221,7 +1221,7 @@ func TestTerraformToBundleModifiedResources(t *testing.T) { Mode: "managed", Name: "test_app_old", Instances: []stateResourceInstance{ - {Attributes: stateInstanceAttributes{ID: "2"}}, + {Attributes: stateInstanceAttributes{Name: "app2"}}, }, }, }, @@ -1306,11 +1306,11 @@ func TestTerraformToBundleModifiedResources(t *testing.T) { assert.Equal(t, "", config.Resources.Dashboards["test_dashboard_new"].ID) assert.Equal(t, resources.ModifiedStatusCreated, config.Resources.Dashboards["test_dashboard_new"].ModifiedStatus) - assert.Equal(t, "1", config.Resources.Apps["test_app"].ID) + assert.Equal(t, "app1", config.Resources.Apps["test_app"].Name) assert.Equal(t, "", config.Resources.Apps["test_app"].ModifiedStatus) - assert.Equal(t, "2", config.Resources.Apps["test_app_old"].ID) + assert.Equal(t, "app2", config.Resources.Apps["test_app_old"].Name) assert.Equal(t, resources.ModifiedStatusDeleted, config.Resources.Apps["test_app_old"].ModifiedStatus) - assert.Equal(t, "", config.Resources.Apps["test_app_new"].ID) + assert.Equal(t, "", config.Resources.Apps["test_app_new"].Name) assert.Equal(t, resources.ModifiedStatusCreated, config.Resources.Apps["test_app_new"].ModifiedStatus) AssertFullResourceCoverage(t, &config) diff --git a/bundle/deploy/terraform/util.go b/bundle/deploy/terraform/util.go index 4da015c23..e2564ac22 100644 --- a/bundle/deploy/terraform/util.go +++ b/bundle/deploy/terraform/util.go @@ -34,6 +34,7 @@ type stateResourceInstance struct { type stateInstanceAttributes struct { ID string `json:"id"` + Name string `json:"name,omitempty"` ETag string `json:"etag,omitempty"` } diff --git a/bundle/deploy/terraform/util_test.go b/bundle/deploy/terraform/util_test.go index 74b329259..5d1310392 100644 --- a/bundle/deploy/terraform/util_test.go +++ b/bundle/deploy/terraform/util_test.go @@ -97,7 +97,7 @@ func TestParseResourcesStateWithExistingStateFile(t *testing.T) { Type: "databricks_pipeline", Name: "test_pipeline", Instances: []stateResourceInstance{ - {Attributes: stateInstanceAttributes{ID: "123"}}, + {Attributes: stateInstanceAttributes{ID: "123", Name: "test_pipeline"}}, }, }, },