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

r/aws_route53_resolver_rule: Correct handling for single dot ('.') domain names #15015

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
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"
ewbankkit marked this conversation as resolved.
Show resolved Hide resolved

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