|
4 | 4 | "errors" |
5 | 5 | "strconv" |
6 | 6 |
|
7 | | - "github.com/hashicorp/terraform/helper/schema" |
8 | 7 | "github.com/Ouest-France/phpipam-sdk-go/controllers/addresses" |
9 | 8 | "github.com/Ouest-France/phpipam-sdk-go/phpipam" |
| 9 | + "github.com/hashicorp/terraform/helper/schema" |
10 | 10 | ) |
11 | 11 |
|
12 | 12 | // resourceAddressOptionalFields represents all the fields that are optional in |
@@ -196,25 +196,37 @@ func expandAddress(d *schema.ResourceData) addresses.Address { |
196 | 196 |
|
197 | 197 | // flattenAddress sets fields in a *schema.ResourceData with fields supplied by |
198 | 198 | // the input addresses.Address. This is used in read operations. |
199 | | -func flattenAddress(a addresses.Address, d *schema.ResourceData) { |
| 199 | +func flattenAddress(a addresses.Address, d *schema.ResourceData) error { |
200 | 200 | d.SetId(strconv.Itoa(a.ID)) |
201 | | - d.Set("address_id", a.ID) |
202 | | - d.Set("subnet_id", a.SubnetID) |
203 | | - d.Set("ip_address", a.IPAddress) |
204 | | - d.Set("is_gateway", a.IsGateway) |
205 | | - d.Set("description", a.Description) |
206 | | - d.Set("hostname", a.Hostname) |
207 | | - d.Set("mac_address", a.MACAddress) |
208 | | - d.Set("owner", a.Owner) |
209 | | - d.Set("state_tag_id", a.Tag) |
210 | | - d.Set("skip_ptr_record", a.PTRIgnore) |
211 | | - d.Set("ptr_record_id", a.PTRRecordID) |
212 | | - d.Set("device_id", a.DeviceID) |
213 | | - d.Set("switch_port_label", a.Port) |
214 | | - d.Set("note", a.Note) |
215 | | - d.Set("last_seen", a.LastSeen) |
216 | | - d.Set("exclude_ping", a.ExcludePing) |
217 | | - d.Set("edit_date", a.EditDate) |
| 201 | + |
| 202 | + fields := map[string]interface{}{ |
| 203 | + "address_id": a.ID, |
| 204 | + "subnet_id": a.SubnetID, |
| 205 | + "ip_address": a.IPAddress, |
| 206 | + "is_gateway": a.IsGateway, |
| 207 | + "description": a.Description, |
| 208 | + "hostname": a.Hostname, |
| 209 | + "mac_address": a.MACAddress, |
| 210 | + "owner": a.Owner, |
| 211 | + "state_tag_id": a.Tag, |
| 212 | + "skip_ptr_record": a.PTRIgnore, |
| 213 | + "ptr_record_id": a.PTRRecordID, |
| 214 | + "device_id": a.DeviceID, |
| 215 | + "switch_port_label": a.Port, |
| 216 | + "note": a.Note, |
| 217 | + "last_seen": a.LastSeen, |
| 218 | + "exclude_ping": a.ExcludePing, |
| 219 | + "edit_date": a.EditDate, |
| 220 | + } |
| 221 | + |
| 222 | + for field, value := range fields { |
| 223 | + err := d.Set(field, value) |
| 224 | + if err != nil { |
| 225 | + return err |
| 226 | + } |
| 227 | + } |
| 228 | + |
| 229 | + return nil |
218 | 230 | } |
219 | 231 |
|
220 | 232 | // addressSearchInSubnet provides the address search functionality for both the |
|
0 commit comments