Skip to content

Commit eda0400

Browse files
authored
summary/run/open: pull App and SecretScope's name into ID field, not Name (#3122)
## Changes When doing Terraform.Load (bundle summary/run/open), do not override app.name and secret_scope.name fields that come from the config with the one stored in Terraform state. Instead store state value in the "id" field. ## Why Conceptually, we separate configuration field (Name) and stored state field (ID, which is Name from last deployment). This means as a user I can see both. Today, configuration's Name is lost in "bundle summary". However, in "bundle validate" Name would be equal to the one from the config, which is confusing -- potentially they could be different. Internally, this makes TerraformToBundle simpler - it only updates ID field and ModifiedStatus (both are always computed and don't come from the user). This means configuration is preserved and also we can make TerraformToBundle generic so that it does not need to have per-resource code (which becomes 2x when we add direct deployment method support). ## Tests Existing tests.
1 parent 0113ee1 commit eda0400

5 files changed

Lines changed: 22 additions & 5 deletions

File tree

acceptance/bundle/deploy/secret-scope/output.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Deployment complete!
88
>>> [CLI] bundle summary --output json
99
{
1010
"backend_type": "DATABRICKS",
11+
"id": "my-secrets-[UUID]",
1112
"modified_status": "created",
1213
"name": "my-secrets-[UUID]",
1314
"permissions": [

bundle/config/resources/apps.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ type AppPermission struct {
2323
}
2424

2525
type App struct {
26+
// This is app's name pulled from the state. Usually the same as Name but may be different if Name in the config
27+
// was changed but the app was not re-deployed yet.
28+
ID string `json:"id,omitempty" bundle:"readonly"`
29+
2630
// SourceCodePath is a required field used by DABs to point to Databricks app source code
2731
// on local disk and to the corresponding workspace path during app deployment.
2832
SourceCodePath string `json:"source_code_path"`
@@ -70,11 +74,15 @@ func (a *App) InitializeURL(baseURL url.URL) {
7074
if a.ModifiedStatus == "" || a.ModifiedStatus == ModifiedStatusCreated {
7175
return
7276
}
73-
baseURL.Path = "apps/" + a.Name
77+
baseURL.Path = "apps/" + a.GetName()
7478
a.URL = baseURL.String()
7579
}
7680

7781
func (a *App) GetName() string {
82+
// Prefer name from the state - that is what is actually deployed
83+
if a.ID != "" {
84+
return a.ID
85+
}
7886
return a.Name
7987
}
8088

bundle/config/resources/secret_scope.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ type SecretScopePermission struct {
2323
}
2424

2525
type SecretScope struct {
26+
// ID is Name that is stored in resources state, usually the same as Name unless re-deployment is pending.
27+
ID string `json:"id,omitempty" bundle:"readonly"`
28+
2629
// A unique name to identify the secret scope.
2730
Name string `json:"name"`
2831

@@ -82,6 +85,9 @@ func (s SecretScope) ResourceDescription() ResourceDescription {
8285
}
8386

8487
func (s SecretScope) GetName() string {
88+
if s.ID != "" {
89+
return s.ID
90+
}
8591
return s.Name
8692
}
8793

bundle/deploy/terraform/convert.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func TerraformToBundle(state *resourcesState, config *config.Root) error {
208208
// because we don't really know if the app source code was updated or not.
209209
cur.ModifiedStatus = resources.ModifiedStatusUpdated
210210
}
211-
cur.Name = instance.Attributes.Name
211+
cur.ID = instance.Attributes.Name
212212
config.Resources.Apps[resource.Name] = cur
213213
case "databricks_secret_scope":
214214
if config.Resources.SecretScopes == nil {
@@ -218,7 +218,7 @@ func TerraformToBundle(state *resourcesState, config *config.Root) error {
218218
if cur == nil {
219219
cur = &resources.SecretScope{ModifiedStatus: resources.ModifiedStatusDeleted}
220220
}
221-
cur.Name = instance.Attributes.Name
221+
cur.ID = instance.Attributes.Name
222222
config.Resources.SecretScopes[resource.Name] = cur
223223
case "databricks_permissions":
224224
case "databricks_grants":

bundle/deploy/terraform/convert_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,8 @@ func TestTerraformToBundleEmptyLocalResources(t *testing.T) {
749749
assert.Equal(t, "1", config.Resources.Dashboards["test_dashboard"].ID)
750750
assert.Equal(t, resources.ModifiedStatusDeleted, config.Resources.Dashboards["test_dashboard"].ModifiedStatus)
751751

752-
assert.Equal(t, "app1", config.Resources.Apps["test_app"].Name)
752+
assert.Equal(t, "app1", config.Resources.Apps["test_app"].ID)
753+
assert.Equal(t, "", config.Resources.Apps["test_app"].Name)
753754
assert.Equal(t, resources.ModifiedStatusDeleted, config.Resources.Apps["test_app"].ModifiedStatus)
754755

755756
AssertFullResourceCoverage(t, &config)
@@ -1335,7 +1336,8 @@ func TestTerraformToBundleModifiedResources(t *testing.T) {
13351336

13361337
assert.Equal(t, "test_app", config.Resources.Apps["test_app"].Name)
13371338
assert.Equal(t, resources.ModifiedStatusUpdated, config.Resources.Apps["test_app"].ModifiedStatus)
1338-
assert.Equal(t, "test_app_old", config.Resources.Apps["test_app_old"].Name)
1339+
assert.Equal(t, "test_app_old", config.Resources.Apps["test_app_old"].ID)
1340+
assert.Equal(t, "", config.Resources.Apps["test_app_old"].Name)
13391341
assert.Equal(t, resources.ModifiedStatusDeleted, config.Resources.Apps["test_app_old"].ModifiedStatus)
13401342
assert.Equal(t, "test_app_new", config.Resources.Apps["test_app_new"].Name)
13411343
assert.Equal(t, resources.ModifiedStatusCreated, config.Resources.Apps["test_app_new"].ModifiedStatus)

0 commit comments

Comments
 (0)