-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployment_group.go
89 lines (71 loc) · 2.51 KB
/
deployment_group.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
package awsspec
import (
iamSpec "github.com/9xb/awsspec/modules/iam"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/codedeploy"
)
// DeploymentGroupHasServiceRole returns true if the specified IAM role ARN is attached to the provided Deployment Group
func (c CodeDeploySpec) DeploymentGroupHasServiceRole(appName, id, role string) (res bool, err error) {
svc := getCodeDeployAPI(c.Session)
in := &codedeploy.GetDeploymentGroupInput{
ApplicationName: aws.String(appName),
DeploymentGroupName: aws.String(id),
}
out, err := svc.GetDeploymentGroup(in)
if err != nil {
return
}
if aws.StringValue(out.DeploymentGroupInfo.ServiceRoleArn) == role {
return true, nil
}
return
}
// DeploymentGroupHasDeploymentConfig returns true if the specified Deployment Configuration is associated to the provided Deployment Group
func (c CodeDeploySpec) DeploymentGroupHasDeploymentConfig(appName, id, config string) (res bool, err error) {
svc := getCodeDeployAPI(c.Session)
in := &codedeploy.GetDeploymentGroupInput{
ApplicationName: aws.String(appName),
DeploymentGroupName: aws.String(id),
}
out, err := svc.GetDeploymentGroup(in)
if err != nil {
return
}
if aws.StringValue(out.DeploymentGroupInfo.DeploymentConfigName) == config {
return true, nil
}
return
}
// DeploymentGroupHasAutoRollback returns true if the provided Deployment Group has auto-rollback enabled
func (c CodeDeploySpec) DeploymentGroupHasAutoRollback(appName, id string) (res bool, err error) {
svc := getCodeDeployAPI(c.Session)
in := &codedeploy.GetDeploymentGroupInput{
ApplicationName: aws.String(appName),
DeploymentGroupName: aws.String(id),
}
out, err := svc.GetDeploymentGroup(in)
if err != nil {
return
}
if aws.BoolValue(out.DeploymentGroupInfo.AutoRollbackConfiguration.Enabled) {
return true, nil
}
return
}
// DeploymentGroupHasAutoRollbackForEvents returns true if the provided Deployment Group is configured to auto-rollback for the specified events
func (c CodeDeploySpec) DeploymentGroupHasAutoRollbackForEvents(appName, id string, events []string) (res bool, err error) {
svc := getCodeDeployAPI(c.Session)
in := &codedeploy.GetDeploymentGroupInput{
ApplicationName: aws.String(appName),
DeploymentGroupName: aws.String(id),
}
out, err := svc.GetDeploymentGroup(in)
if err != nil {
return
}
o := iamSpec.OptSlice{}
for _, v := range aws.StringValueSlice(out.DeploymentGroupInfo.AutoRollbackConfiguration.Events) {
o = append(o, v)
}
return o.Contains(events), nil
}