Skip to content

Commit 2e9b391

Browse files
ppitonakclaude
authored andcommitted
feat(azure): add keep-state and force-destroy support for all Azure destroy commands
Brings Azure destroy operations to parity with AWS by adding --keep-state and --force-destroy flags. Adds Azure Blob Storage service module for state file cleanup, and wires CleanupState/DestroyStack through all Azure action destroy functions. Resolves #674 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Pavol Pitonak <ppitonak@redhat.com>
1 parent e422cb2 commit 2e9b391

105 files changed

Lines changed: 26844 additions & 36 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/mapt/cmd/azure/hosts/linux.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,27 @@ func getCreateLinux(ostype data.OSType, defaultOSVersion string) *cobra.Command
8484
}
8585

8686
func getDestroyLinux() *cobra.Command {
87-
return &cobra.Command{
87+
c := &cobra.Command{
8888
Use: params.DestroyCmdName,
8989
Short: params.DestroyCmdName,
9090
RunE: func(cmd *cobra.Command, args []string) error {
9191
if err := viper.BindPFlags(cmd.Flags()); err != nil {
9292
return err
9393
}
9494
return azureLinux.Destroy(&maptContext.ContextArgs{
95-
Context: cmd.Context(),
96-
ProjectName: viper.GetString(params.ProjectName),
97-
BackedURL: viper.GetString(params.BackedURL),
98-
Debug: viper.IsSet(params.Debug),
99-
DebugLevel: viper.GetUint(params.DebugLevel),
95+
Context: cmd.Context(),
96+
ProjectName: viper.GetString(params.ProjectName),
97+
BackedURL: viper.GetString(params.BackedURL),
98+
Debug: viper.IsSet(params.Debug),
99+
DebugLevel: viper.GetUint(params.DebugLevel),
100+
ForceDestroy: viper.IsSet(params.ForceDestroy),
101+
KeepState: viper.IsSet(params.KeepState),
100102
})
101103
},
102104
}
105+
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
106+
flagSet.Bool(params.ForceDestroy, false, params.ForceDestroyDesc)
107+
flagSet.Bool(params.KeepState, false, params.KeepStateDesc)
108+
c.PersistentFlags().AddFlagSet(flagSet)
109+
return c
103110
}

cmd/mapt/cmd/azure/hosts/rhel.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,27 @@ func getCreateRHEL() *cobra.Command {
8484
}
8585

8686
func getDestroyRHEL() *cobra.Command {
87-
return &cobra.Command{
87+
c := &cobra.Command{
8888
Use: params.DestroyCmdName,
8989
Short: params.DestroyCmdName,
9090
RunE: func(cmd *cobra.Command, args []string) error {
9191
if err := viper.BindPFlags(cmd.Flags()); err != nil {
9292
return err
9393
}
9494
return azureRHEL.Destroy(&maptContext.ContextArgs{
95-
Context: cmd.Context(),
96-
ProjectName: viper.GetString(params.ProjectName),
97-
BackedURL: viper.GetString(params.BackedURL),
98-
Debug: viper.IsSet(params.Debug),
99-
DebugLevel: viper.GetUint(params.DebugLevel),
95+
Context: cmd.Context(),
96+
ProjectName: viper.GetString(params.ProjectName),
97+
BackedURL: viper.GetString(params.BackedURL),
98+
Debug: viper.IsSet(params.Debug),
99+
DebugLevel: viper.GetUint(params.DebugLevel),
100+
ForceDestroy: viper.IsSet(params.ForceDestroy),
101+
KeepState: viper.IsSet(params.KeepState),
100102
})
101103
},
102104
}
105+
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
106+
flagSet.Bool(params.ForceDestroy, false, params.ForceDestroyDesc)
107+
flagSet.Bool(params.KeepState, false, params.KeepStateDesc)
108+
c.PersistentFlags().AddFlagSet(flagSet)
109+
return c
103110
}

cmd/mapt/cmd/azure/hosts/windows.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,30 @@ func getCreateWindowsDesktop() *cobra.Command {
9696
}
9797

9898
func getDestroyWindowsDesktop() *cobra.Command {
99-
return &cobra.Command{
99+
c := &cobra.Command{
100100
Use: params.DestroyCmdName,
101101
Short: params.DestroyCmdName,
102102
RunE: func(cmd *cobra.Command, args []string) error {
103103
if err := viper.BindPFlags(cmd.Flags()); err != nil {
104104
return err
105105
}
106106
if err := azureWindows.Destroy(&maptContext.ContextArgs{
107-
Context: cmd.Context(),
108-
ProjectName: viper.GetString(params.ProjectName),
109-
BackedURL: viper.GetString(params.BackedURL),
110-
Debug: viper.IsSet(params.Debug),
111-
DebugLevel: viper.GetUint(params.DebugLevel),
107+
Context: cmd.Context(),
108+
ProjectName: viper.GetString(params.ProjectName),
109+
BackedURL: viper.GetString(params.BackedURL),
110+
Debug: viper.IsSet(params.Debug),
111+
DebugLevel: viper.GetUint(params.DebugLevel),
112+
ForceDestroy: viper.IsSet(params.ForceDestroy),
113+
KeepState: viper.IsSet(params.KeepState),
112114
}); err != nil {
113115
logging.Error(err)
114116
}
115117
return nil
116118
},
117119
}
120+
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
121+
flagSet.Bool(params.ForceDestroy, false, params.ForceDestroyDesc)
122+
flagSet.Bool(params.KeepState, false, params.KeepStateDesc)
123+
c.PersistentFlags().AddFlagSet(flagSet)
124+
return c
118125
}

cmd/mapt/cmd/azure/services/aks.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,27 @@ func getCreateAKS() *cobra.Command {
8585
}
8686

8787
func getDestroyAKS() *cobra.Command {
88-
return &cobra.Command{
88+
c := &cobra.Command{
8989
Use: params.DestroyCmdName,
9090
Short: params.DestroyCmdName,
9191
RunE: func(cmd *cobra.Command, args []string) error {
9292
if err := viper.BindPFlags(cmd.Flags()); err != nil {
9393
return err
9494
}
9595
return azureAKS.Destroy(&maptContext.ContextArgs{
96-
Context: cmd.Context(),
97-
ProjectName: viper.GetString(params.ProjectName),
98-
BackedURL: viper.GetString(params.BackedURL),
99-
Debug: viper.IsSet(params.Debug),
100-
DebugLevel: viper.GetUint(params.DebugLevel),
96+
Context: cmd.Context(),
97+
ProjectName: viper.GetString(params.ProjectName),
98+
BackedURL: viper.GetString(params.BackedURL),
99+
Debug: viper.IsSet(params.Debug),
100+
DebugLevel: viper.GetUint(params.DebugLevel),
101+
ForceDestroy: viper.IsSet(params.ForceDestroy),
102+
KeepState: viper.IsSet(params.KeepState),
101103
})
102104
},
103105
}
106+
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
107+
flagSet.Bool(params.ForceDestroy, false, params.ForceDestroyDesc)
108+
flagSet.Bool(params.KeepState, false, params.KeepStateDesc)
109+
c.PersistentFlags().AddFlagSet(flagSet)
110+
return c
104111
}

cmd/mapt/cmd/azure/services/kind.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,14 @@ func destroyKind() *cobra.Command {
103103
DebugLevel: viper.GetUint(params.DebugLevel),
104104
Serverless: viper.IsSet(params.Serverless),
105105
ForceDestroy: viper.IsSet(params.ForceDestroy),
106+
KeepState: viper.IsSet(params.KeepState),
106107
})
107108
},
108109
}
109110
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
110111
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
111112
flagSet.Bool(params.ForceDestroy, false, params.ForceDestroyDesc)
113+
flagSet.Bool(params.KeepState, false, params.KeepStateDesc)
112114
c.PersistentFlags().AddFlagSet(flagSet)
113115
return c
114116
}

