Skip to content

Commit

Permalink
Merge pull request #40 from paynejacob/issue-39
Browse files Browse the repository at this point in the history
  • Loading branch information
paynejacob authored Feb 22, 2022
2 parents 6d254e5 + 998f322 commit 605a3ac
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ func NewCommandDelete() *cobra.Command {
Run: deleteCorral,
}

cmd.Flags().Bool("dry-run", false, "Display what resources this corral will create.")
_ = cfgViper.BindPFlag("dry-run", cmd.Flags().Lookup("dry-run"))
cmd.Flags().Bool("skip-cleanup", false, "Do not run terraform destroy just delete the package. This can result in un-tracked infrastructure resources!")

return cmd
}

func deleteCorral(_ *cobra.Command, args []string) {
func deleteCorral(cmd *cobra.Command, args []string) {
for _, name := range args {
c, err := corral.Load(config.CorralPath(name))
if err != nil {
Expand All @@ -46,24 +45,26 @@ func deleteCorral(_ *cobra.Command, args []string) {

c.SetStatus(corral.StatusDeleting)

logrus.Infof("running terraform destroy for [%s]", name)
pkg, err := _package.LoadPackage(c.Source)
if err != nil {
logrus.Error("could not load package associated with corral: ", err)
}
if skip, _ := cmd.Flags().GetBool("skip-cleanup"); !skip {
logrus.Infof("running terraform destroy for [%s]", name)
pkg, err := _package.LoadPackage(c.Source)
if err != nil {
logrus.Error("could not load package associated with corral: ", err)
}

tf, err := config.NewTerraform(c.TerraformPath(), pkg.TerraformVersion())
if err != nil {
logrus.Fatal("failed to load terraform: ", err)
}
if debug {
tf.SetStdout(os.Stdout)
}
tf, err := config.NewTerraform(c.TerraformPath(), pkg.TerraformVersion())
if err != nil {
logrus.Fatal("failed to load terraform: ", err)
}
if debug {
tf.SetStdout(os.Stdout)
}

err = tf.Destroy(context.Background())
if err != nil {
logrus.Errorf("failed to cleanup corral resources [%s]: %s", c.Name, err)
continue
err = tf.Destroy(context.Background())
if err != nil {
logrus.Errorf("failed to cleanup corral resources [%s]: %s", c.Name, err)
continue
}
}

err = c.Delete()
Expand Down

0 comments on commit 605a3ac

Please sign in to comment.