浏览代码

Detect changeset creation failure when there's no changet

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 5 年之前
父节点
当前提交
e99a8b54f8
共有 1 个文件被更改,包括 12 次插入1 次删除
  1. 12 1
      ecs/sdk.go

+ 12 - 1
ecs/sdk.go

@@ -264,9 +264,20 @@ func (s sdk) CreateChangeSet(ctx context.Context, name string, template []byte)
 		return "", err
 	}
 
-	err = s.CF.WaitUntilChangeSetCreateCompleteWithContext(ctx, &cloudformation.DescribeChangeSetInput{
+	// we have to WaitUntilChangeSetCreateComplete even this in fail with error `ResourceNotReady`
+	// so that we can invoke DescribeChangeSet to check status, and then we can know about the actual creation failure cause.
+	s.CF.WaitUntilChangeSetCreateCompleteWithContext(ctx, &cloudformation.DescribeChangeSetInput{ // nolint:errcheck
 		ChangeSetName: changeset.Id,
 	})
+
+	desc, err := s.CF.DescribeChangeSetWithContext(ctx, &cloudformation.DescribeChangeSetInput{
+		ChangeSetName: aws.String(update),
+		StackName:     aws.String(name),
+	})
+	if aws.StringValue(desc.Status) == "FAILED" {
+		return *changeset.Id, fmt.Errorf(aws.StringValue(desc.StatusReason))
+	}
+
 	return *changeset.Id, err
 }