Skip to content

Commit

Permalink
r/aws_route53_resolver_rule: Correct handling for single dot ('.') do…
Browse files Browse the repository at this point in the history
…main name.
  • Loading branch information
ewbankkit committed Sep 3, 2020
1 parent c672984 commit a66506c
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 3 deletions.
67 changes: 67 additions & 0 deletions aws/resource_aws_route53_resolver_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,64 @@ func TestAccAwsRoute53ResolverRule_basic(t *testing.T) {
})
}

func TestAccAwsRoute53ResolverRule_justDotDomainName(t *testing.T) {
var rule route53resolver.ResolverRule
resourceName := "aws_route53_resolver_rule.example"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSRoute53Resolver(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRoute53ResolverRuleDestroy,
Steps: []resource.TestStep{
{
Config: testAccRoute53ResolverRuleConfig("."),
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53ResolverRuleExists(resourceName, &rule),
resource.TestCheckResourceAttr(resourceName, "domain_name", "."),
resource.TestCheckResourceAttr(resourceName, "rule_type", "SYSTEM"),
resource.TestCheckResourceAttr(resourceName, "share_status", "NOT_SHARED"),
testAccCheckResourceAttrAccountID(resourceName, "owner_id"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAwsRoute53ResolverRule_trailingDotDomainName(t *testing.T) {
var rule route53resolver.ResolverRule
resourceName := "aws_route53_resolver_rule.example"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSRoute53Resolver(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRoute53ResolverRuleDestroy,
Steps: []resource.TestStep{
{
Config: testAccRoute53ResolverRuleConfig("example.com."),
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53ResolverRuleExists(resourceName, &rule),
resource.TestCheckResourceAttr(resourceName, "domain_name", "example.com"),
resource.TestCheckResourceAttr(resourceName, "rule_type", "SYSTEM"),
resource.TestCheckResourceAttr(resourceName, "share_status", "NOT_SHARED"),
testAccCheckResourceAttrAccountID(resourceName, "owner_id"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAwsRoute53ResolverRule_tags(t *testing.T) {
var rule route53resolver.ResolverRule
resourceName := "aws_route53_resolver_rule.example"
Expand Down Expand Up @@ -389,6 +447,15 @@ func testAccCheckRoute53ResolverRuleExists(n string, rule *route53resolver.Resol
}
}

func testAccRoute53ResolverRuleConfig(domainName string) string {
return fmt.Sprintf(`
resource "aws_route53_resolver_rule" "example" {
domain_name = %[1]q
rule_type = "SYSTEM"
}
`, domainName)
}

const testAccRoute53ResolverRuleConfig_basicNoTags = `
resource "aws_route53_resolver_rule" "example" {
domain_name = "example.com"
Expand Down
10 changes: 8 additions & 2 deletions aws/resource_aws_route53_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,17 +397,23 @@ func cleanZoneID(ID string) string {

// trimTrailingPeriod is used to remove the trailing period
// of "name" or "domain name" attributes often returned from
// the Route53 API or provided as user input
// the Route53 API or provided as user input.
// The single dot (".") domain name is returned as-is.
func trimTrailingPeriod(v interface{}) string {
var str string
switch value := v.(type) {
case *string:
str = *value
str = aws.StringValue(value)
case string:
str = value
default:
return ""
}

if str == "." {
return str
}

return strings.TrimSuffix(str, ".")
}

Expand Down
10 changes: 9 additions & 1 deletion aws/resource_aws_route53_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,19 @@ func TestCleanChangeID(t *testing.T) {

func TestTrimTrailingPeriod(t *testing.T) {
cases := []struct {
Input, Output string
Input interface{}
Output string
}{
{"example.com", "example.com"},
{"example.com.", "example.com"},
{"www.example.com.", "www.example.com"},
{"", ""},
{".", "."},
{aws.String("example.com"), "example.com"},
{aws.String("example.com."), "example.com"},
{(*string)(nil), ""},
{42, ""},
{nil, ""},
}

for _, tc := range cases {
Expand Down

0 comments on commit a66506c

Please sign in to comment.