Skip to content

Commit 109d453

Browse files
committed
fixes
1 parent a32e69a commit 109d453

File tree

6 files changed

+59
-35
lines changed

6 files changed

+59
-35
lines changed

acceptance/bundle/lifecycle/prevent-destroy/script

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ trace errcode $CLI bundle plan >>out.$DATABRICKS_CLI_DEPLOYMENT.txt 2>&1
1616
trace $CLI bundle deploy --auto-approve >>out.$DATABRICKS_CLI_DEPLOYMENT.txt 2>&1
1717

1818
update_file.py databricks.yml 'prevent_destroy: false' 'prevent_destroy: true'
19-
# Removing the job, deploy must succeed
19+
# Removing the pipeline, deploy must succeed
2020
update_file.py databricks.yml '<<: *pipeline_base' ''
2121
trace errcode $CLI bundle plan >>out.$DATABRICKS_CLI_DEPLOYMENT.txt 2>&1
2222
trace $CLI bundle deploy --auto-approve >>out.$DATABRICKS_CLI_DEPLOYMENT.txt 2>&1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package resources
22

3+
// Lifecycle is a struct that contains the lifecycle settings for a resource.
4+
// It controls the behavior of the resource when it is deployed or destroyed.
35
type Lifecycle struct {
6+
// Lifecycle setting to prevent the resource from being destroyed.
47
PreventDestroy bool `json:"prevent_destroy,omitempty"`
58
}

bundle/internal/schema/annotations.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,6 @@ github.com/databricks/cli/bundle/config/resources.DashboardPermission:
478478
"user_name":
479479
"description": |-
480480
PLACEHOLDER
481-
github.com/databricks/cli/bundle/config/resources.DatabaseCatalog:
482-
"lifecycle":
483-
"description": |-
484-
PLACEHOLDER
485481
github.com/databricks/cli/bundle/config/resources.DatabaseInstancePermission:
486482
"group_name":
487483
"description": |-
@@ -518,7 +514,7 @@ github.com/databricks/cli/bundle/config/resources.JobPermission:
518514
github.com/databricks/cli/bundle/config/resources.Lifecycle:
519515
"prevent_destroy":
520516
"description": |-
521-
PLACEHOLDER
517+
Lifecycle setting to prevent the resource from being destroyed.
522518
github.com/databricks/cli/bundle/config/resources.MlflowExperimentPermission:
523519
"group_name":
524520
"description": |-
@@ -605,7 +601,7 @@ github.com/databricks/cli/bundle/config/resources.SecretScope:
605601
The metadata for the secret scope if the `backend_type` is `AZURE_KEYVAULT`
606602
"lifecycle":
607603
"description": |-
608-
PLACEHOLDER
604+
Lifecycle is a struct that contains the lifecycle settings for a resource. It controls the behavior of the resource when it is deployed or destroyed.
609605
"name":
610606
"description": |-
611607
Scope name requested by the user. Scope names are unique.
@@ -653,7 +649,7 @@ github.com/databricks/cli/bundle/config/resources.SyncedDatabaseTable:
653649
PLACEHOLDER
654650
"lifecycle":
655651
"description": |-
656-
PLACEHOLDER
652+
Lifecycle is a struct that contains the lifecycle settings for a resource. It controls the behavior of the resource when it is deployed or destroyed.
657653
"logical_database_name":
658654
"description": |-
659655
PLACEHOLDER

