Skip to content

Commit

Permalink
Merge pull request #72 from lord-kyron/data_source_vlan_custom_field_fix
Browse files Browse the repository at this point in the history
Fix error for vlans where custom field not defined
  • Loading branch information
lord-kyron authored May 16, 2023
2 parents 0f1c95d + 957af84 commit a403bef
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions plugin/providers/phpipam/data_source_phpipam_vlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,29 @@ func dataSourcePHPIPAMVLANRead(d *schema.ResourceData, meta interface{}) error {
return errors.New("vlan_id or number not defined, cannot proceed with reading data")
}

fields, err := c.GetVLANCustomFields(out.ID)
switch {
case err == nil:
trimMap(fields)
if err := d.Set("custom_fields", fields); err != nil {
if checkVlansCustomFiledsExists(d, c) {
fields, err := c.GetVLANCustomFields(out.ID)
switch {
case err == nil:
trimMap(fields)
if err := d.Set("custom_fields", fields); err != nil {
return err
}
case err != nil:
return err
}
case err != nil:
return err
}

flattenVLAN(out, d)
return nil
}

func checkVlansCustomFiledsExists(d *schema.ResourceData, client *vlans.Controller) bool {
if _, ok := d.GetOk("custom_field_filter"); ok {
return true
} else if _, err := client.GetVLANCustomFieldsSchema(); err == nil {
return true
} else {
return false
}
}

0 comments on commit a403bef

Please sign in to comment.