Merge pull request #13785 from bhood4/master
provider/ultradns: ultradns_rdpool resource minor improvements
This commit is contained in:
commit
87ebc19ae5
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"github.com/Ensighten/udnssdk"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/hashicorp/terraform/helper/validation"
|
||||
)
|
||||
|
||||
func resourceUltradnsRdpool() *schema.Resource {
|
||||
|
@ -28,12 +29,6 @@ func resourceUltradnsRdpool() *schema.Resource {
|
|||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"order": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
// 0-255 char
|
||||
// FIXED | RANDOM | ROUND_ROBIN
|
||||
},
|
||||
"rdata": &schema.Schema{
|
||||
Type: schema.TypeSet,
|
||||
Set: schema.HashString,
|
||||
|
@ -41,10 +36,20 @@ func resourceUltradnsRdpool() *schema.Resource {
|
|||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
},
|
||||
// Optional
|
||||
"description": &schema.Schema{
|
||||
"order": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
// 0-255 char
|
||||
Default: "ROUND_ROBIN",
|
||||
ValidateFunc: validation.StringInSlice([]string{
|
||||
"ROUND_ROBIN",
|
||||
"FIXED",
|
||||
"RANDOM",
|
||||
}, false),
|
||||
},
|
||||
"description": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ValidateFunc: validation.StringLenBetween(0, 255),
|
||||
},
|
||||
"ttl": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
|
@ -111,8 +116,7 @@ func resourceUltradnsRdpoolRead(d *schema.ResourceData, meta interface{}) error
|
|||
r := rrsets[0]
|
||||
|
||||
zone := d.Get("zone")
|
||||
// ttl
|
||||
d.Set("ttl", r.TTL)
|
||||
|
||||
// hostname
|
||||
if r.OwnerName == "" {
|
||||
d.Set("hostname", zone)
|
||||
|
@ -134,11 +138,11 @@ func resourceUltradnsRdpoolRead(d *schema.ResourceData, meta interface{}) error
|
|||
}
|
||||
|
||||
// Set simple values
|
||||
d.Set("ttl", r.TTL)
|
||||
d.Set("description", p.Description)
|
||||
d.Set("order", p.Order)
|
||||
|
||||
err = d.Set("rdata", makeSetFromStrings(r.RData))
|
||||
//err = d.Set("rdata", makeSetFromRdataAlone(r.RData))
|
||||
if err != nil {
|
||||
return fmt.Errorf("rdata set failed: %#v", err)
|
||||
}
|
||||
|
@ -186,13 +190,12 @@ func resourceUltradnsRdpoolDelete(d *schema.ResourceData, meta interface{}) erro
|
|||
func newRRSetResourceFromRdpool(d *schema.ResourceData) (rRSetResource, error) {
|
||||
//rDataRaw := d.Get("rdata").(*schema.Set).List()
|
||||
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
|
||||
RRType: "A",
|
||||
Zone: d.Get("zone").(string),
|
||||
OwnerName: d.Get("name").(string),
|
||||
TTL: d.Get("ttl").(int),
|
||||
//RData: unzipRdataHosts(rDataRaw),
|
||||
}
|
||||
if attr, ok := d.GetOk("rdata"); ok {
|
||||
rdata := attr.(*schema.Set).List()
|
||||
|
@ -213,27 +216,3 @@ func newRRSetResourceFromRdpool(d *schema.ResourceData) (rRSetResource, error) {
|
|||
|
||||
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
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ The following arguments are supported:
|
|||
|
||||
* `zone` - (Required) The domain to add the record to
|
||||
* `name` - (Required) The name of the record
|
||||
* `order` - (Required) Ordering rule, one of FIXED, RANDOM or ROUND_ROBIN
|
||||
* `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.
|
||||
* `ttl` - (Optional) The TTL of the pool in seconds. Default: `3600`.
|
||||
|
||||
|
|
Loading…
Reference in New Issue