From f68a351fba706dfb6b543c40d64f127e301b8b36 Mon Sep 17 00:00:00 2001 From: clint shryock Date: Tue, 22 Dec 2015 16:23:08 -0600 Subject: [PATCH 1/3] provider/aws: Fix issue with Route53 and zero weighted records --- .../aws/resource_aws_route53_record.go | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/builtin/providers/aws/resource_aws_route53_record.go b/builtin/providers/aws/resource_aws_route53_record.go index a6c88ade4..2d024fe5e 100644 --- a/builtin/providers/aws/resource_aws_route53_record.go +++ b/builtin/providers/aws/resource_aws_route53_record.go @@ -64,9 +64,13 @@ func resourceAwsRoute53Record() *schema.Resource { ConflictsWith: []string{"alias"}, }, + // Weight uses a special sentinel value to indicate it's presense. + // Because 0 is a valid value for Weight, we default to -1 so that any + // inclusion of a weight (zero or not) will be a usable value "weight": &schema.Schema{ Type: schema.TypeInt, Optional: true, + Default: -1, }, "set_identifier": &schema.Schema{ @@ -171,8 +175,8 @@ func resourceAwsRoute53RecordCreate(d *schema.ResourceData, meta interface{}) er ChangeBatch: changeBatch, } - log.Printf("[DEBUG] Creating resource records for zone: %s, name: %s", - zone, *rec.Name) + log.Printf("[DEBUG] Creating resource records for zone: %s, name: %s\n\n%s", + zone, *rec.Name, req) wait := resource.StateChangeConf{ Pending: []string{"rejected"}, @@ -292,7 +296,12 @@ func resourceAwsRoute53RecordRead(d *schema.ResourceData, meta interface{}) erro } d.Set("ttl", record.TTL) - d.Set("weight", record.Weight) + // Only set the weight if it's non-nil, otherwise we end up with a 0 weight + // which has actual contextual meaning with Route 53 records + // See http://docs.aws.amazon.com/fr_fr/Route53/latest/APIReference/API_ChangeResourceRecordSets_Examples.html + if record.Weight != nil { + d.Set("weight", record.Weight) + } d.Set("set_identifier", record.SetIdentifier) d.Set("failover", record.Failover) d.Set("health_check_id", record.HealthCheckId) @@ -439,8 +448,9 @@ func resourceAwsRoute53RecordBuildSet(d *schema.ResourceData, zoneName string) ( rec.SetIdentifier = aws.String(v.(string)) } - if v, ok := d.GetOk("weight"); ok { - rec.Weight = aws.Int64(int64(v.(int))) + w := d.Get("weight").(int) + if w > -1 { + rec.Weight = aws.Int64(int64(w)) } return rec, nil From 787340f801e9b2bb7c26072cd5eae71f39102338 Mon Sep 17 00:00:00 2001 From: clint shryock Date: Tue, 22 Dec 2015 16:47:57 -0600 Subject: [PATCH 2/3] make note of -1 value for r53 record --- .../docs/providers/aws/r/route53_record.html.markdown | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/website/source/docs/providers/aws/r/route53_record.html.markdown b/website/source/docs/providers/aws/r/route53_record.html.markdown index e7455ba13..b1c6bf755 100644 --- a/website/source/docs/providers/aws/r/route53_record.html.markdown +++ b/website/source/docs/providers/aws/r/route53_record.html.markdown @@ -99,6 +99,12 @@ record from one another. Required for each weighted record. * `alias` - (Optional) An alias block. Conflicts with `ttl` & `records`. Alias record documented below. +~> **Note:** The `weight` attribute uses a special sentinel value of `-1` for a +default in Terraform. This allows Terraform to distinquish between a `0` value +and an empty value in the configuration (none specified). As a result, a +`weight` of `-1` will be present in the statefile if `weight` is omitted in the +configuraiton. + Exactly one of `records` or `alias` must be specified: this determines whether it's an alias record. Alias records support the following: From 4fc31abc6fac163de4cf3e0ee7e1341020d7acfa Mon Sep 17 00:00:00 2001 From: clint shryock Date: Mon, 4 Jan 2016 09:59:21 -0600 Subject: [PATCH 3/3] fix typo --- .../source/docs/providers/aws/r/route53_record.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/source/docs/providers/aws/r/route53_record.html.markdown b/website/source/docs/providers/aws/r/route53_record.html.markdown index b1c6bf755..11b4b5c59 100644 --- a/website/source/docs/providers/aws/r/route53_record.html.markdown +++ b/website/source/docs/providers/aws/r/route53_record.html.markdown @@ -103,7 +103,7 @@ record from one another. Required for each weighted record. default in Terraform. This allows Terraform to distinquish between a `0` value and an empty value in the configuration (none specified). As a result, a `weight` of `-1` will be present in the statefile if `weight` is omitted in the -configuraiton. +configuration. Exactly one of `records` or `alias` must be specified: this determines whether it's an alias record.