Skip to content

Commit d172c91

Browse files
ppitonakadrianriobo
authored andcommitted
feat: add parameter cleanup-state
Parameter that adds option to remove Pulumi state files from S3 bucket for all AWS commands. Enabled by default. Closes #639 Signed-off-by: Pavol Pitonak <[email protected]>
1 parent e2b3754 commit d172c91

File tree

21 files changed

+139
-44
lines changed

21 files changed

+139
-44
lines changed

cmd/mapt/cmd/aws/hosts/fedora.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,14 @@ func getFedoraDestroy() *cobra.Command {
9797
DebugLevel: viper.GetUint(params.DebugLevel),
9898
Serverless: viper.IsSet(params.Serverless),
9999
ForceDestroy: viper.IsSet(params.ForceDestroy),
100+
CleanupState: viper.IsSet(params.CleanupState),
100101
})
101102
},
102103
}
103104
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
104105
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
105106
flagSet.Bool(params.ForceDestroy, false, params.ForceDestroyDesc)
107+
flagSet.Bool(params.CleanupState, true, params.CleanupStateDesc)
106108
c.PersistentFlags().AddFlagSet(flagSet)
107109
return c
108110
}

cmd/mapt/cmd/aws/hosts/mac.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,16 @@ func getMacDestroy() *cobra.Command {
107107
}
108108
return mac.Destroy(
109109
&maptContext.ContextArgs{
110-
Debug: viper.IsSet(params.Debug),
111-
DebugLevel: viper.GetUint(params.DebugLevel),
110+
Debug: viper.IsSet(params.Debug),
111+
DebugLevel: viper.GetUint(params.DebugLevel),
112+
CleanupState: viper.IsSet(params.CleanupState),
112113
},
113114
viper.GetString(awsParams.MACDHID))
114115
},
115116
}
116117
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
117118
flagSet.StringP(awsParams.MACDHID, "", "", awsParams.MACDHIDDesc)
119+
flagSet.Bool(params.CleanupState, true, params.CleanupStateDesc)
118120
c.PersistentFlags().AddFlagSet(flagSet)
119121
err := c.MarkPersistentFlagRequired(awsParams.MACDHID)
120122
if err != nil {

cmd/mapt/cmd/aws/hosts/rhel.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,18 @@ func getRHELDestroy() *cobra.Command {
9494
return err
9595
}
9696
return rhel.Destroy(&maptContext.ContextArgs{
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-
Serverless: viper.IsSet(params.Serverless),
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+
Serverless: viper.IsSet(params.Serverless),
102+
CleanupState: viper.IsSet(params.CleanupState),
102103
})
103104
},
104105
}
105106
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
106107
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
108+
flagSet.Bool(params.CleanupState, true, params.CleanupStateDesc)
107109
c.PersistentFlags().AddFlagSet(flagSet)
108110
return c
109111
}

cmd/mapt/cmd/aws/hosts/rhelai.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,14 @@ func getRHELAIDestroy() *cobra.Command {
9292
DebugLevel: viper.GetUint(params.DebugLevel),
9393
Serverless: viper.IsSet(params.Serverless),
9494
ForceDestroy: viper.IsSet(params.ForceDestroy),
95+
CleanupState: viper.IsSet(params.CleanupState),
9596
})
9697
},
9798
}
9899
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
99100
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
100101
flagSet.Bool(params.ForceDestroy, false, params.ForceDestroyDesc)
102+
flagSet.Bool(params.CleanupState, true, params.CleanupStateDesc)
101103
c.PersistentFlags().AddFlagSet(flagSet)
102104
return c
103105
}

cmd/mapt/cmd/aws/hosts/windows.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,22 @@ func getWindowsDestroy() *cobra.Command {
101101
Use: params.DestroyCmdName,
102102
Short: params.DestroyCmdName,
103103
RunE: func(cmd *cobra.Command, args []string) error {
104+
if err := viper.BindPFlags(cmd.Flags()); err != nil {
105+
return err
106+
}
104107
return windows.Destroy(&maptContext.ContextArgs{
105-
ProjectName: viper.GetString(params.ProjectName),
106-
BackedURL: viper.GetString(params.BackedURL),
107-
Debug: viper.IsSet(params.Debug),
108-
DebugLevel: viper.GetUint(params.DebugLevel),
109-
Serverless: viper.IsSet(params.Serverless),
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+
Serverless: viper.IsSet(params.Serverless),
113+
CleanupState: viper.IsSet(params.CleanupState),
110114
})
111115
},
112116
}
113117
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
114118
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
119+
flagSet.Bool(params.CleanupState, true, params.CleanupStateDesc)
115120
c.PersistentFlags().AddFlagSet(flagSet)
116121
return c
117122
}

cmd/mapt/cmd/aws/services/eks.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func getCreateEKS() *cobra.Command {
9898
}
9999

