From a0d9a4c96f654390dc9169e5296f80515990583b Mon Sep 17 00:00:00 2001 From: Anthony Stanton Date: Wed, 9 Sep 2015 16:01:58 +0200 Subject: [PATCH 1/2] Workaround to allow weight = 0 in Route53 RRs Moved the GetOk to a Get in the set_identifier block so we can create a zero-weighted RR - otherwise this falls foul of a check in GetOk. See https://github.com/hashicorp/terraform/issues/3189 --- builtin/providers/aws/resource_aws_route53_record.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/builtin/providers/aws/resource_aws_route53_record.go b/builtin/providers/aws/resource_aws_route53_record.go index 9686c48a90..1966c33de4 100644 --- a/builtin/providers/aws/resource_aws_route53_record.go +++ b/builtin/providers/aws/resource_aws_route53_record.go @@ -407,12 +407,9 @@ func resourceAwsRoute53RecordBuildSet(d *schema.ResourceData, zoneName string) ( rec.HealthCheckId = aws.String(v.(string)) } - if v, ok := d.GetOk("weight"); ok { - rec.Weight = aws.Int64(int64(v.(int))) - } - if v, ok := d.GetOk("set_identifier"); ok { rec.SetIdentifier = aws.String(v.(string)) + rec.Weight = aws.Int64(int64(d.Get("weight").(int))) } return rec, nil From 44f2d85de8c804e55c1af82a792c86b0b5e9293d Mon Sep 17 00:00:00 2001 From: Anthony Stanton Date: Thu, 17 Sep 2015 17:20:12 +0200 Subject: [PATCH 2/2] Add acceptance test === RUN TestAccAWSRoute53Record_weighted --- PASS: TestAccAWSRoute53Record_weighted (249.19s) --- .../providers/aws/resource_aws_route53_record_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/builtin/providers/aws/resource_aws_route53_record_test.go b/builtin/providers/aws/resource_aws_route53_record_test.go index 6b25488d37..bbeb859cd8 100644 --- a/builtin/providers/aws/resource_aws_route53_record_test.go +++ b/builtin/providers/aws/resource_aws_route53_record_test.go @@ -133,6 +133,7 @@ func TestAccAWSRoute53Record_weighted(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckRoute53RecordExists("aws_route53_record.www-dev"), testAccCheckRoute53RecordExists("aws_route53_record.www-live"), + testAccCheckRoute53RecordExists("aws_route53_record.www-off"), ), }, }, @@ -407,6 +408,16 @@ resource "aws_route53_record" "www-live" { set_identifier = "live" records = ["dev.notexample.com"] } + +resource "aws_route53_record" "www-off" { + zone_id = "${aws_route53_zone.main.zone_id}" + name = "www" + type = "CNAME" + ttl = "5" + weight = 0 + set_identifier = "off" + records = ["dev.notexample.com"] +} ` const testAccRoute53ElbAliasRecord = `