bundle/internal/schema/annotations_openapi_overrides.yml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ github.com/databricks/cli/bundle/config/resources.App:
1616
PLACEHOLDER
1717
"lifecycle":
1818
"description": |-
19-
PLACEHOLDER
19+
Lifecycle is a struct that contains the lifecycle settings for a resource. It controls the behavior of the resource when it is deployed or destroyed.
2020
"oauth2_app_client_id":
2121
"description": |-
2222
PLACEHOLDER
@@ -89,7 +89,7 @@ github.com/databricks/cli/bundle/config/resources.Cluster:
8989
PLACEHOLDER
9090
"lifecycle":
9191
"description": |-
92-
PLACEHOLDER
92+
Lifecycle is a struct that contains the lifecycle settings for a resource. It controls the behavior of the resource when it is deployed or destroyed.
9393
"permissions":
9494
"description": |-
9595
PLACEHOLDER
@@ -148,7 +148,7 @@ github.com/databricks/cli/bundle/config/resources.Dashboard:
148148
PLACEHOLDER
149149
"lifecycle":
150150
"description": |-
151-
PLACEHOLDER
151+
Lifecycle is a struct that contains the lifecycle settings for a resource. It controls the behavior of the resource when it is deployed or destroyed.
152152
"lifecycle_state":
153153
"description": |-
154154
The state of the dashboard resource. Used for tracking trashed status.
@@ -195,13 +195,16 @@ github.com/databricks/cli/bundle/config/resources.DatabaseCatalog:
195195
"create_database_if_not_exists":
196196
"description": |-
197197
PLACEHOLDER
198+
"lifecycle":
199+
"description": |-
200+
Lifecycle is a struct that contains the lifecycle settings for a resource. It controls the behavior of the resource when it is deployed or destroyed.
198201
"uid":
199202
"description": |-
200203
PLACEHOLDER
201204
github.com/databricks/cli/bundle/config/resources.DatabaseInstance:
202205
"lifecycle":
203206
"description": |-
204-
PLACEHOLDER
207+
Lifecycle is a struct that contains the lifecycle settings for a resource. It controls the behavior of the resource when it is deployed or destroyed.
205208
"permissions":
206209
"description": |-
207210
PLACEHOLDER
@@ -238,7 +241,7 @@ github.com/databricks/cli/bundle/config/resources.Job:
238241
PLACEHOLDER
239242
"lifecycle":
240243
"description": |-
241-
PLACEHOLDER
244+
Lifecycle is a struct that contains the lifecycle settings for a resource. It controls the behavior of the resource when it is deployed or destroyed.
242245
"permissions":
243246
"description": |-
244247
PLACEHOLDER
@@ -275,7 +278,7 @@ github.com/databricks/cli/bundle/config/resources.MlflowExperiment:
275278
```
276279
"lifecycle":
277280
"description": |-
278-
PLACEHOLDER
281+
Lifecycle is a struct that contains the lifecycle settings for a resource. It controls the behavior of the resource when it is deployed or destroyed.
279282
"permissions":
280283
"description": |-
281284
PLACEHOLDER
@@ -294,7 +297,7 @@ github.com/databricks/cli/bundle/config/resources.MlflowModel:
294297
The model resource allows you to define [legacy models](/api/workspace/modelregistry/createmodel) in bundles. Databricks recommends you use Unity Catalog [registered models](#registered-model) instead.
295298
"lifecycle":
296299
"description": |-
297-
PLACEHOLDER
300+
Lifecycle is a struct that contains the lifecycle settings for a resource. It controls the behavior of the resource when it is deployed or destroyed.
298301
"permissions":
299302
"description": |-
300303
PLACEHOLDER
@@ -342,7 +345,7 @@ github.com/databricks/cli/bundle/config/resources.ModelServingEndpoint:
342345
PLACEHOLDER
343346
"lifecycle":
344347
"description": |-
345-
PLACEHOLDER
348+
Lifecycle is a struct that contains the lifecycle settings for a resource. It controls the behavior of the resource when it is deployed or destroyed.
346349
"permissions":
347350
"description": |-
348351
PLACEHOLDER
@@ -384,7 +387,7 @@ github.com/databricks/cli/bundle/config/resources.Pipeline:
384387
PLACEHOLDER
385388
"lifecycle":
386389
"description": |-
387-
PLACEHOLDER
390+
Lifecycle is a struct that contains the lifecycle settings for a resource. It controls the behavior of the resource when it is deployed or destroyed.
388391
"permissions":
389392
"description": |-
390393
PLACEHOLDER
@@ -435,7 +438,7 @@ github.com/databricks/cli/bundle/config/resources.QualityMonitor:
435438
PLACEHOLDER
436439
"lifecycle":
437440
"description": |-
438-
PLACEHOLDER
441+
Lifecycle is a struct that contains the lifecycle settings for a resource. It controls the behavior of the resource when it is deployed or destroyed.
439442
"table_name":
440443
"description": |-
441444
PLACEHOLDER
@@ -464,7 +467,7 @@ github.com/databricks/cli/bundle/config/resources.RegisteredModel:
464467
PLACEHOLDER
465468
"lifecycle":
466469
"description": |-
467-
PLACEHOLDER
470+
Lifecycle is a struct that contains the lifecycle settings for a resource. It controls the behavior of the resource when it is deployed or destroyed.
468471
github.com/databricks/cli/bundle/config/resources.Schema:
469472
"_":
470473
"markdown_description": |-
@@ -517,7 +520,7 @@ github.com/databricks/cli/bundle/config/resources.Schema:
517520
PLACEHOLDER
518521
"lifecycle":
519522
"description": |-
520-
PLACEHOLDER
523+
Lifecycle is a struct that contains the lifecycle settings for a resource. It controls the behavior of the resource when it is deployed or destroyed.
521524
"properties":
522525
"description": |-
523526
PLACEHOLDER
@@ -567,7 +570,7 @@ github.com/databricks/cli/bundle/config/resources.SqlWarehouse:
567570
Defaults to true.
568571
"lifecycle":
569572
"description": |-
570-
PLACEHOLDER
573+
Lifecycle is a struct that contains the lifecycle settings for a resource. It controls the behavior of the resource when it is deployed or destroyed.
571574
"permissions":
572575
"description": |-
573576
PLACEHOLDER
@@ -614,7 +617,7 @@ github.com/databricks/cli/bundle/config/resources.Volume:
614617
PLACEHOLDER
615618
"lifecycle":
616619
"description": |-
617-
PLACEHOLDER
620+
Lifecycle is a struct that contains the lifecycle settings for a resource. It controls the behavior of the resource when it is deployed or destroyed.
618621
"volume_type":
619622
"description": |-
620623
PLACEHOLDER

bundle/phases/plan.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,24 @@ func deployPrepare(ctx context.Context, b *bundle.Bundle) map[string][]libraries
5555
func checkForPreventDestroy(b *bundle.Bundle, actions []deployplan.Action, isDestroy bool) error {
5656
root := b.Config.Value()
5757
for _, action := range actions {
58-
if action.ActionType == deployplan.ActionTypeRecreate || (isDestroy && action.ActionType == deployplan.ActionTypeDelete) {
59-
path := dyn.NewPath(dyn.Key("resources"), dyn.Key(action.Group), dyn.Key(action.Key), dyn.Key("lifecycle"))
60-
lifecycleV, err := dyn.GetByPath(root, path)
61-
// If there is no lifecycle, skip
62-
if err != nil {
63-
return nil
64-
}
58+
// If the action is not a recreate or a delete as part of destroy - skip checking for prevent destroy
59+
// We allow delete as part of deploy though (hence isDestroy check) because we mimic the behavior of terraform which allows such resources to be removed from config.
60+
if action.ActionType != deployplan.ActionTypeRecreate && !(isDestroy && action.ActionType == deployplan.ActionTypeDelete) {
61+
continue
62+
}
63+
64+
path := dyn.NewPath(dyn.Key("resources"), dyn.Key(action.Group), dyn.Key(action.Key), dyn.Key("lifecycle"))
65+
lifecycleV, err := dyn.GetByPath(root, path)
66+
// If there is no lifecycle, skip
67+
if err != nil {
68+
return nil
69+
}
6570

66-
if lifecycleV.Kind() == dyn.KindMap {
67-
preventDestroyV := lifecycleV.Get("prevent_destroy")
68-
preventDestroy, ok := preventDestroyV.AsBool()
69-
if ok && preventDestroy {
70-
return fmt.Errorf("resource %s 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 %s.%s", action.Key, action.Group, action.Key)
71-
}
71+
if lifecycleV.Kind() == dyn.KindMap {
72+
preventDestroyV := lifecycleV.Get("prevent_destroy")
73+
preventDestroy, ok := preventDestroyV.AsBool()
74+
if ok && preventDestroy {
75+
return fmt.Errorf("resource %s 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 %s.%s", action.Key, action.Group, action.Key)
7276
}
7377
}
7478
}

bundle/schema/jsonschema.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)