From c5eb16cfb1b47be59c6f1e3f67cd97cfeee2ec34 Mon Sep 17 00:00:00 2001 From: Clint Shryock Date: Mon, 6 Apr 2015 10:16:23 -0500 Subject: [PATCH 1/2] provider/aws: Change Route 53 record to allow resource updates This removes `ForceNew` from `records` and `ttl`, and introduces a `resourceAwsRoute53RecordUpdate` function. The `resourceAwsRoute53RecordUpdate` falls through to the `resourceAwsRoute53RecordCreate` function, which utilizes AWS `UPSERT` behavior and diffs for us. `Name` and `Type` are used by AWS in the `UPSERT`, so only records with matching `name` and `type` can be updated. Others are created as new, so we leave the `ForceNew` behavior here. --- .../providers/aws/resource_aws_route53_record.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/builtin/providers/aws/resource_aws_route53_record.go b/builtin/providers/aws/resource_aws_route53_record.go index 71ddff05679d..3f8697d53cea 100644 --- a/builtin/providers/aws/resource_aws_route53_record.go +++ b/builtin/providers/aws/resource_aws_route53_record.go @@ -18,6 +18,7 @@ func resourceAwsRoute53Record() *schema.Resource { return &schema.Resource{ Create: resourceAwsRoute53RecordCreate, Read: resourceAwsRoute53RecordRead, + Update: resourceAwsRoute53RecordUpdate, Delete: resourceAwsRoute53RecordDelete, Schema: map[string]*schema.Schema{ @@ -42,14 +43,12 @@ func resourceAwsRoute53Record() *schema.Resource { "ttl": &schema.Schema{ Type: schema.TypeInt, Required: true, - ForceNew: true, }, "records": &schema.Schema{ Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}, Required: true, - ForceNew: true, Set: func(v interface{}) int { return hashcode.String(v.(string)) }, @@ -58,6 +57,19 @@ func resourceAwsRoute53Record() *schema.Resource { } } +func resourceAwsRoute53RecordUpdate(d *schema.ResourceData, meta interface{}) error { + // Route 53 supports CREATE, DELETE, and UPSERT actions. We use UPSERT, and + // AWS dynamically determins if a record should be created or updated. + // Amazon Route 53 can update an existing resource record set only when all + // of the following values match: Name, Type + // (and SetIdentifier, which we don't use yet). + // See http://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets_Requests.html#change-rrsets-request-action + // + // Because we use UPSERT, for resouce update here we simply fall through to + // our resource create function. + return resourceAwsRoute53RecordCreate(d, meta) +} + func resourceAwsRoute53RecordCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).r53conn zone := d.Get("zone_id").(string) From c2b293d0470977a882645a27042203ad47503460 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Mon, 6 Apr 2015 10:45:02 -0500 Subject: [PATCH 2/2] Fix comment typo --- builtin/providers/aws/resource_aws_route53_record.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_route53_record.go b/builtin/providers/aws/resource_aws_route53_record.go index 3f8697d53cea..bfee41978788 100644 --- a/builtin/providers/aws/resource_aws_route53_record.go +++ b/builtin/providers/aws/resource_aws_route53_record.go @@ -59,7 +59,7 @@ func resourceAwsRoute53Record() *schema.Resource { func resourceAwsRoute53RecordUpdate(d *schema.ResourceData, meta interface{}) error { // Route 53 supports CREATE, DELETE, and UPSERT actions. We use UPSERT, and - // AWS dynamically determins if a record should be created or updated. + // AWS dynamically determines if a record should be created or updated. // Amazon Route 53 can update an existing resource record set only when all // of the following values match: Name, Type // (and SetIdentifier, which we don't use yet).