Skip to content

Commit

Permalink
update metal ip rs/ds to check metro from facility if metro is null
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar Cobles committed Nov 17, 2022
1 parent 3a521d4 commit 8d4fe0b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion equinix/data_source_metal_ip_block_ranges.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ func metroMatch(ref string, metro *packngo.Metro) bool {
return false
}

func metroOffacilityMatch(ref string, facility *packngo.Facility) bool {
if ref == "" {
return true
}
if facility != nil && facility.Metro != nil && ref == facility.Metro.Code {
return true
}
return false
}

func dataSourceMetalIPBlockRangesRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Config).metal
projectID := d.Get("project_id").(string)
Expand Down Expand Up @@ -109,7 +119,7 @@ func dataSourceMetalIPBlockRangesRead(d *schema.ResourceData, meta interface{})
} else {
targetSlice = &theIPv6s
}
if targetSlice != nil && facilityMatch(facility, ip.Facility) && metroMatch(metro, ip.Metro) {
if targetSlice != nil && facilityMatch(facility, ip.Facility) && metroMatch(metro, ip.Metro) && metroOffacilityMatch(metro, ip.Facility) {
*targetSlice = append(*targetSlice, cnStr)
}
}
Expand Down
2 changes: 1 addition & 1 deletion equinix/resource_metal_reserved_ip_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func loadBlock(d *schema.ResourceData, reservedBlock *packngo.IPAddressReservati
},
"metro": func(d *schema.ResourceData, k string) error {
if reservedBlock.Metro == nil {
if reservedBlock.Facility != nil {
if reservedBlock.Facility != nil && reservedBlock.Facility.Metro != nil {
return d.Set(k, strings.ToLower(reservedBlock.Facility.Metro.Code))
}
return nil
Expand Down

0 comments on commit 8d4fe0b

Please sign in to comment.