Skip to content

Commit 404192e

Browse files
committed
fixes
1 parent 71d8981 commit 404192e

24 files changed

+162
-403
lines changed

acceptance/bundle/lifecycle/prevent-destroy/out.direct-exp.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11

2+
>>> errcode [CLI] bundle plan
3+
24
>>> musterr [CLI] bundle destroy --auto-approve
3-
Error: resource my_pipelines has lifecycle.prevent_destroy set, but the plan calls for this resource to be recreated or destroyed. To avoid this error, disable lifecycle.prevent_destroy
5+
Error: resource my_pipelines has lifecycle.prevent_destroy set, but the plan calls for this resource to be recreated or destroyed. To avoid this error, disable lifecycle.prevent_destroy for pipelines.my_pipelines
46

57

68
Exit code (musterr): 1
79

10+
>>> errcode [CLI] bundle plan
11+
recreate pipelines.my_pipelines
12+
813
>>> musterr [CLI] bundle deploy
914
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/prevent-destroy/default/files...
10-
Error: resource my_pipelines has lifecycle.prevent_destroy set, but the plan calls for this resource to be recreated or destroyed. To avoid this error, disable lifecycle.prevent_destroy
15+
Error: resource my_pipelines has lifecycle.prevent_destroy set, but the plan calls for this resource to be recreated or destroyed. To avoid this error, disable lifecycle.prevent_destroy for pipelines.my_pipelines
1116

1217

1318
Exit code (musterr): 1
1419

20+
>>> errcode [CLI] bundle plan
21+
recreate pipelines.my_pipelines
22+
1523
>>> [CLI] bundle deploy --auto-approve
1624
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/prevent-destroy/default/files...
1725

@@ -24,6 +32,9 @@ Deploying resources...
2432
Updating deployment state...
2533
Deployment complete!
2634

35+
>>> errcode [CLI] bundle plan
36+
delete pipelines.my_pipelines
37+
2738
>>> [CLI] bundle deploy --auto-approve
2839
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/prevent-destroy/default/files...
2940

acceptance/bundle/lifecycle/prevent-destroy/out.terraform.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
>>> errcode [CLI] bundle plan
3+
24
>>> musterr [CLI] bundle destroy --auto-approve
35
Error: exit status 1
46

@@ -16,6 +18,23 @@ the scope of the plan using the -target flag.
1618

1719
Exit code (musterr): 1
1820