100100
func getDestroyEKS() *cobra.Command {
101-
return &cobra.Command{
101+
c := &cobra.Command{
102102
Use: params.DestroyCmdName,
103103
Short: params.DestroyCmdName,
104104
RunE: func(cmd *cobra.Command, args []string) error {
@@ -107,11 +107,16 @@ func getDestroyEKS() *cobra.Command {
107107
}
108108
return awsEKS.Destroy(
109109
&maptContext.ContextArgs{
110-
ProjectName: viper.GetString(params.ProjectName),
111-
BackedURL: viper.GetString(params.BackedURL),
112-
Debug: viper.IsSet(params.Debug),
113-
DebugLevel: viper.GetUint(params.DebugLevel),
110+
ProjectName: viper.GetString(params.ProjectName),
111+
BackedURL: viper.GetString(params.BackedURL),
112+
Debug: viper.IsSet(params.Debug),
113+
DebugLevel: viper.GetUint(params.DebugLevel),
114+
CleanupState: viper.IsSet(params.CleanupState),
114115
})
115116
},
116117
}
118+
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
119+
flagSet.Bool(params.CleanupState, true, params.CleanupStateDesc)
120+
c.PersistentFlags().AddFlagSet(flagSet)
121+
return c
117122
}

cmd/mapt/cmd/aws/services/kind.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,14 @@ func destroyKind() *cobra.Command {
100100
DebugLevel: viper.GetUint(params.DebugLevel),
101101
Serverless: viper.IsSet(params.Serverless),
102102
ForceDestroy: viper.IsSet(params.ForceDestroy),
103+
CleanupState: viper.IsSet(params.CleanupState),
103104
})
104105
},
105106
}
106107
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
107108
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
108109
flagSet.Bool(params.ForceDestroy, false, params.ForceDestroyDesc)
110+
flagSet.Bool(params.CleanupState, true, params.CleanupStateDesc)
109111
c.PersistentFlags().AddFlagSet(flagSet)
110112
return c
111113
}

cmd/mapt/cmd/aws/services/mac-pool.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,17 @@ func destroyMP() *cobra.Command {
9898
return err
9999
}
100100
return macpool.Destroy(&maptContext.ContextArgs{
101-
ProjectName: viper.GetString(params.ProjectName),
102-
BackedURL: viper.GetString(params.BackedURL),
103-
Debug: viper.IsSet(params.Debug),
104-
DebugLevel: viper.GetUint(params.DebugLevel),
101+
ProjectName: viper.GetString(params.ProjectName),
102+
BackedURL: viper.GetString(params.BackedURL),
103+
Debug: viper.IsSet(params.Debug),
104+
DebugLevel: viper.GetUint(params.DebugLevel),
105+
CleanupState: viper.IsSet(params.CleanupState),
105106
})
106107
},
107108
}
108109
flagSet := pflag.NewFlagSet(params.CreateCmdName, pflag.ExitOnError)
109110
params.AddCommonFlags(flagSet)
111+
flagSet.Bool(params.CleanupState, true, params.CleanupStateDesc)
110112
c.PersistentFlags().AddFlagSet(flagSet)
111113
return c
112114
}

cmd/mapt/cmd/aws/services/openshift-snc.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,18 @@ func destroySNC() *cobra.Command {
8989
return err
9090
}
9191
return openshiftsnc.Destroy(&maptContext.ContextArgs{
92-
ProjectName: viper.GetString(params.ProjectName),
93-
BackedURL: viper.GetString(params.BackedURL),
94-
Debug: viper.IsSet(params.Debug),
95-
DebugLevel: viper.GetUint(params.DebugLevel),
96-
Serverless: viper.IsSet(params.Serverless),
92+
ProjectName: viper.GetString(params.ProjectName),
93+
BackedURL: viper.GetString(params.BackedURL),
94+
Debug: viper.IsSet(params.Debug),
95+
DebugLevel: viper.GetUint(params.DebugLevel),
96+
Serverless: viper.IsSet(params.Serverless),
97+
CleanupState: viper.IsSet(params.CleanupState),
9798
})
9899
},
99100
}
100101
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
101102
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
103+
flagSet.Bool(params.CleanupState, true, params.CleanupStateDesc)
102104
c.PersistentFlags().AddFlagSet(flagSet)
103105
return c
104106
}

cmd/mapt/cmd/params/params.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ const (
9999
Serverless string = "serverless"
100100
ServerlessDesc string = "if serverless is set the command will be executed as a serverless action."
101101

102-
// Desytoy
102+
// Destroy
103103
ForceDestroy string = "force-destroy"
104104
ForceDestroyDesc string = "if force-destroy is set the command will destroy even if there is a lock."
105+
CleanupState string = "cleanup-state"
106+
CleanupStateDesc string = "automatically remove Pulumi state files from S3 backend after successful destroy"
105107

106108
// Kind
107109
KindCmd = "kind"

0 commit comments

Comments
 (0)