github.com/mohanarpit/terraform@v0.6.16-0.20160909104007-291f29853544/builtin/providers/aws/resource_aws_api_gateway_domain_name_test.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/aws/aws-sdk-go/aws" 8 "github.com/aws/aws-sdk-go/aws/awserr" 9 "github.com/aws/aws-sdk-go/service/apigateway" 10 "github.com/hashicorp/terraform/helper/resource" 11 "github.com/hashicorp/terraform/terraform" 12 ) 13 14 func TestAccAWSAPIGatewayDomainName_basic(t *testing.T) { 15 var conf apigateway.DomainName 16 17 // Our test cert is for a wildcard on this domain 18 name := fmt.Sprintf("%s.tf-acc.invalid", resource.UniqueId()) 19 20 resource.Test(t, resource.TestCase{ 21 PreCheck: func() { testAccPreCheck(t) }, 22 Providers: testAccProviders, 23 CheckDestroy: testAccCheckAWSAPIGatewayDomainNameDestroy, 24 Steps: []resource.TestStep{ 25 resource.TestStep{ 26 Config: testAccAWSAPIGatewayDomainNameConfigCreate(name), 27 Check: resource.ComposeTestCheckFunc( 28 testAccCheckAWSAPIGatewayDomainNameExists("aws_api_gateway_domain_name.test", &conf), 29 resource.TestCheckResourceAttr( 30 "aws_api_gateway_domain_name.test", "certificate_body", testAccAWSAPIGatewayCertBody, 31 ), 32 resource.TestCheckResourceAttr( 33 "aws_api_gateway_domain_name.test", "certificate_chain", testAccAWSAPIGatewayCertChain, 34 ), 35 resource.TestCheckResourceAttr( 36 "aws_api_gateway_domain_name.test", "certificate_name", "tf-acc-apigateway-domain-name", 37 ), 38 resource.TestCheckResourceAttr( 39 "aws_api_gateway_domain_name.test", "certificate_private_key", testAccAWSAPIGatewayCertPrivateKey, 40 ), 41 resource.TestCheckResourceAttr( 42 "aws_api_gateway_domain_name.test", "domain_name", name, 43 ), 44 ), 45 }, 46 }, 47 }) 48 } 49 50 func testAccCheckAWSAPIGatewayDomainNameExists(n string, res *apigateway.DomainName) resource.TestCheckFunc { 51 return func(s *terraform.State) error { 52 rs, ok := s.RootModule().Resources[n] 53 if !ok { 54 return fmt.Errorf("Not found: %s", n) 55 } 56 57 if rs.Primary.ID == "" { 58 return fmt.Errorf("No API Gateway DomainName ID is set") 59 } 60 61 conn := testAccProvider.Meta().(*AWSClient).apigateway 62 63 req := &apigateway.GetDomainNameInput{ 64 DomainName: aws.String(rs.Primary.ID), 65 } 66 describe, err := conn.GetDomainName(req) 67 if err != nil { 68 return err 69 } 70 71 if *describe.DomainName != rs.Primary.ID { 72 return fmt.Errorf("APIGateway DomainName not found") 73 } 74 75 *res = *describe 76 77 return nil 78 } 79 } 80 81 func testAccCheckAWSAPIGatewayDomainNameDestroy(s *terraform.State) error { 82 conn := testAccProvider.Meta().(*AWSClient).apigateway 83 84 for _, rs := range s.RootModule().Resources { 85 if rs.Type != "aws_api_gateway_api_key" { 86 continue 87 } 88 89 describe, err := conn.GetDomainNames(&apigateway.GetDomainNamesInput{}) 90 91 if err == nil { 92 if len(describe.Items) != 0 && 93 *describe.Items[0].DomainName == rs.Primary.ID { 94 return fmt.Errorf("API Gateway DomainName still exists") 95 } 96 } 97 98 aws2err, ok := err.(awserr.Error) 99 if !ok { 100 return err 101 } 102 if aws2err.Code() != "NotFoundException" { 103 return err 104 } 105 106 return nil 107 } 108 109 return nil 110 } 111 112 // Expires on August 20, 2026 113 const testAccAWSAPIGatewayCertBody = `-----BEGIN CERTIFICATE----- 114 MIIEfjCCA2agAwIBAgIRAPHiUbRWC/Ff/reiyzqh3wAwDQYJKoZIhvcNAQELBQAw 115 gcsxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNUGlyYXRlIEhh 116 cmJvcjEZMBcGA1UECRMQNTg3OSBDb3R0b24gTGluazETMBEGA1UEERMKOTU1NTkt 117 MTIyNzEVMBMGA1UEChMMRXhhbXBsZSwgSW5jMSgwJgYDVQQLEx9EZXBhcnRtZW50 118 IG9mIFRlcnJhZm9ybSBUZXN0aW5nMRowGAYDVQQDExF0Zi1hY2MtY2EuaW52YWxp 119 ZDEKMAgGA1U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etAQcD/Tfbq7vY9fNQJ4XQTlF5sN625miijTQcNg/s/H2Fj3FENR3UaFiQDtLQ 136 eatV0KGF/ik8XFHPbFm7XUZfUcDxvoaljglJfXyVttU956j892ZakvAHzhylFRyy 137 /wJnKV7K3zQVCEV0n/dJpXhf7w9PuWHrCp+HZJLMPMtm1IPblVxPNwHhGBG40I+Z 138 FSg= 139 -----END CERTIFICATE----- 140 ` 141 142 // Expires on August 20, 2026 143 const testAccAWSAPIGatewayCertChain = `-----BEGIN CERTIFICATE----- 144 MIIEoDCCA4igAwIBAgIQRR1EBw7bN+mMYtXrrvzLdzANBgkqhkiG9w0BAQsFADCB 145 yzELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1QaXJhdGUgSGFy 146 Ym9yMRkwFwYDVQQJExA1ODc5IENvdHRvbiBMaW5rMRMwEQYDVQQREwo5NTU1OS0x 147 MjI3MRUwEwYDVQQKEwxFeGFtcGxlLCBJbmMxKDAmBgNVBAsTH0RlcGFydG1lbnQg 148 b2YgVGVycmFmb3JtIFRlc3RpbmcxGjAYBgNVBAMTEXRmLWFjYy1jYS5pbnZhbGlk 149 MQowCAYDVQQFEwEyMB4XDTE2MDgyMjE2NDU1NloXDTI2MDgyMDE2NDU1Nlowgcsx 150 CzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNUGlyYXRlIEhhcmJv 151 cjEZMBcGA1UECRMQNTg3OSBDb3R0b24gTGluazETMBEGA1UEERMKOTU1NTktMTIy 152 NzEVMBMGA1UEChMMRXhhbXBsZSwgSW5jMSgwJgYDVQQLEx9EZXBhcnRtZW50IG9m 153 IFRlcnJhZm9ybSBUZXN0aW5nMRowGAYDVQQDExF0Zi1hY2MtY2EuaW52YWxpZDEK 154 MAgGA1UEBRMBMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK7k1xdX 155 HdA0HTajtSPvCwIeNE4HO3IsYn9jnUBvhQ52EJ72GPzlg91AhdVufIncJRjk51iP 156 n86TO/bg/dx4d+G45aUFw7WmZGTTZjurhnVWCDPeeetItV3PmsWHkwTiBj4GJYW4 157 1mJk0ACjmmGEyz24T46Cn87Tljk+ivdCQL/oYTjpC7jc2i5b7ziiwsToWMEljWV1 158 cf/4qQNFmFnETbaQW2qcFdjUoO8N1gRNkC9yvOjo6Fc+lETRHn3e926jDSaqfbwJ 159 hKKBoXciYnddNXgA83GBTdnsRiRoD4zFEhNThmgvy5MmkEEdwKl5QIz6ajo4Xxtd 160 54XZpt0y/ZVy6BECAwEAAaN+MHwwDgYDVR0PAQH/BAQDAgIEMBkGA1UdJQQSMBAG 161 CCsGAQUFBwMBBgRVHSUAMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFP4VkPlF 162 IexIi3dHwrIMtY70oMZLMB8GA1UdIwQYMBaAFP4VkPlFIexIi3dHwrIMtY70oMZL 163 MA0GCSqGSIb3DQEBCwUAA4IBAQBlXSOkvE/c8pcI6vijInnAWY+eX2W7njCzEfmP 164 gkDeW/2A1/6eSM6C/ym+9zEgZ9YLxPfiQKzN8Ej+EziFiZW3ZBHnWcW9rZt36wFA 165 swF2nIqWa5nkVnAX2aPVfULN1u1BQiv3XZqNNlBk6m9AsgxiZ9jtOY8oQQU3uDYe 166 bs9ttLMKJApbe08sKmPawVlXHqj6qb85Pg4bzzknA+euRee9KIi87eTlWc/Ht+WN 167 Huh16WqokePii7e/PAaiTAe7ubsPav29lzmHq2NooXrs+FljXveQJpBqu6wKKTXe 168 6/5BBsp2474RiZgTbuO2Mbr2nwcoJ9V6iu1M9siCGbbt1nQr 169 -----END CERTIFICATE----- 170 ` 171 172 const testAccAWSAPIGatewayCertPrivateKey = `-----BEGIN RSA PRIVATE KEY----- 173 MIIEpAIBAAKCAQEAv/FM+jPe2e+QuO2GqwwrBZW0TXKLbXRSex4FiRzbDqJBRcwK 174 xeTDY9ldbpAhbujUY2OesTn2OR4QnYAERjKiv6iho1maMnR29jW0V6syG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A7rhOw/5x4ZB8lGc 191 cRbrZbBp033YdkdV3r9IAoz5aoNgoaSq+Yk0KIeU2FYqRXl2FltqYL+aQgJmjR5Z 192 fxz8Xvy9qtlfuWcDM/e24QKBgQDGtH8mk+lCfUkfRuh4UJCaHnGSif5grS2R9ZZA 193 n18rpbThd9qS6reXYgUm/5Hs8KRBzqX5cS4qY4rlw2XRIPMxfU6lWbFh96KToPFx 194 MD1+L5JxpbRFpGnsYvYdCmHxy03r03wojRAcH7JU6o9U7j936hDTLjqmq7LRhid5 195 goFwlQKBgQCGxTWqQu9FJjtmjdM/ARi7CcwWT40NI8ybyebjDtElekILFMUwO+/w 196 M78Me3d5g/oyeS6qCfyK1f7vBb/WhxLBBegaqMGUWbRoKYD0LH5U3zkqZ9ehnDFB 197 vhcEnoxPD9HmdFkRduJscyzVNJ50lMuQ3uk7zwiYuS/Z7shH81xzMQ== 198 -----END RSA PRIVATE KEY----- 199 ` 200 201 func testAccAWSAPIGatewayDomainNameConfigCreate(name string) string { 202 return fmt.Sprintf(` 203 resource "aws_api_gateway_domain_name" "test" { 204 domain_name = "%s" 205 certificate_body = "%v" 206 certificate_chain = "%v" 207 certificate_name = "tf-acc-apigateway-domain-name" 208 certificate_private_key = "%v" 209 } 210 `, name, testAccAWSAPIGatewayCertBody, testAccAWSAPIGatewayCertChain, testAccAWSAPIGatewayCertPrivateKey) 211 }