forked from gruntwork-io/terratest
-
Notifications
You must be signed in to change notification settings - Fork 1
/
acm.go
56 lines (46 loc) · 1.33 KB
/
acm.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
package aws
import (
"testing"
"github.com/aws/aws-sdk-go/service/acm"
)
// GetAcmCertificateArn gets the ACM certificate for the given domain name in the given region.
func GetAcmCertificateArn(t *testing.T, awsRegion string, certDomainName string) string {
arn, err := GetAcmCertificateArnE(t, awsRegion, certDomainName)
if err != nil {
t.Fatal(err)
}
return arn
}
// GetAcmCertificateArnE gets the ACM certificate for the given domain name in the given region.
func GetAcmCertificateArnE(t *testing.T, awsRegion string, certDomainName string) (string, error) {
acmClient, err := NewAcmClientE(t, awsRegion)
if err != nil {
return "", err
}
result, err := acmClient.ListCertificates(&acm.ListCertificatesInput{})
if err != nil {
return "", err
}
for _, summary := range result.CertificateSummaryList {
if *summary.DomainName == certDomainName {
return *summary.CertificateArn, nil
}
}
return "", nil
}
// NewAcmClient create a new ACM client.
func NewAcmClient(t *testing.T, region string) *acm.ACM {
client, err := NewAcmClientE(t, region)
if err != nil {
t.Fatal(err)
}
return client
}
// NewAcmClientE creates a new ACM client.
func NewAcmClientE(t *testing.T, awsRegion string) (*acm.ACM, error) {
sess, err := NewAuthenticatedSession(awsRegion)
if err != nil {
return nil, err
}
return acm.New(sess), nil
}