21+
>>> errcode [CLI] bundle plan
22+
Error: exit status 1
23+
24+
Error: Instance cannot be destroyed
25+
26+
on bundle.tf.json line 15, in resource.databricks_pipeline:
27+
15: "my_pipelines": {
28+
29+
Resource databricks_pipeline.my_pipelines has lifecycle.prevent_destroy set,
30+
but the plan calls for this resource to be destroyed. To avoid this error and
31+
continue with the plan, either disable lifecycle.prevent_destroy or reduce
32+
the scope of the plan using the -target flag.
33+
34+
35+
36+
Exit code: 1
37+
1938
>>> musterr [CLI] bundle deploy
2039
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/prevent-destroy/default/files...
2140
Error: exit status 1
@@ -34,6 +53,9 @@ the scope of the plan using the -target flag.
3453

3554
Exit code (musterr): 1
3655

56+
>>> errcode [CLI] bundle plan
57+
recreate pipelines.my_pipelines
58+
3759
>>> [CLI] bundle deploy --auto-approve
3860
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/prevent-destroy/default/files...
3961

@@ -46,6 +68,9 @@ Deploying resources...
4668
Updating deployment state...
4769
Deployment complete!
4870

71+
>>> errcode [CLI] bundle plan
72+
delete pipelines.my_pipelines
73+
4974
>>> [CLI] bundle deploy --auto-approve
5075
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/prevent-destroy/default/files...
5176

acceptance/bundle/lifecycle/prevent-destroy/script

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@ trace $CLI bundle validate
22

33
trace $CLI bundle deploy
44

5-
trace musterr $CLI bundle destroy --auto-approve >out.$DATABRICKS_CLI_DEPLOYMENT.txt 2>&1
5+
trace errcode $CLI bundle plan >out.$DATABRICKS_CLI_DEPLOYMENT.txt 2>&1
6+
trace musterr $CLI bundle destroy --auto-approve >>out.$DATABRICKS_CLI_DEPLOYMENT.txt 2>&1
67

78
# Changing the catalog name, deploy must fail because pipeline will be recreated
89
update_file.py databricks.yml 'catalog: main' 'catalog: mainnew'
10+
trace errcode $CLI bundle plan >>out.$DATABRICKS_CLI_DEPLOYMENT.txt 2>&1
911
trace musterr $CLI bundle deploy >>out.$DATABRICKS_CLI_DEPLOYMENT.txt 2>&1
1012

1113
# Removing the prevent_destroy, deploy must succeed
1214
update_file.py databricks.yml 'prevent_destroy: true' 'prevent_destroy: false'
15+
trace errcode $CLI bundle plan >>out.$DATABRICKS_CLI_DEPLOYMENT.txt 2>&1
1316
trace $CLI bundle deploy --auto-approve >>out.$DATABRICKS_CLI_DEPLOYMENT.txt 2>&1
1417

1518
update_file.py databricks.yml 'prevent_destroy: false' 'prevent_destroy: true'
1619
# Removing the job, deploy must succeed
1720
update_file.py databricks.yml '<<: *pipeline_base' ''
21+
trace errcode $CLI bundle plan >>out.$DATABRICKS_CLI_DEPLOYMENT.txt 2>&1
1822
trace $CLI bundle deploy --auto-approve >>out.$DATABRICKS_CLI_DEPLOYMENT.txt 2>&1

bundle/config/resources/database_catalog.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type DatabaseCatalog struct {
1616
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`
1717

1818
database.DatabaseCatalog
19+
Lifecycle Lifecycle `json:"lifecycle,omitempty"`
1920
}
2021

2122
func (d *DatabaseCatalog) Exists(ctx context.Context, w *databricks.WorkspaceClient, name string) (bool, error) {

bundle/config/resources/synced_database_table.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type SyncedDatabaseTable struct {
1616
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`
1717

1818
database.SyncedDatabaseTable
19+
Lifecycle Lifecycle `json:"lifecycle,omitempty"`
1920
}
2021

2122
func (s *SyncedDatabaseTable) Exists(ctx context.Context, w *databricks.WorkspaceClient, name string) (bool, error) {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package terraform
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"testing"
7+
8+
"github.com/databricks/cli/bundle/config"
9+
"github.com/databricks/cli/libs/dyn"
10+
"github.com/stretchr/testify/require"
11+
)
12+
13+
func TestConvertLifecycleForAllResources(t *testing.T) {
14+
supportedResources := config.SupportedResources()
15+
ctx := context.Background()
16+
17+
for resourceType := range supportedResources {
18+
t.Run(resourceType, func(t *testing.T) {
19+
vin := dyn.NewValue(map[string]dyn.Value{
20+
"resources": dyn.NewValue(map[string]dyn.Value{
21+
resourceType: dyn.NewValue(map[string]dyn.Value{
22+
"test_resource": dyn.NewValue(map[string]dyn.Value{
23+
"lifecycle": dyn.NewValue(map[string]dyn.Value{
24+
"prevent_destroy": dyn.NewValue(true, nil),
25+
}, nil),
26+
}, nil),
27+
}, nil),
28+
}, nil),
29+
}, nil)
30+
31+
tfroot, err := BundleToTerraformWithDynValue(ctx, vin)
32+
require.NoError(t, err)
33+
34+
bytes, err := json.Marshal(tfroot.Resource)
35+
require.NoError(t, err)
36+
require.Contains(t, string(bytes), `"lifecycle":{"prevent_destroy":true}`)
37+
})
38+
}
39+
}

bundle/deploy/terraform/tfdyn/convert_app_test.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -156,36 +156,3 @@ func TestConvertAppWithNoDescription(t *testing.T) {
156156
},
157157
}, app)
158158
}
159-
160-
func TestConvertAppWithLifecycle(t *testing.T) {
161-
src := resources.App{
162-
SourceCodePath: "./app",
163-
Config: map[string]any{
164-
"command": []string{"python", "app.py"},
165-
},
166-
App: apps.App{
167-
Name: "app_id",
168-
},
169-
Lifecycle: resources.Lifecycle{
170-
PreventDestroy: true,
171-
},
172-
}
173-
174-
vin, err := convert.FromTyped(src, dyn.NilValue)
175-
require.NoError(t, err)
176-
177-
ctx := context.Background()
178-
out := schema.NewResources()
179-
err = appConverter{}.Convert(ctx, "my_app", vin, out)
180-
require.NoError(t, err)
181-
182-
// Assert equality on the app
183-
assert.Equal(t, map[string]any{
184-
"name": "app_id",
185-
"description": "",
186-
"no_compute": true,
187-
"lifecycle": map[string]any{
188-
"prevent_destroy": true,
189-
},
190-
}, out.App["my_app"])
191-
}

