github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/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 resource.TestCheckResourceAttrSet( 45 "aws_api_gateway_domain_name.test", "certificate_upload_date", 46 ), 47 ), 48 }, 49 }, 50 }) 51 } 52 53 func testAccCheckAWSAPIGatewayDomainNameExists(n string, res *apigateway.DomainName) resource.TestCheckFunc { 54 return func(s *terraform.State) error { 55 rs, ok := s.RootModule().Resources[n] 56 if !ok { 57 return fmt.Errorf("Not found: %s", n) 58 } 59 60 if rs.Primary.ID == "" { 61 return fmt.Errorf("No API Gateway DomainName ID is set") 62 } 63 64 conn := testAccProvider.Meta().(*AWSClient).apigateway 65 66 req := &apigateway.GetDomainNameInput{ 67 DomainName: aws.String(rs.Primary.ID), 68 } 69 describe, err := conn.GetDomainName(req) 70 if err != nil { 71 return err 72 } 73 74 if *describe.DomainName != rs.Primary.ID { 75 return fmt.Errorf("APIGateway DomainName not found") 76 } 77 78 *res = *describe 79 80 return nil 81 } 82 } 83 84 func testAccCheckAWSAPIGatewayDomainNameDestroy(s *terraform.State) error { 85 conn := testAccProvider.Meta().(*AWSClient).apigateway 86 87 for _, rs := range s.RootModule().Resources { 88 if rs.Type != "aws_api_gateway_api_key" { 89 continue 90 } 91 92 describe, err := conn.GetDomainNames(&apigateway.GetDomainNamesInput{}) 93 94 if err == nil { 95 if len(describe.Items) != 0 && 96 *describe.Items[0].DomainName == rs.Primary.ID { 97 return fmt.Errorf("API Gateway DomainName still exists") 98 } 99 } 100 101 aws2err, ok := err.(awserr.Error) 102 if !ok { 103 return err 104 } 105 if aws2err.Code() != "NotFoundException" { 106 return err 107 } 108 109 return nil 110 } 111 112 return nil 113 } 114 115 // Expires on August 20, 2026 116 const testAccAWSAPIGatewayCertBody = `-----BEGIN CERTIFICATE----- 117 MIIEfjCCA2agAwIBAgIRAPHiUbRWC/Ff/reiyzqh3wAwDQYJKoZIhvcNAQELBQAw 118 gcsxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNUGlyYXRlIEhh 119 cmJvcjEZMBcGA1UECRMQNTg3OSBDb3R0b24gTGluazETMBEGA1UEERMKOTU1NTkt 120 MTIyNzEVMBMGA1UEChMMRXhhbXBsZSwgSW5jMSgwJgYDVQQLEx9EZXBhcnRtZW50 121 IG9mIFRlcnJhZm9ybSB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xZo13EwgzTOmebDxm4W+Og4vBxsKS3x/L8D8BKdzBcmVJvggJqTs5Qau 138 ePetAQcD/Tfbq7vY9fNQJ4XQTlF5sN625miijTQcNg/s/H2Fj3FENR3UaFiQDtLQ 139 eatV0KGF/ik8XFHPbFm7XUZfUcDxvoaljglJfXyVttU956j892ZakvAHzhylFRyy 140 /wJnKV7K3zQVCEV0n/dJpXhf7w9PuWHrCp+HZJLMPMtm1IPblVxPNwHhGBG40I+Z 141 FSg= 142 -----END CERTIFICATE----- 143 ` 144 145 // Expires on August 20, 2026 146 const testAccAWSAPIGatewayCertChain = `-----BEGIN CERTIFICATE----- 147 MIIEoDCCA4igAwIBAgIQRR1EBw7bN+mMYtXrrvzLdzANBgkqhkiG9w0BAQsFADCB 148 yzELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1QaXJhdGUgSGFy 149 Ym9yMRkwFwYDVQQJExA1ODc5IENvdHRvbiBMaW5rMRMwEQYDVQQREwo5NTU1OS0x 150 MjI3MRUwEwYDVQQKEwxFeGFtcGxlLCBJbmMxKDAmBgNVBAsTH0RlcGFydG1lbnQg 151 b2YgVGVycmFmb3JtIFRlc3RpbmcxGjAYBgNVBAMTEXRmLWFjYy1jYS5pbnZhbGlk 152 MQowCAYDVQQFEwEyMB4XDTE2MDgyMjE2NDU1NloXDTI2MDgyMDE2NDU1Nlowgcsx 153 CzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNUGlyYXRlIEhhcmJv 154 cjEZMBcGA1UECRMQNTg3OSBDb3R0b24gTGluazETMBEGA1UEERMKOTU1NTktMTIy 155 NzEVMBMGA1UEChMMRXhhbXBsZSwgSW5jMSgwJgYDVQQLEx9EZXBhcnRtZW50IG9m 156 IFRlcnJhZm9ybSBUZXN0aW5nMRowGAYDVQQDExF0Zi1hY2MtY2EuaW52YWxpZDEK 157 MAgGA1UEBRMBMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK7k1xdX 158 HdA0HTajtSPvCwIeNE4HO3IsYn9jnUBvhQ52EJ72GPzlg91AhdVufIncJRjk51iP 159 n86TO/bg/dx4d+G45aUFw7WmZGTTZjurhnVWCDPeeetItV3PmsWHkwTiBj4GJYW4 160 1mJk0ACjmmGEyz24T46Cn87Tljk+ivdCQL/oYTjpC7jc2i5b7ziiwsToWMEljWV1 161 cf/4qQNFmFnETbaQW2qcFdjUoO8N1gRNkC9yvOjo6Fc+lETRHn3e926jDSaqfbwJ 162 hKKBoXciYnddNXgA83GBTdnsRiRoD4zFEhNThmgvy5MmkEEdwKl5QIz6ajo4Xxtd 163 54XZpt0y/ZVy6BECAwEAAaN+MHwwDgYDVR0PAQH/BAQDAgIEMBkGA1UdJQQSMBAG 164 CCsGAQUFBwMBBgRVHSUAMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFP4VkPlF 165 IexIi3dHwrIMtY70oMZLMB8GA1UdIwQYMBaAFP4VkPlFIexIi3dHwrIMtY70oMZL 166 MA0GCSqGSIb3DQEBCwUAA4IBAQBlXSOkvE/c8pcI6vijInnAWY+eX2W7njCzEfmP 167 gkDeW/2A1/6eSM6C/ym+9zEgZ9YLxPfiQKzN8Ej+EziFiZW3ZBHnWcW9rZt36wFA 168 swF2nIqWa5nkVnAX2aPVfULN1u1BQiv3XZqNNlBk6m9AsgxiZ9jtOY8oQQU3uDYe 169 bs9ttLMKJApbe08sKmPawVlXHqj6qb85Pg4bzzknA+euRee9KIi87eTlWc/Ht+WN 170 Huh16WqokePii7e/PAaiTAe7ubsPav29lzmHq2NooXrs+FljXveQJpBqu6wKKTXe 171 6/5BBsp2474RiZgTbuO2Mbr2nwcoJ9V6iu1M9siCGbbt1nQr 172 -----END CERTIFICATE----- 173 ` 174 175 const testAccAWSAPIGatewayCertPrivateKey = `-----BEGIN RSA PRIVATE KEY----- 176 MIIEpAIBAAKCAQEAv/FM+jPe2e+QuO2GqwwrBZW0TXKLbXRSex4FiRzbDqJ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cgucFRiB 193 PPJ5DDCkIhmgYYWA7R7CvEB/OxyppvFj+RtYMYqNg8xWRH1DA7rhOw/5x4ZB8lGc 194 cRbrZbBp033YdkdV3r9IAoz5aoNgoaSq+Yk0KIeU2FYqRXl2FltqYL+aQgJmjR5Z 195 fxz8Xvy9qtlfuWcDM/e24QKBgQDGtH8mk+lCfUkfRuh4UJCaHnGSif5grS2R9ZZA 196 n18rpbThd9qS6reXYgUm/5Hs8KRBzqX5cS4qY4rlw2XRIPMxfU6lWbFh96KToPFx 197 MD1+L5JxpbRFpGnsYvYdCmHxy03r03wojRAcH7JU6o9U7j936hDTLjqmq7LRhid5 198 goFwlQKBgQCGxTWqQu9FJjtmjdM/ARi7CcwWT40NI8ybyebjDtElekILFMUwO+/w 199 M78Me3d5g/oyeS6qCfyK1f7vBb/WhxLBBegaqMGUWbRoKYD0LH5U3zkqZ9ehnDFB 200 vhcEnoxPD9HmdFkRduJscyzVNJ50lMuQ3uk7zwiYuS/Z7shH81xzMQ== 201 -----END RSA PRIVATE KEY----- 202 ` 203 204 func testAccAWSAPIGatewayDomainNameConfigCreate(name string) string { 205 return fmt.Sprintf(` 206 resource "aws_api_gateway_domain_name" "test" { 207 domain_name = "%s" 208 certificate_body = "%v" 209 certificate_chain = "%v" 210 certificate_name = "tf-acc-apigateway-domain-name" 211 certificate_private_key = "%v" 212 } 213 `, name, testAccAWSAPIGatewayCertBody, testAccAWSAPIGatewayCertChain, testAccAWSAPIGatewayCertPrivateKey) 214 }