This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
changeset.go
99 lines (81 loc) · 2.87 KB
/
changeset.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0
package types
import (
"strings"
sdktypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types"
)
// ChangeSetDescription is the output of the DescribeChangeSet action.
type ChangeSetDescription struct {
Arn string
Status sdktypes.ChangeSetStatus
ExecutionStatus sdktypes.ExecutionStatus
StatusReason string
Changes []sdktypes.Change
}
const (
// Status reasons that can occur if the change set execution status is "FAILED".
noChangesReason = "NO_CHANGES_REASON"
noUpdatesReason = "NO_UPDATES_REASON"
)
var (
inProgressChangeSetStatuses = []sdktypes.ChangeSetStatus{
sdktypes.ChangeSetStatusCreateInProgress,
sdktypes.ChangeSetStatusCreatePending,
sdktypes.ChangeSetStatusDeleteInProgress,
sdktypes.ChangeSetStatusDeletePending,
}
failedChangeSetStatuses = []sdktypes.ChangeSetStatus{
sdktypes.ChangeSetStatusDeleteFailed,
sdktypes.ChangeSetStatusFailed,
}
inProgressChangeSetExecutionStatuses = []sdktypes.ExecutionStatus{
sdktypes.ExecutionStatusExecuteInProgress,
sdktypes.ExecutionStatusUnavailable,
}
failedChangeSetExecutionStatuses = []sdktypes.ExecutionStatus{
sdktypes.ExecutionStatusExecuteFailed,
sdktypes.ExecutionStatusObsolete,
}
)
func (d *ChangeSetDescription) IsEmpty() bool {
return (len(d.Changes) == 0 && strings.Contains(d.StatusReason, "didn't contain changes")) ||
d.StatusReason == noChangesReason ||
d.StatusReason == noUpdatesReason
}
func (d *ChangeSetDescription) IsDeleted() bool {
return d.Status == sdktypes.ChangeSetStatusDeleteComplete
}
func (d *ChangeSetDescription) IsCreated() bool {
return d.Status == sdktypes.ChangeSetStatusCreateComplete
}
func (d *ChangeSetDescription) InProgress() bool {
return changesetStatusListContains(d.Status, inProgressChangeSetStatuses) ||
changesetExecutionStatusListContains(d.ExecutionStatus, inProgressChangeSetExecutionStatuses)
}
func (d *ChangeSetDescription) IsFailed() bool {
return changesetStatusListContains(d.Status, failedChangeSetStatuses) ||
changesetExecutionStatusListContains(d.ExecutionStatus, failedChangeSetExecutionStatuses)
}
func (d *ChangeSetDescription) IsSuccess() bool {
return d.IsCreated() && d.ExecutionStatus == sdktypes.ExecutionStatusExecuteComplete
}
func (d *ChangeSetDescription) ReadyForExecution() bool {
return d.IsCreated() && d.ExecutionStatus == sdktypes.ExecutionStatusAvailable
}
func changesetStatusListContains(element sdktypes.ChangeSetStatus, statusList []sdktypes.ChangeSetStatus) bool {
for _, status := range statusList {
if element == status {
return true
}
}
return false
}
func changesetExecutionStatusListContains(element sdktypes.ExecutionStatus, statusList []sdktypes.ExecutionStatus) bool {
for _, status := range statusList {
if element == status {
return true
}
}
return false
}