Skip to content

Commit

Permalink
Merge pull request #36 from Constellix/bug-fixes
Browse files Browse the repository at this point in the history
Updated NS_Record, Domain and Geo_filter resources
  • Loading branch information
jr-frazier authored Aug 18, 2021
2 parents e22dca0 + 979a978 commit 1b966c3
Show file tree
Hide file tree
Showing 81 changed files with 515 additions and 582 deletions.
2 changes: 1 addition & 1 deletion constellix/datasource_constellix_aaaa_record_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func datasourceConstellixAAAArecordpool() *schema.Resource {
},

"weight": &schema.Schema{
Type: schema.TypeInt,
Type: schema.TypeString,
Required: true,
},

Expand Down
4 changes: 2 additions & 2 deletions constellix/datasource_constellix_txt_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ func datasourceConstellixTxtRead(d *schema.ResourceData, m interface{}) error {
for _, val := range resrr {
tpMap := make(map[string]interface{})
inner := val.(map[string]interface{})
tpMap["value"] = fmt.Sprintf("%v", inner["value"])
tpMap["disable_flag"] = fmt.Sprintf("%v", inner["disableFlag"])
tpMap["value"] = stripQuotes(inner["value"].(string)) // removing the quotes added by the server during the GET call
tpMap["disable_flag"] = inner["disableFlag"].(bool)
mapListRR = append(mapListRR, tpMap)
}

Expand Down
4 changes: 2 additions & 2 deletions constellix/resource_constellix_a_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func resourceConstellixARecordImport(d *schema.ResourceData, m interface{}) ([]*
d.Set("gtd_region", data["gtdRegion"])
d.Set("type", data["type"])
d.Set("pools", data["pools"])
d.Set("contact_ids", data["contactId"])
d.Set("contact_ids", data["contactIds"])
d.Set("roundrobin", rrlist)
d.Set("roundrobin_failover", rrflist)
d.Set("record_failover_values", rcdflist)
Expand Down Expand Up @@ -540,7 +540,7 @@ func resourceConstellixARecordRead(d *schema.ResourceData, m interface{}) error
d.Set("gtd_region", data["gtdRegion"])
d.Set("type", data["type"])
d.Set("pools", data["pools"])
d.Set("contact_ids", data["contactId"])
d.Set("contact_ids", data["contactIds"])
d.Set("roundrobin", rrlist)
d.Set("roundrobin_failover", rrflist)
d.Set("record_failover_values", rcdflist)
Expand Down
2 changes: 1 addition & 1 deletion constellix/resource_constellix_aaaa_record_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func resourceConstellixAAAArecordPool() *schema.Resource {
},

"weight": &schema.Schema{
Type: schema.TypeInt,
Type: schema.TypeString,
Required: true,
},

Expand Down
34 changes: 6 additions & 28 deletions constellix/resource_constellix_aname_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func resourceConstellixANAMERecordImport(d *schema.ResourceData, m interface{})
d.Set("pools", data["pools"])
d.Set("gtd_region", data["gtdRegion"])
d.Set("type", data["type"])
d.Set("contact_ids", data["contactids"])
d.Set("contact_ids", data["contactIds"])
d.Set("roundrobin", rrlist)
d.Set("record_failover_values", rcdflist)
d.Set("record_failover_failover_type", rcdfSet["record_failover_failover_type"])
Expand Down Expand Up @@ -313,19 +313,8 @@ func resourceConstellixANAMERecordCreate(d *schema.ResourceData, m interface{})
anameAttr.Pools = toListOfInt(pools)
}

if contactids, ok := d.GetOk("contact_ids"); ok {
contactidList := toStringList(contactids.([]interface{}))
var intlist []int
intlist = make([]int, len(contactidList))
for _, i := range contactidList {
j, err := strconv.Atoi(i)
if err != nil {
panic(err)
}
intlist = append(intlist, j)
}

anameAttr.ContactIDs = intlist
if contactid, ok := d.GetOk("contact_ids"); ok {
anameAttr.ContactIDs = toListOfInt(contactid)
}

geoloc := &models.GeolocationANAME{}
Expand Down Expand Up @@ -493,7 +482,7 @@ func resourceConstellixANAMERecordRead(d *schema.ResourceData, m interface{}) er
d.Set("pools", data["pools"])
d.Set("gtd_region", data["gtdRegion"])
d.Set("type", data["type"])
d.Set("contact_ids", data["contactids"])
d.Set("contact_ids", data["contactIds"])
d.Set("roundrobin", rrlist)
d.Set("record_failover_values", rcdflist)
d.Set("record_failover_failover_type", rcdfSet["record_failover_failover_type"])
Expand Down Expand Up @@ -539,19 +528,8 @@ func resourceConstellixANAMERecordUpdate(d *schema.ResourceData, m interface{})
anameAttr.Pools = toListOfInt(pools)
}

if _, ok := d.GetOk("contact_ids"); ok {

contactidslist := toStringList(d.Get("contact_ids").([]interface{}))
var intlist []int
intlist = make([]int, len(contactidslist))
for _, i := range contactidslist {
j, err := strconv.Atoi(i)
if err != nil {
panic(err)
}
intlist = append(intlist, j)
}
anameAttr.ContactIDs = intlist
if contactid, ok := d.GetOk("contact_ids"); ok {
anameAttr.ContactIDs = toListOfInt(contactid)
}

geoloc := &models.GeolocationANAME{}
Expand Down
4 changes: 2 additions & 2 deletions constellix/resource_constellix_cname_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func resourceConstellixCNameRecordImport(d *schema.ResourceData, m interface{})
d.Set("gtd_region", data["gtdRegion"])
d.Set("type", data["type"])
d.Set("pools", data["pools"])
d.Set("contact_ids", data["contactId"])
d.Set("contact_ids", data["contactIds"])
d.Set("record_failover_values", rcdflist)
d.Set("record_failover_failover_type", rcdfset["record_failover_failover_type"])
d.Set("record_failover_disable_flag", rcdfset["record_failover_disable_flag"])
Expand Down Expand Up @@ -436,7 +436,7 @@ func resourceConstellixCNameRecordRead(d *schema.ResourceData, m interface{}) er
d.Set("gtd_region", data["gtdRegion"])
d.Set("type", data["type"])
d.Set("pools", data["pools"])
d.Set("contact_ids", data["contactId"])
d.Set("contact_ids", data["contactIds"])
d.Set("record_failover_values", rcdflist)
d.Set("record_failover_failover_type", rcdfset["record_failover_failover_type"])
d.Set("record_failover_disable_flag", rcdfset["record_failover_disable_flag"])
Expand Down
28 changes: 17 additions & 11 deletions constellix/resource_constellix_contact_lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func resourceConstellixContactList() *schema.Resource {
ForceNew: true,
},
"email_addresses": &schema.Schema{
Type: schema.TypeList,
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
Expand Down Expand Up @@ -59,7 +59,7 @@ func resourceConstellixContactListImport(d *schema.ResourceData, m interface{})

d.SetId(fmt.Sprintf("%.0f", data["id"]))
d.Set("name", data["name"])
d.Set("email_addresses", data["emailAddresses"])
d.Set("email_addresses", data["emailAddresses"].([]interface{}))
log.Printf("[DEBUG] %s finished import", d.Id())
return []*schema.ResourceData{d}, nil
}
Expand All @@ -72,8 +72,12 @@ func resourceConstellixContactListCreate(d *schema.ResourceData, m interface{})
}

if contactemails, ok := d.GetOk("email_addresses"); ok {
contactemailsList := toListOfString(contactemails)
contactlistAttr.EmailAddresses = contactemailsList
var contactemailList = contactemails.(*schema.Set).List()
emailList := make([]string, 0, 1)
for _, val := range contactemailList {
emailList = append(emailList, val.(string))
}
contactlistAttr.EmailAddresses = emailList
}

resp, err := client.Save(contactlistAttr, "v2/contactLists")
Expand All @@ -90,9 +94,8 @@ func resourceConstellixContactListCreate(d *schema.ResourceData, m interface{})
var data map[string]interface{}
json.Unmarshal([]byte(bodystring), &data)
idstruct := data["successContactLists"].([]interface{})[0]
var idStruct map[string]interface{}

idStruct = idstruct.(map[string]interface{})
var idStruct = idstruct.(map[string]interface{})

d.SetId(fmt.Sprintf("%.0f", idStruct["id"]))
return resourceConstellixContactListRead(d, m)
Expand All @@ -104,10 +107,13 @@ func resourceConstellixcontactListUpdate(d *schema.ResourceData, m interface{})

contactlistAttr.Name = d.Get("name").(string)

if _, ok := d.GetOk("email_addresses"); ok {
contactemaillist := toListOfString(d.Get("email_addresses"))
contactlistAttr.EmailAddresses = contactemaillist

if contactemails, ok := d.GetOk("email_addresses"); ok {
var contactemailList = contactemails.(*schema.Set).List()
emailList := make([]string, 0, 1)
for _, val := range contactemailList {
emailList = append(emailList, val.(string))
}
contactlistAttr.EmailAddresses = emailList
}

cid := d.Id()
Expand Down Expand Up @@ -140,7 +146,7 @@ func resourceConstellixContactListRead(d *schema.ResourceData, m interface{}) er

d.SetId(fmt.Sprintf("%.0f", data["id"]))
d.Set("name", data["name"])
d.Set("email_addresses", data["emailAddresses"])
d.Set("email_addresses", data["emailAddresses"].([]interface{}))
return nil
}

Expand Down
112 changes: 64 additions & 48 deletions constellix/resource_constellix_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,26 @@ func resourceConstellixDNSImport(d *schema.ResourceData, m interface{}) ([]*sche
}

soaset := make(map[string]interface{})
soaset["primary_nameserver"] = stripQuotes(obj.S("soa", "primaryNameserver").String())
soaset["ttl"] = stripQuotes(obj.S("soa", "ttl").String())
if value, ok := d.GetOk("soa"); ok {
tp := value.(map[string]interface{})
if tp["email"] != nil {
soaset["email"] = stripQuotes(obj.S("soa", "email").String())
}
}
soaset["refresh"] = stripQuotes(obj.S("soa", "refresh").String())
soaset["expire"] = stripQuotes(obj.S("soa", "expire").String())
soaset["retry"] = stripQuotes(obj.S("soa", "retry").String())
soaset["negcache"] = stripQuotes(obj.S("soa", "negCache").String())

if obj.Exists("soa") {
soaset["primary_nameserver"] = stripQuotes(obj.S("soa", "primaryNameserver").String())
soaset["ttl"] = stripQuotes(obj.S("soa", "ttl").String())
soaset["refresh"] = stripQuotes(obj.S("soa", "refresh").String())
soaset["expire"] = stripQuotes(obj.S("soa", "expire").String())
soaset["retry"] = stripQuotes(obj.S("soa", "retry").String())
soaset["negcache"] = stripQuotes(obj.S("soa", "negCache").String())
}

d.Set("id", stripQuotes(obj.S("id").String()))
d.Set("name", stripQuotes(obj.S("name").String()))
d.Set("soa", soaset)

if hasGeoIP, err := strconv.ParseBool(stripQuotes(obj.S("hasGeoIP").String())); err == nil {
d.Set("has_geoip", hasGeoIP)
}
Expand Down Expand Up @@ -233,10 +237,10 @@ func resourceConstellixDNSCreate(d *schema.ResourceData, m interface{}) error {
soaAttr = &models.Soa{}
tp := value.(map[string]interface{})
if tp["primary_nameserver"] != nil {
soaAttr.PrimaryNameServer = fmt.Sprintf("%v", tp["primary_nameserver"])
soaAttr.PrimaryNameServer = tp["primary_nameserver"].(string)
}
if tp["email"] != nil {
soaAttr.Email = fmt.Sprintf("%v", tp["email"])
soaAttr.Email = tp["email"].(string)
}
if tp["ttl"] != nil {
soaAttr.TTL = tp["ttl"].(string)
Expand Down Expand Up @@ -296,22 +300,25 @@ func resourceConstellixDNSRead(d *schema.ResourceData, m interface{}) error {
}

soaset := make(map[string]interface{})
soaset["primary_nameserver"] = stripQuotes(obj.S("soa", "primaryNameserver").String())
soaset["ttl"] = stripQuotes(obj.S("soa", "ttl").String())
if value, ok := d.GetOk("soa"); ok {
tp := value.(map[string]interface{})
if tp["email"] != nil {
soaset["email"] = stripQuotes(obj.S("soa", "email").String())
}
}
soaset["refresh"] = stripQuotes(obj.S("soa", "refresh").String())
soaset["expire"] = stripQuotes(obj.S("soa", "expire").String())
soaset["retry"] = stripQuotes(obj.S("soa", "retry").String())
soaset["negcache"] = stripQuotes(obj.S("soa", "negCache").String())
if obj.Exists("soa") {
soaset["primary_nameserver"] = stripQuotes(obj.S("soa", "primaryNameserver").String())
soaset["ttl"] = stripQuotes(obj.S("soa", "ttl").String())
soaset["refresh"] = stripQuotes(obj.S("soa", "refresh").String())
soaset["expire"] = stripQuotes(obj.S("soa", "expire").String())
soaset["retry"] = stripQuotes(obj.S("soa", "retry").String())
soaset["negcache"] = stripQuotes(obj.S("soa", "negCache").String())
}

d.Set("id", stripQuotes(obj.S("id").String()))
d.Set("name", stripQuotes(obj.S("name").String()))
d.Set("soa", soaset)

if hasGeoIP, err := strconv.ParseBool(stripQuotes(obj.S("hasGeoIP").String())); err == nil {
d.Set("has_geoip", hasGeoIP)
}
Expand Down Expand Up @@ -342,64 +349,73 @@ func resourceConstellixDNSUpdate(d *schema.ResourceData, m interface{}) error {

domainAttr := models.DomainAttributes{}

domainAttr.HasGtdRegions = d.Get("has_gtd_regions").(bool)
if d.HasChange("has_gtd_regions") {
domainAttr.HasGtdRegions = d.Get("has_gtd_regions").(bool)
}

domainAttr.HasGeoIP = d.Get("has_geoip").(bool)
if d.HasChange("has_geoip") {
domainAttr.HasGeoIP = d.Get("has_geoip").(bool)
}

if vanityNS, ok := d.GetOk("vanity_nameserver"); ok {
domainAttr.VanityNameServer = vanityNS.(string)
if d.HasChange("vanity_nameserver") {
domainAttr.VanityNameServer = d.Get("vanity_nameserver").(string)
}

if _, ok := d.GetOk("nameserver_group"); ok {
if d.HasChange("nameserver_group") {
domainAttr.NameserverGroup = d.Get("nameserver_group").(string)
}

if _, ok := d.GetOk("note"); ok {
if d.HasChange("note") {
domainAttr.Note = d.Get("note").(string)
}

if d.HasChange("tags") {
tagsList := d.Get("tags").([]interface{})
domainAttr.Tags = tagsList
if tg, ok := d.GetOk("tags"); ok {
tagsList := tg.([]interface{})
domainAttr.Tags = tagsList
} else {
domainAttr.Tags = make([]interface{}, 0, 1)
}
}

var soaAttr *models.Soa
if d.HasChange("soa") {
if value, ok := d.GetOk("soa"); ok {
soaAttr = &models.Soa{}
tp := value.(map[string]interface{})
if tp["primary_nameserver"] != nil {
soaAttr.PrimaryNameServer = fmt.Sprintf("%v", tp["primary_nameserver"])
}
if tp["email"] != nil {
soaAttr.Email = fmt.Sprintf("%v", tp["email"])
}
if tp["ttl"] != nil {
soaAttr.TTL = tp["ttl"].(string)
}
if tp["expire"] != nil {
soaAttr.Expire = tp["expire"].(string)
}
if tp["negcache"] != nil {
soaAttr.NegCache = tp["negcache"].(string)
}
if tp["refresh"] != nil {
soaAttr.Refresh = tp["refresh"].(string)
}
if tp["retry"] != nil {
soaAttr.Retry = tp["retry"].(string)
}
}

value := d.Get("soa")
soaAttr = &models.Soa{}
tp := value.(map[string]interface{})
if tp["primary_nameserver"] != nil {
soaAttr.PrimaryNameServer = fmt.Sprintf("%v", tp["primary_nameserver"])
}
if tp["email"] != nil {
soaAttr.Email = fmt.Sprintf("%v", tp["email"])
}
if tp["ttl"] != nil {
soaAttr.TTL = tp["ttl"].(string)
}
if tp["expire"] != nil {
soaAttr.Expire = tp["expire"].(string)
}
if tp["negcache"] != nil {
soaAttr.NegCache = tp["negcache"].(string)
}
if tp["refresh"] != nil {
soaAttr.Refresh = tp["refresh"].(string)
}
if tp["retry"] != nil {
soaAttr.Retry = tp["retry"].(string)
domainAttr.Soa = soaAttr
}

domainAttr.Soa = soaAttr

dn := d.Id()

_, err := constellixClient.UpdatebyID(domainAttr, "v1/domains/"+dn)
if err != nil {
return err
}
return resourceConstellixDNSRead(d, m)

}

func resourceConstellixDNSDelete(d *schema.ResourceData, m interface{}) error {
Expand Down
2 changes: 1 addition & 1 deletion constellix/resource_constellix_geo_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func resourceConstellixIPFilter() *schema.Resource {
Elem: &schema.Schema{
Type: schema.TypeString,
},
Required: true,
Optional: true,
},
"geoip_regions": &schema.Schema{
Type: schema.TypeList,
Expand Down
Loading

0 comments on commit 1b966c3

Please sign in to comment.