cmd/mapt/cmd/params/params.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ const (
119119
ForceDestroy string = "force-destroy"
120120
ForceDestroyDesc string = "if force-destroy is set the command will destroy even if there is a lock."
121121
KeepState string = "keep-state"
122-
KeepStateDesc string = "keep Pulumi state files in S3 backend after successful destroy (by default, state files are removed)"
122+
KeepStateDesc string = "keep Pulumi state files in backend storage after successful destroy (by default, state files are removed)"
123123

124124
// Kind
125125
KindCmd = "kind"

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ require (
7979
github.com/Azure/azure-sdk-for-go/sdk/internal v1.12.0 // indirect
8080
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v3 v3.2.0 // indirect
8181
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups v1.2.0 // indirect
82+
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.6.4 // indirect
8283
github.com/AzureAD/microsoft-authentication-library-for-go v1.7.1 // indirect
8384
github.com/agext/levenshtein v1.2.3 // indirect
8485
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources/v3
2626
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources/v3 v3.0.1/go.mod h1:8h8yhzh9o+0HeSIhUxYny+rEQajScrfIpNktvgYG3Q8=
2727
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions v1.3.0 h1:wxQx2Bt4xzPIKvW59WQf1tJNx/ZZKPfN+EhPX3Z6CYY=
2828
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions v1.3.0/go.mod h1:TpiwjwnW/khS0LKs4vW5UmmT9OWcxaveS8U7+tlknzo=
29+
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.6.4 h1:jWQK1GI+LeGGUKBADtcH2rRqPxYB1Ljwms5gFA2LqrM=
30+
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.6.4/go.mod h1:8mwH4klAm9DUgR2EEHyEEAQlRDvLPyg5fQry3y+cDew=
2931
github.com/AzureAD/microsoft-authentication-extensions-for-go/cache v0.1.1 h1:WJTmL004Abzc5wDB5VtZG2PJk5ndYDgVacGqfirKxjM=
3032
github.com/AzureAD/microsoft-authentication-extensions-for-go/cache v0.1.1/go.mod h1:tCcJZ0uHAmvjsVYzEFivsRTN00oz5BEsRgQHu5JZ9WE=
3133
github.com/AzureAD/microsoft-authentication-library-for-go v1.7.1 h1:edShSHV3DV90+kt+CMaEXEzR9QF7wFrPJxVGz2blMIU=

pkg/provider/azure/action/aks/aks.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,16 @@ func Create(mCtxArgs *mc.ContextArgs, args *AKSArgs) (err error) {
8787

8888
func Destroy(mCtxArgs *mc.ContextArgs) error {
8989
logging.Debug("Destroy AKS")
90-
// Create mapt Context
9190
mCtx, err := mc.Init(mCtxArgs, azure.Provider())
9291
if err != nil {
9392
return err
9493
}
95-
return azure.Destroy(mCtx, stackAKS)
94+
if err := azure.DestroyStack(mCtx, azure.DestroyStackRequest{
95+
Stackname: stackAKS,
96+
}); err != nil {
97+
return err
98+
}
99+
return azure.CleanupState(mCtx)
96100
}
97101

98102
// Main function to deploy all requried resources to azure

pkg/provider/azure/action/kind/kind.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,16 @@ func Create(mCtxArgs *mc.ContextArgs, args *utilKind.KindArgs) (*utilKind.KindRe
9595
}
9696

9797
func Destroy(mCtxArgs *mc.ContextArgs) (err error) {
98-
// Create mapt Context
9998
mCtx, err := mc.Init(mCtxArgs, azure.Provider())
10099
if err != nil {
101100
return err
102101
}
103-
// destroy
104-
return azure.Destroy(mCtx, stackAzureKind)
102+
if err := azure.DestroyStack(mCtx, azure.DestroyStackRequest{
103+
Stackname: stackAzureKind,
104+
}); err != nil {
105+
return err
106+
}
107+
return azure.CleanupState(mCtx)
105108
}
106109

107110
// Main function to deploy all requried resources to azure

0 commit comments

Comments
 (0)