Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #7501 Unable to create api_gateway_domain using aws_route53_zone.name #7588

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion aws/resource_aws_api_gateway_domain_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"fmt"
"log"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -138,8 +139,11 @@ func resourceAwsApiGatewayDomainNameCreate(d *schema.ResourceData, meta interfac
conn := meta.(*AWSClient).apigateway
log.Printf("[DEBUG] Creating API Gateway Domain Name")

name := d.Get("domain_name").(string)
v := strings.TrimSuffix(name, ".")

params := &apigateway.CreateDomainNameInput{
DomainName: aws.String(d.Get("domain_name").(string)),
DomainName: aws.String(v),
}

if v, ok := d.GetOk("certificate_arn"); ok {
Expand Down
33 changes: 33 additions & 0 deletions aws/resource_aws_api_gateway_domain_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,39 @@ func TestAccAWSAPIGatewayDomainName_CertificateName(t *testing.T) {
})
}

func TestAccAWSAPIGatewayDomainName_verifyDomainName(t *testing.T) {
var conf apigateway.DomainName

rString := acctest.RandString(8)
name := fmt.Sprintf("tf-acc-%s.terraformtest.com", rString)
commonName := "*.terraformtest.com"
certRe := regexp.MustCompile("^-----BEGIN CERTIFICATE-----\n")
keyRe := regexp.MustCompile("^-----BEGIN RSA PRIVATE KEY-----\n")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProvidersWithTLS,
CheckDestroy: testAccCheckAWSAPIGatewayDomainNameDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSAPIGatewayDomainNameConfig_CertificateName(fmt.Sprintf("%s.", name), commonName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayDomainNameExists("aws_api_gateway_domain_name.test", &conf),
resource.TestMatchResourceAttr("aws_api_gateway_domain_name.test", "certificate_body", certRe),
resource.TestMatchResourceAttr("aws_api_gateway_domain_name.test", "certificate_chain", certRe),
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "certificate_name", "tf-acc-apigateway-domain-name"),
resource.TestMatchResourceAttr("aws_api_gateway_domain_name.test", "certificate_private_key", keyRe),
resource.TestCheckResourceAttrSet("aws_api_gateway_domain_name.test", "cloudfront_domain_name"),
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "cloudfront_zone_id", "Z2FDTNDATAQYW2"),
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "domain_name", name),
resource.TestCheckResourceAttrSet("aws_api_gateway_domain_name.test", "certificate_upload_date"),
),
ExpectNonEmptyPlan: true,
},
},
})
}

func TestAccAWSAPIGatewayDomainName_RegionalCertificateArn(t *testing.T) {
// For now, use an environment variable to limit running this test
regionalCertificateArn := os.Getenv("AWS_API_GATEWAY_DOMAIN_NAME_REGIONAL_CERTIFICATE_ARN")
Expand Down