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

resource/aws_ses_domain_identity: Support trailing period in domain name #3840

Merged
merged 1 commit into from
Mar 20, 2018
Merged
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
5 changes: 5 additions & 0 deletions aws/resource_aws_ses_domain_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"fmt"
"log"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ses"
Expand All @@ -27,6 +28,9 @@ func resourceAwsSesDomainIdentity() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
StateFunc: func(v interface{}) string {
return strings.TrimSuffix(v.(string), ".")
},
},
"verification_token": {
Type: schema.TypeString,
Expand All @@ -40,6 +44,7 @@ func resourceAwsSesDomainIdentityCreate(d *schema.ResourceData, meta interface{}
conn := meta.(*AWSClient).sesConn

domainName := d.Get("domain").(string)
domainName = strings.TrimSuffix(domainName, ".")

createOpts := &ses.VerifyDomainIdentityInput{
Domain: aws.String(domainName),
Expand Down
51 changes: 38 additions & 13 deletions aws/resource_aws_ses_domain_identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package aws

import (
"fmt"
"strings"
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/ses"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
Expand All @@ -17,14 +19,33 @@ func TestAccAWSSESDomainIdentity_basic(t *testing.T) {
acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsSESDomainIdentityDestroy,
Steps: []resource.TestStep{
{
Config: testAccAwsSESDomainIdentityConfig(domain),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsSESDomainIdentityExists("aws_ses_domain_identity.test"),
testAccCheckAwsSESDomainIdentityArn("aws_ses_domain_identity.test", domain),
),
},
},
})
}

func TestAccAWSSESDomainIdentity_trailingPeriod(t *testing.T) {
domain := fmt.Sprintf(
"%s.terraformtesting.com.",
acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsSESDomainIdentityDestroy,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(testAccAwsSESDomainIdentityConfig, domain),
Config: testAccAwsSESDomainIdentityConfig(domain),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsSESDomainIdentityExists("aws_ses_domain_identity.test"),
testAccCheckAwsSESDomainIdentityArn("aws_ses_domain_identity.test", domain),
Expand Down Expand Up @@ -98,24 +119,28 @@ func testAccCheckAwsSESDomainIdentityExists(n string) resource.TestCheckFunc {
func testAccCheckAwsSESDomainIdentityArn(n string, domain string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, _ := s.RootModule().Resources[n]
awsClient := testAccProvider.Meta().(*AWSClient)

expected := arn.ARN{
AccountID: awsClient.accountid,
Partition: awsClient.partition,
Region: awsClient.region,
Resource: fmt.Sprintf("identity/%s", strings.TrimSuffix(domain, ".")),
Service: "ses",
}

expected := fmt.Sprintf(
"arn:%s:ses:%s:%s:identity/%s",
testAccProvider.Meta().(*AWSClient).partition,
testAccProvider.Meta().(*AWSClient).region,
testAccProvider.Meta().(*AWSClient).accountid,
domain)

if rs.Primary.Attributes["arn"] != expected {
if rs.Primary.Attributes["arn"] != expected.String() {
return fmt.Errorf("Incorrect ARN: expected %q, got %q", expected, rs.Primary.Attributes["arn"])
}

return nil
}
}

const testAccAwsSESDomainIdentityConfig = `
func testAccAwsSESDomainIdentityConfig(domain string) string {
return fmt.Sprintf(`
resource "aws_ses_domain_identity" "test" {
domain = "%s"
}
`
`, domain)
}