Skip to content
Draft
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
19 changes: 13 additions & 6 deletions ns1/resource_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,18 +315,14 @@ func recordToResourceData(d *schema.ResourceData, r *dns.Record) error {
}
}
if len(r.Regions) > 0 {
regions := make([]map[string]interface{}, 0, len(r.Regions))
regions := schema.NewSet(regionHash, nil)
for name, region := range r.Regions {
newRegion := make(map[string]interface{})
newRegion["name"] = name
newRegion["meta"] = region.Meta.StringMap()
regions = append(regions, newRegion)
regions.Add(newRegion)
}
log.Printf("Setting regions %+v", regions)
err := d.Set("regions", regions)
if err != nil {
return fmt.Errorf("[DEBUG] Error setting regions for: %s, error: %#v", r.Domain, err)
}
}
return nil
}
Expand Down Expand Up @@ -801,3 +797,14 @@ func subdivisionConverter(s string) (map[string]interface{}, error) {

return subdivisionsMap, nil
}

// regions are maps, but the names should be unique, so use the name as index
func regionHash(i interface{}) int {
if m, ok := i.(map[string]interface{}); ok {
if n, ok := m["name"].(string); ok {
return schema.HashString(n)
}
}
// if the name is missing
return 0
}
10 changes: 9 additions & 1 deletion ns1/resource_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,12 @@ func TestAccRecord_updatedWithRegions(t *testing.T) {
),
),
},
{
// Plan again to detect "loop" conditions
Config: testAccRecordUpdatedWithRegionWeight(rString),
PlanOnly: true,
ExpectNonEmptyPlan: false,
},
{
Config: testAccRecordUpdatedWithRegions(rString),
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -1903,7 +1909,9 @@ resource "ns1_record" "it" {
regions {
name = "cal"
meta = {
weight = 100
country = "RU,CA,MX,US"
georegion = "EUROPE,US-CENTRAL,US-WEST,AFRICA,US-EAST"
weight = 100
}
}

Expand Down
Loading