Skip to content

Commit

Permalink
replace hardcoded values with configs
Browse files Browse the repository at this point in the history
  • Loading branch information
nirdosh17 committed Aug 13, 2024
1 parent 097cf86 commit 0b15394
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
3 changes: 1 addition & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ import (
// config vars
var (
cfgFile string
config models.Config
)

var config models.Config

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "cfn-teardown",
Expand Down
17 changes: 4 additions & 13 deletions utils/deleter.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ import (
"github.com/nirdosh17/cfn-teardown/models"
)

// -------------- configs ---------------
const (
// STACK_DELETION_WAIT_TIME_IN_SEC is the time to wait for stacks before peforming status checks after delete requests have been sent.
STACK_DELETION_WAIT_TIME_IN_SEC int16 = 30

// MAX_DELETE_RETRY_COUNT specifies the number of times we should retry deleting a stack before giving up.
MAX_DELETE_RETRY_COUNT int16 = 5
)

var (
// NUKE_START_TIME is the start timestamp of teardown.
NUKE_START_TIME = CurrentUTCDateTime()
Expand Down Expand Up @@ -152,8 +143,8 @@ func InitiateTearDown(config models.Config) {

// 3. Wait for 30 seconds
fmt.Println("\n-----------------------------------------------------------------------------")
fmt.Printf("Waiting for %v seconds...\n", STACK_DELETION_WAIT_TIME_IN_SEC)
time.Sleep(time.Duration(STACK_DELETION_WAIT_TIME_IN_SEC) * time.Second)
fmt.Printf("Waiting for %v seconds...\n", config.StackWaitTimeSeconds)
time.Sleep(time.Duration(config.StackWaitTimeSeconds) * time.Second)

// 4. Get list of stacks in DELETE_IN_PROGRESS and describe stack
// 4.1. If status is still DELETE_IN_PROGRESS, skip
Expand Down Expand Up @@ -208,7 +199,7 @@ func InitiateTearDown(config models.Config) {
writeToJSON(config.StackPattern, dependencyTree)
fmt.Printf("Stack successfully deleted: %v\n", sName)
} else {
if stack.DeleteAttempt >= MAX_DELETE_RETRY_COUNT {
if stack.DeleteAttempt >= config.MaxDeleteRetryCount {
stack.Status = newStatus
statusReason := *details.StackStatusReason
stack.StackStatusReason = statusReason
Expand All @@ -225,7 +216,7 @@ func InitiateTearDown(config models.Config) {
// In some cases cloud9 stacks can't be deleted due to security group being manually attached to other resources like elastic search or redis
// In such case it is better to wait for dependent resource's(mostly datastore or cache) stack and security group to get deleted and retry again
newDeleteAttempt := stack.DeleteAttempt + 1
fmt.Printf("Retrying deleting stack: %v Delete Attempt: %v/%v\n", sName, newDeleteAttempt, MAX_DELETE_RETRY_COUNT)
fmt.Printf("Retrying deleting stack: %v Delete Attempt: %v/%v\n", sName, newDeleteAttempt, config.MaxDeleteRetryCount)
err := cfn.DeleteStack(sName)
if err != nil {
UpdateNukeStats(dependencyTree)
Expand Down

0 comments on commit 0b15394

Please sign in to comment.