removed app id

This commit is contained in:
Andrew Nester 2024-12-17 19:56:06 +01:00
parent e8cae54be9
commit ab85a7f992
No known key found for this signature in database
GPG Key ID: 12BC628A44B7DA57
5 changed files with 19 additions and 22 deletions

View File

@ -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()
}

View File

@ -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
}
}

View File

@ -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)

View File

@ -34,6 +34,7 @@ type stateResourceInstance struct {
type stateInstanceAttributes struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
ETag string `json:"etag,omitempty"`
}

View File

@ -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"}},
},
},
},