Skip to content
This repository was archived by the owner on Sep 30, 2020. It is now read-only.

Commit 16a044b

Browse files
StackExists has changed behavoir it should not return an error if a stack does not exist. (#1535)
1 parent 78a7905 commit 16a044b

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

cfnstack/cfnstack.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,27 @@ func StackExists(cf CFInterrogator, stackName string) (bool, error) {
9898
logger.Debug("calling AWS cloudformation DescribeStacks ->")
9999
stacks, err := cf.DescribeStacks(req)
100100
if err != nil {
101+
if strings.HasPrefix(err.Error(), "ValidationError: Stack with id "+stackName+" does not exist") {
102+
return false, nil
103+
}
101104
return false, fmt.Errorf("could not list cloudformation stacks: %v", err)
102105
}
103106
if stacks == nil {
107+
logger.Debugf("<- AWS Responded with empty stacks object")
104108
return false, nil
105109
}
106-
logger.Debugf("<- AWS Responded with %d stacks", len(stacks.Stacks))
107-
for _, summary := range stacks.Stacks {
108-
if *summary.StackName == stackName {
109-
logger.Debugf("found matching stack %s: %+v", *summary.StackName, *summary)
110-
if summary.DeletionTime == nil {
111-
logger.Debugf("stack is active - matched!")
112-
return true, nil
113-
} else {
114-
logger.Debugf("stack is not active, ignoring")
110+
111+
if stacks.Stacks != nil {
112+
logger.Debugf("<- AWS Responded with %d stacks", len(stacks.Stacks))
113+
for _, summary := range stacks.Stacks {
114+
if *summary.StackName == stackName {
115+
logger.Debugf("found matching stack %s: %+v", *summary.StackName, *summary)
116+
if summary.DeletionTime == nil {
117+
logger.Debugf("stack is active - matched!")
118+
return true, nil
119+
} else {
120+
logger.Debugf("stack is not active, ignoring")
121+
}
115122
}
116123
}
117124
}

0 commit comments

Comments
 (0)