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

r/route53_record - support zero ttl #12481

Closed
Closed
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
50 changes: 29 additions & 21 deletions aws/resource_aws_route53_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"log"
"math"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -84,6 +85,7 @@ func resourceAwsRoute53Record() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
ConflictsWith: []string{"alias"},
ValidateFunc: validation.IntBetween(0, math.MaxInt32),
},

"set_identifier": {
Expand Down Expand Up @@ -136,13 +138,10 @@ func resourceAwsRoute53Record() *schema.Resource {
"type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: func(v interface{}, k string) (ws []string, es []error) {
value := v.(string)
if value != "PRIMARY" && value != "SECONDARY" {
es = append(es, fmt.Errorf("Failover policy type must be PRIMARY or SECONDARY"))
}
return
},
ValidateFunc: validation.StringInSlice([]string{
route53.ResourceRecordSetFailoverPrimary,
route53.ResourceRecordSetFailoverSecondary,
}, false),
},
},
},
Expand Down Expand Up @@ -181,6 +180,15 @@ func resourceAwsRoute53Record() *schema.Resource {
"continent": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"AF",
"AN",
"AS",
"EU",
"OC",
"NA",
"SA",
}, false),
},
"country": {
Type: schema.TypeString,
Expand All @@ -206,8 +214,9 @@ func resourceAwsRoute53Record() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"weight": {
Type: schema.TypeInt,
Required: true,
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.IntBetween(0, 255),
},
},
},
Expand All @@ -234,7 +243,6 @@ func resourceAwsRoute53Record() *schema.Resource {
ConflictsWith: []string{"alias"},
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
Set: schema.HashString,
},

"allow_overwrite": {
Expand Down Expand Up @@ -295,7 +303,7 @@ func resourceAwsRoute53RecordUpdate(d *schema.ResourceData, meta interface{}) er
}
}

if v, _ := d.GetChange("ttl"); v.(int) != 0 {
if v, _ := d.GetChange("ttl"); v != nil {
oldRec.TTL = aws.Int64(int64(v.(int)))
}

Expand Down Expand Up @@ -537,7 +545,7 @@ func resourceAwsRoute53RecordRead(d *schema.ResourceData, meta interface{}) erro

err = d.Set("records", flattenResourceRecords(record.ResourceRecords, aws.StringValue(record.Type)))
if err != nil {
return fmt.Errorf("Error setting records for: %s, error: %w", d.Id(), err)
return fmt.Errorf("error setting records for: %s, error: %w", d.Id(), err)
}

if alias := record.AliasTarget; alias != nil {
Expand All @@ -558,7 +566,7 @@ func resourceAwsRoute53RecordRead(d *schema.ResourceData, meta interface{}) erro
"type": aws.StringValue(record.Failover),
}}
if err := d.Set("failover_routing_policy", v); err != nil {
return fmt.Errorf("Error setting failover records for: %s, error: %w", d.Id(), err)
return fmt.Errorf("error setting failover records for: %s, error: %w", d.Id(), err)
}
}

Expand All @@ -569,7 +577,7 @@ func resourceAwsRoute53RecordRead(d *schema.ResourceData, meta interface{}) erro
"subdivision": aws.StringValue(record.GeoLocation.SubdivisionCode),
}}
if err := d.Set("geolocation_routing_policy", v); err != nil {
return fmt.Errorf("Error setting gelocation records for: %s, error: %w", d.Id(), err)
return fmt.Errorf("error setting gelocation records for: %s, error: %w", d.Id(), err)
}
}

Expand All @@ -578,22 +586,22 @@ func resourceAwsRoute53RecordRead(d *schema.ResourceData, meta interface{}) erro
"region": aws.StringValue(record.Region),
}}
if err := d.Set("latency_routing_policy", v); err != nil {
return fmt.Errorf("Error setting latency records for: %s, error: %w", d.Id(), err)
return fmt.Errorf("error setting latency records for: %s, error: %w", d.Id(), err)
}
}

if record.Weight != nil {
v := []map[string]interface{}{{
"weight": aws.Int64Value((record.Weight)),
"weight": aws.Int64Value(record.Weight),
}}
if err := d.Set("weighted_routing_policy", v); err != nil {
return fmt.Errorf("Error setting weighted records for: %s, error: %w", d.Id(), err)
return fmt.Errorf("error setting weighted records for: %s, error: %w", d.Id(), err)
}
}

if record.MultiValueAnswer != nil {
if err := d.Set("multivalue_answer_routing_policy", record.MultiValueAnswer); err != nil {
return fmt.Errorf("Error setting multivalue answer records for: %s, error: %w", d.Id(), err)
return fmt.Errorf("error setting multivalue answer records for: %s, error: %w", d.Id(), err)
}
}

Expand Down Expand Up @@ -680,7 +688,7 @@ func findRecord(d *schema.ResourceData, meta interface{}) (*route53.ResourceReco
err = conn.ListResourceRecordSetsPages(lopts, func(resp *route53.ListResourceRecordSetsOutput, lastPage bool) bool {
for _, recordSet := range resp.ResourceRecordSets {

responseName := strings.ToLower(cleanRecordName(*recordSet.Name))
responseName := strings.ToLower(cleanRecordName(aws.StringValue(recordSet.Name)))
responseType := strings.ToUpper(aws.StringValue(recordSet.Type))

if recordName != responseName {
Expand Down Expand Up @@ -788,7 +796,7 @@ func resourceAwsRoute53RecordBuildSet(d *schema.ResourceData, zoneName string) (
Type: aws.String(d.Get("type").(string)),
}

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

Expand All @@ -812,7 +820,7 @@ func resourceAwsRoute53RecordBuildSet(d *schema.ResourceData, zoneName string) (
}
log.Printf("[DEBUG] Creating alias: %#v", alias)
} else {
if _, ok := d.GetOk("ttl"); !ok {
if _, ok := d.GetOkExists("ttl"); !ok {
return nil, fmt.Errorf(`provider.aws: aws_route53_record: %s: "ttl": required field is not set`, d.Get("name").(string))
}

Expand Down
Loading