github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/modules/aws/acm.go (about)

     1  package aws
     2  
     3  import (
     4  	"github.com/aws/aws-sdk-go/service/acm"
     5  
     6  	"github.com/gruntwork-io/terratest/modules/testing"
     7  )
     8  
     9  // GetAcmCertificateArn gets the ACM certificate for the given domain name in the given region.
    10  func GetAcmCertificateArn(t testing.TestingT, awsRegion string, certDomainName string) string {
    11  	arn, err := GetAcmCertificateArnE(t, awsRegion, certDomainName)
    12  	if err != nil {
    13  		t.Fatal(err)
    14  	}
    15  	return arn
    16  }
    17  
    18  // GetAcmCertificateArnE gets the ACM certificate for the given domain name in the given region.
    19  func GetAcmCertificateArnE(t testing.TestingT, awsRegion string, certDomainName string) (string, error) {
    20  	acmClient, err := NewAcmClientE(t, awsRegion)
    21  	if err != nil {
    22  		return "", err
    23  	}
    24  
    25  	result, err := acmClient.ListCertificates(&acm.ListCertificatesInput{})
    26  	if err != nil {
    27  		return "", err
    28  	}
    29  
    30  	for _, summary := range result.CertificateSummaryList {
    31  		if *summary.DomainName == certDomainName {
    32  			return *summary.CertificateArn, nil
    33  		}
    34  	}
    35  
    36  	return "", nil
    37  }
    38  
    39  // NewAcmClient create a new ACM client.
    40  func NewAcmClient(t testing.TestingT, region string) *acm.ACM {
    41  	client, err := NewAcmClientE(t, region)
    42  	if err != nil {
    43  		t.Fatal(err)
    44  	}
    45  	return client
    46  }
    47  
    48  // NewAcmClientE creates a new ACM client.
    49  func NewAcmClientE(t testing.TestingT, awsRegion string) (*acm.ACM, error) {
    50  	sess, err := NewAuthenticatedSession(awsRegion)
    51  	if err != nil {
    52  		return nil, err
    53  	}
    54  
    55  	return acm.New(sess), nil
    56  }