cleanup and validation, rdpool.order optional with ROUND_ROBIN default

This commit is contained in:
ebilhoo 2017-04-19 19:54:42 +00:00
parent 627544e872
commit 65d364d805
2 changed files with 27 additions and 37 deletions

View File

@ -28,12 +28,6 @@ func resourceUltradnsRdpool() *schema.Resource {
Required: true, Required: true,
ForceNew: true, ForceNew: true,
}, },
"order": &schema.Schema{
Type: schema.TypeString,
Required: true,
// 0-255 char
// FIXED | RANDOM | ROUND_ROBIN
},
"rdata": &schema.Schema{ "rdata": &schema.Schema{
Type: schema.TypeSet, Type: schema.TypeSet,
Set: schema.HashString, Set: schema.HashString,
@ -41,10 +35,32 @@ func resourceUltradnsRdpool() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
}, },
// Optional // Optional
"order": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "ROUND_ROBIN",
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if value != "ROUND_ROBIN" && value != "FIXED" && value != "RANDOM" {
errors = append(errors, fmt.Errorf(
"Only 'ROUND_ROBIN', 'FIXED', and 'RANDOM' are supported values for 'order'"))
}
return
},
},
"description": &schema.Schema{ "description": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
// 0-255 char ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
if v != nil {
value := v.(string)
if len(value) > 255 {
errors = append(errors, fmt.Errorf(
"'description' length must be 0-255"))
}
}
return
},
}, },
"ttl": &schema.Schema{ "ttl": &schema.Schema{
Type: schema.TypeInt, Type: schema.TypeInt,
@ -111,8 +127,7 @@ func resourceUltradnsRdpoolRead(d *schema.ResourceData, meta interface{}) error
r := rrsets[0] r := rrsets[0]
zone := d.Get("zone") zone := d.Get("zone")
// ttl
d.Set("ttl", r.TTL)
// hostname // hostname
if r.OwnerName == "" { if r.OwnerName == "" {
d.Set("hostname", zone) d.Set("hostname", zone)
@ -134,11 +149,11 @@ func resourceUltradnsRdpoolRead(d *schema.ResourceData, meta interface{}) error
} }
// Set simple values // Set simple values
d.Set("ttl", r.TTL)
d.Set("description", p.Description) d.Set("description", p.Description)
d.Set("order", p.Order) d.Set("order", p.Order)
err = d.Set("rdata", makeSetFromStrings(r.RData)) err = d.Set("rdata", makeSetFromStrings(r.RData))
//err = d.Set("rdata", makeSetFromRdataAlone(r.RData))
if err != nil { if err != nil {
return fmt.Errorf("rdata set failed: %#v", err) return fmt.Errorf("rdata set failed: %#v", err)
} }
@ -186,13 +201,12 @@ func resourceUltradnsRdpoolDelete(d *schema.ResourceData, meta interface{}) erro
func newRRSetResourceFromRdpool(d *schema.ResourceData) (rRSetResource, error) { func newRRSetResourceFromRdpool(d *schema.ResourceData) (rRSetResource, error) {
//rDataRaw := d.Get("rdata").(*schema.Set).List() //rDataRaw := d.Get("rdata").(*schema.Set).List()
r := rRSetResource{ r := rRSetResource{
// "The only valid rrtype value for SiteBacker or Traffic Controller pools is A" // "The only valid rrtype value for RDpools is A"
// per https://portal.ultradns.com/static/docs/REST-API_User_Guide.pdf // per https://portal.ultradns.com/static/docs/REST-API_User_Guide.pdf
RRType: "A", RRType: "A",
Zone: d.Get("zone").(string), Zone: d.Get("zone").(string),
OwnerName: d.Get("name").(string), OwnerName: d.Get("name").(string),
TTL: d.Get("ttl").(int), TTL: d.Get("ttl").(int),
//RData: unzipRdataHosts(rDataRaw),
} }
if attr, ok := d.GetOk("rdata"); ok { if attr, ok := d.GetOk("rdata"); ok {
rdata := attr.(*schema.Set).List() rdata := attr.(*schema.Set).List()
@ -213,27 +227,3 @@ func newRRSetResourceFromRdpool(d *schema.ResourceData) (rRSetResource, error) {
return r, nil return r, nil
} }
// zip RData into []map[string]interface{}
func zipRDataAlone(rds []string) []map[string]interface{} {
result := make([]map[string]interface{}, 0, len(rds))
for _, rd := range rds {
r := map[string]interface{}{
// "host": rds[i],
"host": rd,
}
result = append(result, r)
}
return result
}
// makeSetFromRdatas encodes an array of Rdata into a
// *schema.Set in the appropriate structure for the schema
func makeSetFromRdataAlone(rds []string) *schema.Set {
s := &schema.Set{F: hashRdatas}
rs := zipRDataAlone(rds)
for _, r := range rs {
s.Add(r)
}
return s
}

View File

@ -33,8 +33,8 @@ The following arguments are supported:
* `zone` - (Required) The domain to add the record to * `zone` - (Required) The domain to add the record to
* `name` - (Required) The name of the record * `name` - (Required) The name of the record
* `order` - (Required) Ordering rule, one of FIXED, RANDOM or ROUND_ROBIN
* `rdata` - (Required) list ip addresses. * `rdata` - (Required) list ip addresses.
* `order` - (Optional) Ordering rule, one of FIXED, RANDOM or ROUND_ROBIN. Default: 'ROUND_ROBIN'.
* `description` - (Optional) Description of the Resource Distribution pool. Valid values are strings less than 256 characters. * `description` - (Optional) Description of the Resource Distribution pool. Valid values are strings less than 256 characters.
* `ttl` - (Optional) The TTL of the pool in seconds. Default: `3600`. * `ttl` - (Optional) The TTL of the pool in seconds. Default: `3600`.