From b1c215f5e28dab48726de46f0fe23bdbd18120be Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 21 Apr 2016 08:53:53 -0700 Subject: [PATCH] providers/aws: route53_zone id-only refresh --- .../aws/resource_aws_route53_zone.go | 8 +++++ .../aws/resource_aws_route53_zone_test.go | 30 +++++++++++-------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/builtin/providers/aws/resource_aws_route53_zone.go b/builtin/providers/aws/resource_aws_route53_zone.go index 2b2930ac1..ad918884a 100644 --- a/builtin/providers/aws/resource_aws_route53_zone.go +++ b/builtin/providers/aws/resource_aws_route53_zone.go @@ -138,6 +138,14 @@ func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error return err } + // In the import case this will be empty + if _, ok := d.GetOk("zone_id"); !ok { + d.Set("zone_id", d.Id()) + } + if _, ok := d.GetOk("name"); !ok { + d.Set("name", zone.HostedZone.Name) + } + if !*zone.HostedZone.Config.PrivateZone { ns := make([]string, len(zone.DelegationSet.NameServers)) for i := range zone.DelegationSet.NameServers { diff --git a/builtin/providers/aws/resource_aws_route53_zone_test.go b/builtin/providers/aws/resource_aws_route53_zone_test.go index 9f9ef0006..bea1d9320 100644 --- a/builtin/providers/aws/resource_aws_route53_zone_test.go +++ b/builtin/providers/aws/resource_aws_route53_zone_test.go @@ -69,9 +69,10 @@ func TestAccAWSRoute53Zone_basic(t *testing.T) { var td route53.ResourceTagSet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRoute53ZoneDestroy, + PreCheck: func() { testAccPreCheck(t) }, + IDRefreshName: "aws_route53_zone.main", + Providers: testAccProviders, + CheckDestroy: testAccCheckRoute53ZoneDestroy, Steps: []resource.TestStep{ resource.TestStep{ Config: testAccRoute53ZoneConfig, @@ -90,9 +91,10 @@ func TestAccAWSRoute53Zone_updateComment(t *testing.T) { var td route53.ResourceTagSet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRoute53ZoneDestroy, + PreCheck: func() { testAccPreCheck(t) }, + IDRefreshName: "aws_route53_zone.main", + Providers: testAccProviders, + CheckDestroy: testAccCheckRoute53ZoneDestroy, Steps: []resource.TestStep{ resource.TestStep{ Config: testAccRoute53ZoneConfig, @@ -122,9 +124,10 @@ func TestAccAWSRoute53Zone_private_basic(t *testing.T) { var zone route53.GetHostedZoneOutput resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRoute53ZoneDestroy, + PreCheck: func() { testAccPreCheck(t) }, + IDRefreshName: "aws_route53_zone.main", + Providers: testAccProviders, + CheckDestroy: testAccCheckRoute53ZoneDestroy, Steps: []resource.TestStep{ resource.TestStep{ Config: testAccRoute53PrivateZoneConfig, @@ -153,6 +156,7 @@ func TestAccAWSRoute53Zone_private_region(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, + IDRefreshName: "aws_route53_zone.main", ProviderFactories: providerFactories, CheckDestroy: testAccCheckRoute53ZoneDestroyWithProviders(&providers), Steps: []resource.TestStep{ @@ -310,7 +314,7 @@ func testAccLoadTagsR53(zone *route53.GetHostedZoneOutput, td *route53.ResourceT const testAccRoute53ZoneConfig = ` resource "aws_route53_zone" "main" { - name = "hashicorp.com" + name = "hashicorp.com." comment = "Custom comment" tags { @@ -322,7 +326,7 @@ resource "aws_route53_zone" "main" { const testAccRoute53ZoneConfigUpdateComment = ` resource "aws_route53_zone" "main" { - name = "hashicorp.com" + name = "hashicorp.com." comment = "Change Custom Comment" tags { @@ -341,7 +345,7 @@ resource "aws_vpc" "main" { } resource "aws_route53_zone" "main" { - name = "hashicorp.com" + name = "hashicorp.com." vpc_id = "${aws_vpc.main.id}" } ` @@ -367,7 +371,7 @@ resource "aws_vpc" "main" { resource "aws_route53_zone" "main" { provider = "aws.west" - name = "hashicorp.com" + name = "hashicorp.com." vpc_id = "${aws_vpc.main.id}" vpc_region = "us-east-1" }