Skip to content

Commit

Permalink
- minor wording update and link to docs
Browse files Browse the repository at this point in the history
- fix error checking
- update debug log on migration
- remove regression test because the attribute is renamed
  • Loading branch information
catsby committed May 31, 2016
1 parent 97fbeaf commit d89a240
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 67 deletions.
23 changes: 9 additions & 14 deletions builtin/providers/aws/resource_aws_route53_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func resourceAwsRoute53Record() *schema.Resource {
"weight": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Removed: "Now implemented as weighted_routing_policy; see docs",
Removed: "Now implemented as weighted_routing_policy; Please see https://www.terraform.io/docs/providers/aws/r/route53_record.html",
},

"set_identifier": &schema.Schema{
Expand Down Expand Up @@ -151,7 +151,6 @@ func resourceAwsRoute53Record() *schema.Resource {
"region": &schema.Schema{
Type: schema.TypeString,
Required: true,
Optional: false,
},
},
},
Expand Down Expand Up @@ -382,9 +381,8 @@ func resourceAwsRoute53RecordRead(d *schema.ResourceData, meta interface{}) erro
v := []map[string]interface{}{{
"type": aws.StringValue(record.Failover),
}}
d.Set("failover_routing_policy", v)
if err != nil {
return fmt.Errorf("[DEBUG] Error setting records for: %s, error: %#v", d.Id(), err)
if err := d.Set("failover_routing_policy", v); err != nil {
return fmt.Errorf("[DEBUG] Error setting failover records for: %s, error: %#v", d.Id(), err)
}
}

Expand All @@ -394,29 +392,26 @@ func resourceAwsRoute53RecordRead(d *schema.ResourceData, meta interface{}) erro
"country": aws.StringValue(record.GeoLocation.CountryCode),
"subdivision": aws.StringValue(record.GeoLocation.SubdivisionCode),
}}
d.Set("geolocation_routing_policy", v)
if err != nil {
return fmt.Errorf("[DEBUG] Error setting records for: %s, error: %#v", d.Id(), err)
if err := d.Set("geolocation_routing_policy", v); err != nil {
return fmt.Errorf("[DEBUG] Error setting gelocation records for: %s, error: %#v", d.Id(), err)
}
}

if record.Region != nil {
v := []map[string]interface{}{{
"region": aws.StringValue(record.Region),
}}
d.Set("latency_routing_policy", v)
if err != nil {
return fmt.Errorf("[DEBUG] Error setting records for: %s, error: %#v", d.Id(), err)
if err := d.Set("latency_routing_policy", v); err != nil {
return fmt.Errorf("[DEBUG] Error setting latency records for: %s, error: %#v", d.Id(), err)
}
}

if record.Weight != nil {
v := []map[string]interface{}{{
"weight": aws.Int64Value((record.Weight)),
}}
d.Set("weighted_routing_policy", v)
if err != nil {
return fmt.Errorf("[DEBUG] Error setting records for: %s, error: %#v", d.Id(), err)
if err := d.Set("weighted_routing_policy", v); err != nil {
return fmt.Errorf("[DEBUG] Error setting weighted records for: %s, error: %#v", d.Id(), err)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func resourceAwsRoute53RecordMigrateState(
log.Println("[INFO] Found AWS Route53 Record State v0; migrating to v1")
return migrateRoute53RecordStateV0toV1(is)
case 1:
log.Println("[INFO] Found AWS Route53 Record State v0; migrating to v1")
log.Println("[INFO] Found AWS Route53 Record State v1; migrating to v2")
return migrateRoute53RecordStateV1toV2(is)
default:
return is, fmt.Errorf("Unexpected schema version: %d", v)
Expand Down
52 changes: 0 additions & 52 deletions builtin/providers/aws/resource_aws_route53_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,58 +336,6 @@ func TestAccAWSRoute53Record_TypeChange(t *testing.T) {
})
}

// Test record deletion out of band and make sure we render a new plan
// Part of regression test(s) for https://github.com/hashicorp/terraform/pull/4892
func TestAccAWSRoute53Record_planUpdate(t *testing.T) {
var zone route53.GetHostedZoneOutput
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRoute53RecordDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccRoute53RecordConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53RecordExists("aws_route53_record.default"),
testAccCheckRoute53ZoneExists("aws_route53_zone.main", &zone),
),
},
resource.TestStep{
Config: testAccRoute53RecordConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53DeleteRecord("aws_route53_record.default", &zone),
),
ExpectNonEmptyPlan: true,
},
resource.TestStep{
Config: testAccRoute53RecordNoConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53ZoneExists("aws_route53_zone.main", &zone),
),
},
},
})
}

func testAccCheckRoute53DeleteRecord(n string, zone *route53.GetHostedZoneOutput) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}

if rs.Primary.ID == "" {
return fmt.Errorf("No hosted zone ID is set")
}

// Manually set the weight to 0 to replicate a record created in Terraform
// pre-0.6.9
rs.Primary.Attributes["weight"] = "0"

return nil
}
}

func testAccCheckRoute53RecordDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).r53conn
for _, rs := range s.RootModule().Resources {
Expand Down

0 comments on commit d89a240

Please sign in to comment.