From ac40e02195e80054c3d976657dfe1922beb03b9e Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Tue, 5 Nov 2024 12:51:22 +0100 Subject: [PATCH 1/3] Do not execute build on bundle destroy --- cmd/bundle/destroy.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/bundle/destroy.go b/cmd/bundle/destroy.go index cd7e630626..9cb97bdc90 100644 --- a/cmd/bundle/destroy.go +++ b/cmd/bundle/destroy.go @@ -62,7 +62,6 @@ func newDestroyCommand() *cobra.Command { diags = bundle.Apply(ctx, b, bundle.Seq( phases.Initialize(), - phases.Build(), phases.Destroy(), )) if err := diags.Error(); err != nil { From f2ff4db494908971fc82f65bb88b41189922397b Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Tue, 5 Nov 2024 13:03:40 +0100 Subject: [PATCH 2/3] resolve variables for backward compatibility --- cmd/bundle/destroy.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/bundle/destroy.go b/cmd/bundle/destroy.go index 9cb97bdc90..f0b75f97cc 100644 --- a/cmd/bundle/destroy.go +++ b/cmd/bundle/destroy.go @@ -6,6 +6,7 @@ import ( "os" "github.com/databricks/cli/bundle" + "github.com/databricks/cli/bundle/config/mutator" "github.com/databricks/cli/bundle/phases" "github.com/databricks/cli/cmd/bundle/utils" "github.com/databricks/cli/cmd/root" @@ -62,6 +63,9 @@ func newDestroyCommand() *cobra.Command { diags = bundle.Apply(ctx, b, bundle.Seq( phases.Initialize(), + mutator.ResolveVariableReferences( + "artifacts", + ), phases.Destroy(), )) if err := diags.Error(); err != nil { From 99874a2b8ff5541d2813116c84dc58eadb39e8c0 Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Tue, 5 Nov 2024 21:13:28 +0100 Subject: [PATCH 3/3] add a comment --- cmd/bundle/destroy.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/bundle/destroy.go b/cmd/bundle/destroy.go index f0b75f97cc..711abbcd73 100644 --- a/cmd/bundle/destroy.go +++ b/cmd/bundle/destroy.go @@ -63,6 +63,9 @@ func newDestroyCommand() *cobra.Command { diags = bundle.Apply(ctx, b, bundle.Seq( phases.Initialize(), + // We need to resolve artifact variable (how we do it in build phase) + // because some of the to-be-destroyed resource might use this variable. + // Not resolving might lead to terraform "Reference to undeclared resource" error mutator.ResolveVariableReferences( "artifacts", ),