github.com/mehmetalisavas/terraform@v0.7.10/builtin/providers/aws/data_source_aws_acm_certificate_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"testing"
     7  
     8  	"github.com/hashicorp/terraform/helper/resource"
     9  	"github.com/hashicorp/terraform/terraform"
    10  )
    11  
    12  func TestAccAwsAcmCertificateDataSource_basic(t *testing.T) {
    13  	region := os.Getenv("AWS_ACM_TEST_REGION")
    14  	domain := os.Getenv("AWS_ACM_TEST_DOMAIN")
    15  	certArn := os.Getenv("AWS_ACM_TEST_CERT_ARN")
    16  	resource.Test(t, resource.TestCase{
    17  		PreCheck: func() {
    18  			testAccPreCheck(t)
    19  			if region == "" {
    20  				t.Skip("AWS_ACM_TEST_REGION must be set to a region an ACM certificate pre-created for this test.")
    21  			}
    22  			if domain == "" {
    23  				t.Skip("AWS_ACM_TEST_DOMAIN must be set to a domain with an ACM certificate pre-created for this test.")
    24  			}
    25  			if certArn == "" {
    26  				t.Skip("AWS_ACM_TEST_CERT_ARN must be set to the ARN of an ACM cert pre-created for this test.")
    27  			}
    28  		},
    29  		Providers: testAccProviders,
    30  		Steps: []resource.TestStep{
    31  			{
    32  				Config: testAccCheckAwsAcmCertificateDataSourceConfig(region, domain),
    33  				Check:  testAccCheckAcmArnMatches("data.aws_acm_certificate.test", certArn),
    34  			},
    35  		},
    36  	})
    37  }
    38  
    39  func testAccCheckAcmArnMatches(name, expectArn string) resource.TestCheckFunc {
    40  	return func(s *terraform.State) error {
    41  		ms := s.RootModule()
    42  		rs, ok := ms.Resources[name]
    43  		if !ok {
    44  			return fmt.Errorf("Not found: %s", name)
    45  		}
    46  		gotArn := rs.Primary.Attributes["arn"]
    47  		if gotArn != expectArn {
    48  			return fmt.Errorf("Expected cert to have arn: %s, got: %s", expectArn, gotArn)
    49  		}
    50  		return nil
    51  	}
    52  }
    53  
    54  func testAccCheckAwsAcmCertificateDataSourceConfig(region, domain string) string {
    55  	return fmt.Sprintf(`
    56  provider "aws" {
    57  	region = "%s"
    58  }
    59  data "aws_acm_certificate" "test" {
    60  	domain = "%s"
    61  }
    62  	`, region, domain)
    63  }