Skip to content

Commit

Permalink
r/aws_route53domains_domain: Initial tests, update docs, fix to alway…
Browse files Browse the repository at this point in the history
…s use us-eas-t1
  • Loading branch information
gazoakley committed Apr 26, 2020
1 parent 0a5e4f7 commit 28fdd45
Show file tree
Hide file tree
Showing 4 changed files with 341 additions and 28 deletions.
7 changes: 6 additions & 1 deletion aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,6 @@ func (c *Config) Client() (interface{}, error) {
redshiftconn: redshift.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["redshift"])})),
region: c.Region,
resourcegroupsconn: resourcegroups.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["resourcegroups"])})),
route53domainsconn: route53domains.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["route53domains"])})),
route53resolverconn: route53resolver.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["route53resolver"])})),
s3controlconn: s3control.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["s3control"])})),
sagemakerconn: sagemaker.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["sagemaker"])})),
Expand Down Expand Up @@ -550,6 +549,9 @@ func (c *Config) Client() (interface{}, error) {
route53Config := &aws.Config{
Endpoint: aws.String(c.Endpoints["route53"]),
}
route53DomainsConfig := &aws.Config{
Endpoint: aws.String(c.Endpoints["route53domains"]),
}
shieldConfig := &aws.Config{
Endpoint: aws.String(c.Endpoints["shield"]),
}
Expand Down Expand Up @@ -578,6 +580,7 @@ func (c *Config) Client() (interface{}, error) {
case endpoints.AwsPartitionID:
globalAcceleratorConfig.Region = aws.String(endpoints.UsWest2RegionID)
route53Config.Region = aws.String(endpoints.UsEast1RegionID)
route53DomainsConfig.Region = aws.String(endpoints.UsEast1RegionID)
shieldConfig.Region = aws.String(endpoints.UsEast1RegionID)
case endpoints.AwsCnPartitionID:
// The AWS Go SDK is missing endpoint information for Route 53 in the AWS China partition.
Expand All @@ -592,6 +595,8 @@ func (c *Config) Client() (interface{}, error) {

client.globalacceleratorconn = globalaccelerator.New(sess.Copy(globalAcceleratorConfig))
client.r53conn = route53.New(sess.Copy(route53Config))
client.route53domainsconn = route53domains.New(sess.Copy(route53DomainsConfig))

client.shieldconn = shield.New(sess.Copy(shieldConfig))

// Workaround for https://github.com/aws/aws-sdk-go/issues/1472
Expand Down
13 changes: 6 additions & 7 deletions aws/resource_aws_route53domains_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func resourceAwsRoute53DomainsDomainContactDetail() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"address_line_1": {
Expand Down Expand Up @@ -214,12 +213,14 @@ func resourceAwsRoute53DomainsDomain() *schema.Resource {
func resourceAwsRoute53DomainsDomainCreate(d *schema.ResourceData, meta interface{}) error {
domainName := d.Get("domain_name").(string)
d.SetId(domainName)
return resourceAwsRoute53DomainsDomainRead(d, meta)
return resourceAwsRoute53DomainsDomainUpdate(d, meta)
}

func resourceAwsRoute53DomainsDomainRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).route53domainsconn

d.Set("domain_name", d.Id())

log.Printf("[DEBUG] Get domain details for Route 53 Domain: %s", d.Id())
out, err := conn.GetDomainDetail(&route53domains.GetDomainDetailInput{
DomainName: aws.String(d.Id()),
Expand All @@ -240,16 +241,16 @@ func resourceAwsRoute53DomainsDomainRead(d *schema.ResourceData, meta interface{
d.Set("admin_contact", resourceAwsRoute53DomainsDomainFlattenContactDetail(out.AdminContact))
d.Set("admin_privacy", out.AdminPrivacy)
d.Set("auto_renew", out.AutoRenew)
d.Set("creation_date", out.CreationDate)
d.Set("expiration_date", out.ExpirationDate)
d.Set("creation_date", out.CreationDate.String())
d.Set("expiration_date", out.ExpirationDate.String())
d.Set("name_servers", resourceAwsRoute53DomainsDomainFlattenNameservers(out.Nameservers))
d.Set("registrant_contact", resourceAwsRoute53DomainsDomainFlattenContactDetail(out.RegistrantContact))
d.Set("registrant_privacy", out.RegistrantPrivacy)
d.Set("registrar_name", out.RegistrarName)
d.Set("registrar_url", out.RegistrarUrl)
d.Set("tech_contact", resourceAwsRoute53DomainsDomainFlattenContactDetail(out.TechContact))
d.Set("tech_privacy", out.TechPrivacy)
d.Set("updated_date", out.UpdatedDate)
// d.Set("updated_date", out.UpdatedDate.String())
d.Set("whois_server", out.WhoIsServer)

if err := d.Set("status_list", flattenStringList(out.StatusList)); err != nil {
Expand Down Expand Up @@ -423,8 +424,6 @@ func resourceAwsRoute53DomainsDomainUpdate(d *schema.ResourceData, meta interfac
}
}

// Changes to domain contact

// Changes to domain contact privacy
if d.HasChange("admin_privacy") || d.HasChange("registrant_privacy") || d.HasChange("tech_privacy") {
log.Printf("[DEBUG] Updating domain contact privacy settings for Route 53 domain (%s)", d.Id())
Expand Down
307 changes: 307 additions & 0 deletions aws/resource_aws_route53domains_domain_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,307 @@
package aws

import (
"fmt"
"os"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccAWSRoute53DomainsDomain_Basic(t *testing.T) {
domainName := os.Getenv("ROUTE53DOMAINS_DOMAIN")
if domainName == "" {
t.Skip("Environment variable ROUTE53DOMAINS_DOMAIN is not set")
}

resourceName := "aws_route53domains_domain.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccRoute53DomainsDomainConfig_Basic(domainName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "domain_name", domainName),
resource.TestMatchResourceAttr(resourceName, "name_servers.#", regexp.MustCompile(`^\d+$`)),
resource.TestMatchResourceAttr(resourceName, "tags.%", regexp.MustCompile(`^\d+$`)),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSRoute53DomainsDomain_Tags(t *testing.T) {
domainName := os.Getenv("ROUTE53DOMAINS_DOMAIN")
if domainName == "" {
t.Skip("Environment variable ROUTE53DOMAINS_DOMAIN is not set")
}

resourceName := "aws_route53domains_domain.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccRoute53DomainsDomainConfig_TagsSingle(domainName, "tag1key", "tag1value"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.tag1key", "tag1value"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccRoute53DomainsDomainConfig_TagsMultiple(domainName, "tag1key", "tag1valueupdated", "tag2key", "tag2value"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(resourceName, "tags.tag1key", "tag1valueupdated"),
resource.TestCheckResourceAttr(resourceName, "tags.tag2key", "tag2value"),
),
},
{
Config: testAccRoute53DomainsDomainConfig_TagsSingle(domainName, "tag2key", "tag2value"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.tag2key", "tag2value"),
),
},
},
})
}

func TestAccAWSRoute53DomainsDomain_AutoRenew(t *testing.T) {
domainName := os.Getenv("ROUTE53DOMAINS_DOMAIN")
if domainName == "" {
t.Skip("Environment variable ROUTE53DOMAINS_DOMAIN is not set")
}

resourceName := "aws_route53domains_domain.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccRoute53DomainsDomainConfig_AutoRenew(domainName, "false"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "auto_renew", "false"),
),
},
{
Config: testAccRoute53DomainsDomainConfig_AutoRenew(domainName, "true"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "auto_renew", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSRoute53DomainsDomain_TransferLock(t *testing.T) {
domainName := os.Getenv("ROUTE53DOMAINS_DOMAIN")
if domainName == "" {
t.Skip("Environment variable ROUTE53DOMAINS_DOMAIN is not set")
}

resourceName := "aws_route53domains_domain.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccRoute53DomainsDomainConfig_TransferLock(domainName, "false"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "transfer_lock", "false"),
),
},
{
Config: testAccRoute53DomainsDomainConfig_TransferLock(domainName, "true"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "transfer_lock", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSRoute53DomainsDomain_Privacy(t *testing.T) {
domainName := os.Getenv("ROUTE53DOMAINS_DOMAIN")
if domainName == "" {
t.Skip("Environment variable ROUTE53DOMAINS_DOMAIN is not set")
}

resourceName := "aws_route53domains_domain.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccRoute53DomainsDomainConfig_Privacy(domainName, true, false, false),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "admin_privacy", "true"),
resource.TestCheckResourceAttr(resourceName, "registrant_privacy", "false"),
resource.TestCheckResourceAttr(resourceName, "tech_privacy", "false"),
),
},
{
Config: testAccRoute53DomainsDomainConfig_Privacy(domainName, false, true, false),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "admin_privacy", "false"),
resource.TestCheckResourceAttr(resourceName, "registrant_privacy", "true"),
resource.TestCheckResourceAttr(resourceName, "tech_privacy", "false"),
),
},
{
Config: testAccRoute53DomainsDomainConfig_Privacy(domainName, true, true, true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "admin_privacy", "true"),
resource.TestCheckResourceAttr(resourceName, "registrant_privacy", "true"),
resource.TestCheckResourceAttr(resourceName, "tech_privacy", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSRoute53DomainsDomain_NameServers(t *testing.T) {
domainName := os.Getenv("ROUTE53DOMAINS_DOMAIN")
if domainName == "" {
t.Skip("Environment variable ROUTE53DOMAINS_DOMAIN is not set")
}

resourceName := "aws_route53domains_domain.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccRoute53DomainsDomainConfig_NameServers(domainName, "b.iana-servers.net", "c.iana-servers.net"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "name_servers.#", "2"),
resource.TestCheckResourceAttr(resourceName, "name_servers.0.name", "b.iana-servers.net"),
resource.TestCheckResourceAttr(resourceName, "name_servers.1.name", "c.iana-servers.net"),
),
},
{
Config: testAccRoute53DomainsDomainConfig_NameServers(domainName, "a.iana-servers.net", "b.iana-servers.net"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "name_servers.#", "2"),
resource.TestCheckResourceAttr(resourceName, "name_servers.0.name", "a.iana-servers.net"),
resource.TestCheckResourceAttr(resourceName, "name_servers.1.name", "b.iana-servers.net"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccRoute53DomainsDomainConfig_Basic(domainName string) string {
return fmt.Sprintf(`
resource "aws_route53domains_domain" "test" {
domain_name = "%s"
}
`, domainName)
}

func testAccRoute53DomainsDomainConfig_TagsSingle(domainName, tag1Key, tag1Value string) string {
return fmt.Sprintf(`
resource "aws_route53domains_domain" "test" {
domain_name = "%s"
tags = {
%q = %q
}
}
`, domainName, tag1Key, tag1Value)
}

func testAccRoute53DomainsDomainConfig_TagsMultiple(domainName, tag1Key, tag1Value, tag2Key, tag2Value string) string {
return fmt.Sprintf(`
resource "aws_route53domains_domain" "test" {
domain_name = "%s"
tags = {
%q = %q
%q = %q
}
}
`, domainName, tag1Key, tag1Value, tag2Key, tag2Value)
}

func testAccRoute53DomainsDomainConfig_AutoRenew(domainName, autoRenew string) string {
return fmt.Sprintf(`
resource "aws_route53domains_domain" "test" {
domain_name = "%s"
auto_renew = %s
}
`, domainName, autoRenew)
}

func testAccRoute53DomainsDomainConfig_TransferLock(domainName, transferLock string) string {
return fmt.Sprintf(`
resource "aws_route53domains_domain" "test" {
domain_name = "%s"
transfer_lock = %s
}
`, domainName, transferLock)
}

func testAccRoute53DomainsDomainConfig_Privacy(domainName string, adminPrivacy, registrantPrivacy, techPrivacy bool) string {
return fmt.Sprintf(`
resource "aws_route53domains_domain" "test" {
domain_name = "%s"
admin_privacy = %t
registrant_privacy = %t
tech_privacy = %t
}
`, domainName, adminPrivacy, registrantPrivacy, techPrivacy)
}

func testAccRoute53DomainsDomainConfig_NameServers(domainName, nameServer1, nameServer2 string) string {
return fmt.Sprintf(`
resource "aws_route53domains_domain" "test" {
domain_name = "%s"
name_servers {
name = "%s"
}
name_servers {
name = "%s"
}
}
`, domainName, nameServer1, nameServer2)
}
Loading

0 comments on commit 28fdd45

Please sign in to comment.