provider/aws: Fix issue in updating Route 53 records on refresh/read.

Route 53 records were silently erroring out when saving the records returned
from AWS, because they weren't being presented as an array of strings like we
expected.
This commit is contained in:
Clint Shryock 2015-04-08 09:06:15 -05:00
parent 18f2e13275
commit f2b68c4ca8
3 changed files with 35 additions and 1 deletions

View File

@ -184,7 +184,10 @@ func resourceAwsRoute53RecordRead(d *schema.ResourceData, meta interface{}) erro
found = true
d.Set("records", record.ResourceRecords)
err := d.Set("records", flattenResourceRecords(record.ResourceRecords))
if err != nil {
log.Printf("[DEBUG] Error setting records for: %s, error: %#v", en, err)
}
d.Set("ttl", record.TTL)
break

View File

@ -7,6 +7,7 @@ import (
"github.com/hashicorp/aws-sdk-go/gen/ec2"
"github.com/hashicorp/aws-sdk-go/gen/elb"
"github.com/hashicorp/aws-sdk-go/gen/rds"
"github.com/hashicorp/aws-sdk-go/gen/route53"
"github.com/hashicorp/terraform/helper/schema"
)
@ -251,3 +252,11 @@ func flattenAttachment(a *ec2.NetworkInterfaceAttachment) map[string]interface{}
att["attachment_id"] = *a.AttachmentID
return att
}
func flattenResourceRecords(recs []route53.ResourceRecord) []string {
strs := make([]string, 0, len(recs))
for _, r := range recs {
strs = append(strs, *r.Value)
}
return strs
}

View File

@ -8,6 +8,7 @@ import (
ec2 "github.com/hashicorp/aws-sdk-go/gen/ec2"
"github.com/hashicorp/aws-sdk-go/gen/elb"
"github.com/hashicorp/aws-sdk-go/gen/rds"
"github.com/hashicorp/aws-sdk-go/gen/route53"
"github.com/hashicorp/terraform/flatmap"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema"
@ -442,3 +443,24 @@ func TestFlattenAttachment(t *testing.T) {
t.Fatalf("expected attachment_id to be at-002, but got %s", result["attachment_id"])
}
}
func TestFlattenResourceRecords(t *testing.T) {
expanded := []route53.ResourceRecord{
route53.ResourceRecord{
Value: aws.String("127.0.0.1"),
},
route53.ResourceRecord{
Value: aws.String("127.0.0.3"),
},
}
result := flattenResourceRecords(expanded)
if result == nil {
t.Fatal("expected result to have value, but got nil")
}
if len(result) != 2 {
t.Fatal("expected result to have value, but got nil")
}
}