Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/aws: fix for creating failover route53 records #3900

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion builtin/providers/aws/resource_aws_route53_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,10 @@ func resourceAwsRoute53RecordBuildSet(d *schema.ResourceData, zoneName string) (

if v, ok := d.GetOk("set_identifier"); ok {
rec.SetIdentifier = aws.String(v.(string))
rec.Weight = aws.Int64(int64(d.Get("weight").(int)))
}

if v, ok := d.GetOk("weight"); ok {
rec.Weight = aws.Int64(int64(v.(int)))
}

return rec, nil
Expand Down
57 changes: 57 additions & 0 deletions builtin/providers/aws/resource_aws_route53_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,23 @@ func TestAccAWSRoute53Record_wildcard(t *testing.T) {
})
}

func TestAccAWSRoute53Record_failover(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRoute53RecordDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccRoute53FailoverCNAMERecord,
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53RecordExists("aws_route53_record.www-primary"),
testAccCheckRoute53RecordExists("aws_route53_record.www-secondary"),
),
},
},
})
}

func TestAccAWSRoute53Record_weighted(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -384,6 +401,46 @@ resource "aws_route53_record" "default" {
}
`

const testAccRoute53FailoverCNAMERecord = `
resource "aws_route53_zone" "main" {
name = "notexample.com"
}

resource "aws_route53_health_check" "foo" {
fqdn = "dev.notexample.com"
port = 80
type = "HTTP"
resource_path = "/"
failure_threshold = "2"
request_interval = "30"

tags = {
Name = "tf-test-health-check"
}
}

resource "aws_route53_record" "www-primary" {
zone_id = "${aws_route53_zone.main.zone_id}"
name = "www"
type = "CNAME"
ttl = "5"
failover = "PRIMARY"
health_check_id = "${aws_route53_health_check.foo.id}"
set_identifier = "www-primary"
records = ["primary.notexample.com"]
}

resource "aws_route53_record" "www-secondary" {
zone_id = "${aws_route53_zone.main.zone_id}"
name = "www"
type = "CNAME"
ttl = "5"
failover = "SECONDARY"
set_identifier = "www-secondary"
records = ["secondary.notexample.com"]
}
`

const testAccRoute53WeightedCNAMERecord = `
resource "aws_route53_zone" "main" {
name = "notexample.com"
Expand Down