@@ -19,55 +19,95 @@ import (
1919 "github.com/databricks/cli/bundle/scripts"
2020 "github.com/databricks/cli/libs/cmdio"
2121 terraformlib "github.com/databricks/cli/libs/terraform"
22+ tfjson "github.com/hashicorp/terraform-json"
2223)
2324
24- func approvalForUcSchemaDelete (ctx context.Context , b * bundle.Bundle ) (bool , error ) {
25- tf := b .Terraform
26- if tf == nil {
27- return false , fmt .Errorf ("terraform not initialized" )
28- }
29-
30- // read plan file
31- plan , err := tf .ShowPlanFile (ctx , b .Plan .Path )
32- if err != nil {
33- return false , err
34- }
35-
36- actions := make ([]terraformlib.Action , 0 )
37- for _ , rc := range plan .ResourceChanges {
38- // We only care about destructive actions on UC schema resources.
39- if rc .Type != "databricks_schema" {
25+ func parseTerraformActions (changes []* tfjson.ResourceChange , toInclude func (typ string , actions tfjson.Actions ) bool ) []terraformlib.Action {
26+ res := make ([]terraformlib.Action , 0 )
27+ for _ , rc := range changes {
28+ if ! toInclude (rc .Type , rc .Change .Actions ) {
4029 continue
4130 }
4231
4332 var actionType terraformlib.ActionType
44-
4533 switch {
4634 case rc .Change .Actions .Delete ():
4735 actionType = terraformlib .ActionTypeDelete
4836 case rc .Change .Actions .Replace ():
4937 actionType = terraformlib .ActionTypeRecreate
5038 default :
51- // We don't need a prompt for non-destructive actions like creating
52- // or updating a schema.
39+ // No use case for other action types yet.
5340 continue
5441 }
5542
56- actions = append (actions , terraformlib.Action {
43+ res = append (res , terraformlib.Action {
5744 Action : actionType ,
5845 ResourceType : rc .Type ,
5946 ResourceName : rc .Name ,
6047 })
6148 }
6249
63- // No restricted actions planned. No need for approval.
64- if len (actions ) == 0 {
50+ return res
51+ }
52+
53+ func approvalForDeploy (ctx context.Context , b * bundle.Bundle ) (bool , error ) {
54+ tf := b .Terraform
55+ if tf == nil {
56+ return false , fmt .Errorf ("terraform not initialized" )
57+ }
58+
59+ // read plan file
60+ plan , err := tf .ShowPlanFile (ctx , b .Plan .Path )
61+ if err != nil {
62+ return false , err
63+ }
64+
65+ schemaActions := parseTerraformActions (plan .ResourceChanges , func (typ string , actions tfjson.Actions ) bool {
66+ // Filter in only UC schema resources.
67+ if typ != "databricks_schema" {
68+ return false
69+ }
70+
71+ // We only display prompts for destructive actions like deleting or
72+ // recreating a schema.
73+ return actions .Delete () || actions .Replace ()
74+ })
75+
76+ dltActions := parseTerraformActions (plan .ResourceChanges , func (typ string , actions tfjson.Actions ) bool {
77+ // Filter in only DLT pipeline resources.
78+ if typ != "databricks_pipeline" {
79+ return false
80+ }
81+
82+ // Recreating DLT pipeline leads to metadata loss and for a transient period
83+ // the underling tables will be unavailable.
84+ return actions .Replace () || actions .Delete ()
85+ })
86+
87+ // We don't need to display any prompts in this case.
88+ if len (dltActions ) == 0 && len (schemaActions ) == 0 {
6589 return true , nil
6690 }
6791
68- cmdio .LogString (ctx , "The following UC schemas will be deleted or recreated. Any underlying data may be lost:" )
69- for _ , action := range actions {
70- cmdio .Log (ctx , action )
92+ // One or more UC schema resources will be deleted or recreated.
93+ if len (schemaActions ) != 0 {
94+ cmdio .LogString (ctx , "The following UC schemas will be deleted or recreated. Any underlying data may be lost:" )
95+ for _ , action := range schemaActions {
96+ cmdio .Log (ctx , action )
97+ }
98+ }
99+
100+ // One or more DLT pipelines is being recreated.
101+ if len (dltActions ) != 0 {
102+ msg := `
103+ This action will result in the deletion or recreation of the following DLT Pipelines along with the
104+ Streaming Tables (STs) and Materialized Views (MVs) managed by them. Recreating the Pipelines will
105+ restore the defined STs and MVs through full refresh. Note that recreation is necessary when pipeline
106+ properties such as the 'catalog' or 'storage' are changed:`
107+ cmdio .LogString (ctx , msg )
108+ for _ , action := range dltActions {
109+ cmdio .Log (ctx , action )
110+ }
71111 }
72112
73113 if b .AutoApprove {
@@ -126,7 +166,7 @@ func Deploy() bundle.Mutator {
126166 terraform .CheckRunningResource (),
127167 terraform .Plan (terraform .PlanGoal ("deploy" )),
128168 bundle .If (
129- approvalForUcSchemaDelete ,
169+ approvalForDeploy ,
130170 deployCore ,
131171 bundle .LogString ("Deployment cancelled!" ),
132172 ),
0 commit comments