diff --git a/builtin/providers/aws/resource_aws_route53_record.go b/builtin/providers/aws/resource_aws_route53_record.go index 3a8ef2e5c..58d54b4e7 100644 --- a/builtin/providers/aws/resource_aws_route53_record.go +++ b/builtin/providers/aws/resource_aws_route53_record.go @@ -269,18 +269,8 @@ func resourceAwsRoute53RecordDelete(d *schema.ResourceData, meta interface{}) er func resourceAwsRoute53RecordBuildSet(d *schema.ResourceData, zoneName string) (*route53.ResourceRecordSet, error) { recs := d.Get("records").(*schema.Set).List() - records := make([]route53.ResourceRecord, 0, len(recs)) - typeStr := d.Get("type").(string) - for _, r := range recs { - switch typeStr { - case "TXT": - str := fmt.Sprintf("\"%s\"", r.(string)) - records = append(records, route53.ResourceRecord{Value: aws.String(str)}) - default: - records = append(records, route53.ResourceRecord{Value: aws.String(r.(string))}) - } - } + records := expandResourceRecords(recs, d.Get("type").(string)) // get expanded name en := expandRecordName(d.Get("name").(string), zoneName) diff --git a/builtin/providers/aws/structure.go b/builtin/providers/aws/structure.go index b4ff209d6..03a9bca8c 100644 --- a/builtin/providers/aws/structure.go +++ b/builtin/providers/aws/structure.go @@ -1,6 +1,7 @@ package aws import ( + "fmt" "strings" "github.com/hashicorp/aws-sdk-go/aws" @@ -256,7 +257,25 @@ func flattenAttachment(a *ec2.NetworkInterfaceAttachment) map[string]interface{} func flattenResourceRecords(recs []route53.ResourceRecord) []string { strs := make([]string, 0, len(recs)) for _, r := range recs { - strs = append(strs, *r.Value) + if r.Value != nil { + s := strings.Replace(*r.Value, "\"", "", 2) + strs = append(strs, s) + } } return strs } + +func expandResourceRecords(recs []interface{}, typeStr string) []route53.ResourceRecord { + records := make([]route53.ResourceRecord, 0, len(recs)) + for _, r := range recs { + s := r.(string) + switch typeStr { + case "TXT": + str := fmt.Sprintf("\"%s\"", s) + records = append(records, route53.ResourceRecord{Value: aws.String(str)}) + default: + records = append(records, route53.ResourceRecord{Value: aws.String(s)}) + } + } + return records +}