bundle/deploy/terraform/tfdyn/convert_cluster_test.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -94,35 +94,3 @@ func TestConvertCluster(t *testing.T) {
9494
},
9595
}, out.Permissions["cluster_my_cluster"])
9696
}
97-
98-
func TestConvertClusterWithLifecycle(t *testing.T) {
99-
src := resources.Cluster{
100-
ClusterSpec: compute.ClusterSpec{
101-
NumWorkers: 3,
102-
SparkVersion: "13.3.x-scala2.12",
103-
ClusterName: "cluster",
104-
},
105-
Lifecycle: resources.Lifecycle{
106-
PreventDestroy: true,
107-
},
108-
}
109-
110-
vin, err := convert.FromTyped(src, dyn.NilValue)
111-
require.NoError(t, err)
112-
113-
ctx := context.Background()
114-
out := schema.NewResources()
115-
err = clusterConverter{}.Convert(ctx, "my_cluster", vin, out)
116-
require.NoError(t, err)
117-
118-
// Assert equality on the cluster
119-
assert.Equal(t, map[string]any{
120-
"num_workers": int64(3),
121-
"spark_version": "13.3.x-scala2.12",
122-
"cluster_name": "cluster",
123-
"no_wait": true,
124-
"lifecycle": map[string]any{
125-
"prevent_destroy": true,
126-
},
127-
}, out.Cluster["my_cluster"])
128-
}

bundle/deploy/terraform/tfdyn/convert_dashboard_test.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -112,34 +112,3 @@ func TestConvertDashboardSerializedDashboardAny(t *testing.T) {
112112
// Assert that the "file_path" is dropped.
113113
assert.NotContains(t, out.Dashboard["my_dashboard"], "file_path")
114114
}
115-
116-
func TestConvertDashboardWithLifecycle(t *testing.T) {
117-
src := resources.Dashboard{
118-
DashboardConfig: resources.DashboardConfig{
119-
Dashboard: dashboards.Dashboard{
120-
DisplayName: "my dashboard",
121-
WarehouseId: "f00dcafe",
122-
},
123-
},
124-
Lifecycle: resources.Lifecycle{
125-
PreventDestroy: true,
126-
},
127-
}
128-
129-
vin, err := convert.FromTyped(src, dyn.NilValue)
130-
require.NoError(t, err)
131-
132-
ctx := context.Background()
133-
out := schema.NewResources()
134-
err = dashboardConverter{}.Convert(ctx, "my_dashboard", vin, out)
135-
require.NoError(t, err)
136-
137-
// Assert equality on the dashboard
138-
assert.Equal(t, map[string]any{
139-
"display_name": "my dashboard",
140-
"warehouse_id": "f00dcafe",
141-
"lifecycle": map[string]any{
142-
"prevent_destroy": true,
143-
},
144-
}, out.Dashboard["my_dashboard"])
145-
}

bundle/deploy/terraform/tfdyn/convert_database_catalog.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ func (d databaseCatalogConverter) Convert(ctx context.Context, key string, vin d
1818
for _, diag := range diags {
1919
log.Debugf(ctx, "database Catalog normalization diagnostic: %s", diag.Summary)
2020
}
21+
22+
var err error
23+
vout, err = convertLifecycle(ctx, vout, vin.Get("lifecycle"))
24+
if err != nil {
25+
return err
26+
}
27+
2128
out.DatabaseDatabaseCatalog[key] = vout.AsAny()
2229

2330
return nil

0 commit comments

Comments
 (0)