Skip to content

Commit e7d2877

Browse files
Restore comments and whitespace removed unnecessarily from deploy/destroy phases
Co-authored-by: Isaac
1 parent cdc80c7 commit e7d2877

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

bundle/direct/bundle_apply.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func (b *DeploymentBundle) Apply(ctx context.Context, client *databricks.Workspa
114114
}
115115

116116
// We don't keep NewState around for 'skip' nodes
117+
117118
if action != deployplan.Skip {
118119
if !b.resolveReferences(ctx, resourceKey, entry, errorPrefix, false) {
119120
return false

bundle/phases/deploy.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ func approvalForDeploy(ctx context.Context, b *bundle.Bundle, plan *deployplan.P
9898
}
9999

100100
func deployCore(ctx context.Context, b *bundle.Bundle, plan *deployplan.Plan, targetEngine engine.EngineType) {
101+
// Core mutators that CRUD resources and modify deployment state. These
102+
// mutators need informed consent if they are potentially destructive.
101103
cmdio.LogString(ctx, "Deploying resources...")
102104

103105
if targetEngine.IsDirect() {
@@ -113,6 +115,7 @@ func deployCore(ctx context.Context, b *bundle.Bundle, plan *deployplan.Plan, ta
113115
bundle.ApplyContext(ctx, b, terraform.Apply())
114116
}
115117

118+
// Even if deployment failed, there might be updates in states that we need to upload
116119
statemgmt.PushResourcesState(ctx, b, targetEngine)
117120
if logdiag.HasError(ctx) {
118121
return
@@ -178,11 +181,13 @@ func Deploy(ctx context.Context, b *bundle.Bundle, outputHandler sync.OutputHand
178181
metrics.TrackUsedCompute(),
179182
deploy.ResourcePathMkdir(),
180183
)
184+
181185
if logdiag.HasError(ctx) {
182186
return
183187
}
184188

185189
if plan != nil {
190+
// Initialize DeploymentBundle for applying the loaded plan
186191
err := b.DeploymentBundle.InitForApply(ctx, b.WorkspaceClient(), plan)
187192
if err != nil {
188193
logdiag.LogError(ctx, err)
@@ -191,6 +196,7 @@ func Deploy(ctx context.Context, b *bundle.Bundle, outputHandler sync.OutputHand
191196
} else {
192197
plan = RunPlan(ctx, b, engine)
193198
}
199+
194200
if logdiag.HasError(ctx) {
195201
return
196202
}
@@ -200,12 +206,13 @@ func Deploy(ctx context.Context, b *bundle.Bundle, outputHandler sync.OutputHand
200206
logdiag.LogError(ctx, err)
201207
return
202208
}
203-
if !haveApproval {
209+
if haveApproval {
210+
deployCore(ctx, b, plan, engine)
211+
} else {
204212
cmdio.LogString(ctx, "Deployment cancelled!")
205213
return
206214
}
207215

208-
deployCore(ctx, b, plan, engine)
209216
if logdiag.HasError(ctx) {
210217
return
211218
}

bundle/phases/destroy.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ func destroyCore(ctx context.Context, b *bundle.Bundle, plan *deployplan.Plan, e
104104
}
105105
}
106106
} else {
107+
// Core destructive mutators for destroy. These require informed user consent.
107108
bundle.ApplyContext(ctx, b, terraform.Apply())
108109
}
109110

@@ -127,6 +128,7 @@ func Destroy(ctx context.Context, b *bundle.Bundle, engine engine.EngineType) {
127128
logdiag.LogError(ctx, err)
128129
return
129130
}
131+
130132
if !ok {
131133
cmdio.LogString(ctx, "No active deployment found to destroy!")
132134
return
@@ -149,6 +151,9 @@ func Destroy(ctx context.Context, b *bundle.Bundle, engine engine.EngineType) {
149151

150152
if !engine.IsDirect() {
151153
bundle.ApplySeqContext(ctx, b,
154+
// We need to resolve artifact variable (how we do it in build phase)
155+
// because some of the to-be-destroyed resource might use this variable.
156+
// Not resolving might lead to terraform "Reference to undeclared resource" error
152157
mutator.ResolveVariableReferencesWithoutResources("artifacts"),
153158
mutator.ResolveVariableReferencesOnlyResources("artifacts"),
154159

0 commit comments

Comments
 (0)