Skip to content

Commit 32c8c93

Browse files
yfodilquantumsheep
andauthored
feat(baremetal): add ipv4 & ipv6 fields (#2003)
* feat(baremetal): add ipv4 & ipv6 fields * update doc * fix * Update lbacl-basic.cassette.yaml * Update lbacl-basic.cassette.yaml * Update lbacl-basic.cassette.yaml * Update docs/resources/baremetal_server.md Co-authored-by: Nathanael Demacon <[email protected]> * refactor --------- Co-authored-by: Nathanael Demacon <[email protected]>
1 parent 0fa1d1f commit 32c8c93

19 files changed

+53315
-37516
lines changed

docs/resources/baremetal_server.md

+10
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ In addition to all above arguments, the following attributes are exported:
166166
- `address` - The address of the IP.
167167
- `reverse` - The reverse of the IP.
168168
- `version` - The type of the IP.
169+
- `ipv4` - (List of) The IPv4 addresses of the server.
170+
- `id` - The ID of the IPv4.
171+
- `address` - The address of the IPv4.
172+
- `reverse` - The reverse of the IPv4.
173+
- `version` - The type of the IPv4.
174+
- `ipv6` - (List of) The IPv6 addresses of the server.
175+
- `id` - The ID of the IPv6.
176+
- `address` - The address of the IPv6.
177+
- `reverse` - The reverse of the IPv6.
178+
- `version` - The type of the IPv6.
169179
- `domain` - The domain of the server.
170180
- `organization_id` - The organization ID the server is associated with.
171181

scaleway/helpers_baremetal.go

+36
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,42 @@ func flattenBaremetalIPs(ips []*baremetal.IP) interface{} {
160160
return flattendIPs
161161
}
162162

163+
func flattenBaremetalIPv4s(ips []*baremetal.IP) interface{} {
164+
if ips == nil {
165+
return nil
166+
}
167+
flattendIPs := []map[string]interface{}(nil)
168+
for _, ip := range ips {
169+
if ip.Version == baremetal.IPVersionIPv4 {
170+
flattendIPs = append(flattendIPs, map[string]interface{}{
171+
"id": ip.ID,
172+
"address": ip.Address.String(),
173+
"reverse": ip.Reverse,
174+
"version": ip.Version.String(),
175+
})
176+
}
177+
}
178+
return flattendIPs
179+
}
180+
181+
func flattenBaremetalIPv6s(ips []*baremetal.IP) interface{} {
182+
if ips == nil {
183+
return nil
184+
}
185+
flattendIPs := []map[string]interface{}(nil)
186+
for _, ip := range ips {
187+
if ip.Version == baremetal.IPVersionIPv6 {
188+
flattendIPs = append(flattendIPs, map[string]interface{}{
189+
"id": ip.ID,
190+
"address": ip.Address.String(),
191+
"reverse": ip.Reverse,
192+
"version": ip.Version.String(),
193+
})
194+
}
195+
}
196+
return flattendIPs
197+
}
198+
163199
func flattenBaremetalOptions(zone scw.Zone, options []*baremetal.ServerOption) interface{} {
164200
if options == nil {
165201
return nil

scaleway/resource_baremetal_server.go

+45-26
Original file line numberDiff line numberDiff line change
@@ -132,32 +132,22 @@ If this behaviour is wanted, please set 'reinstall_on_ssh_key_changes' argument
132132
"organization_id": organizationIDSchema(),
133133
"project_id": projectIDSchema(),
134134
"ips": {
135-
Type: schema.TypeList,
136-
Computed: true,
137-
Elem: &schema.Resource{
138-
Schema: map[string]*schema.Schema{
139-
"id": {
140-
Type: schema.TypeString,
141-
Computed: true,
142-
Description: "The ID of the IP",
143-
},
144-
"version": {
145-
Type: schema.TypeString,
146-
Computed: true,
147-
Description: "The version of the IP",
148-
},
149-
"address": {
150-
Type: schema.TypeString,
151-
Computed: true,
152-
Description: "The IP address of the IP",
153-
},
154-
"reverse": {
155-
Type: schema.TypeString,
156-
Computed: true,
157-
Description: "The Reverse of the IP",
158-
},
159-
},
160-
},
135+
Type: schema.TypeList,
136+
Computed: true,
137+
Description: "IP addresses attached to the server.",
138+
Elem: resourceScalewayBaremetalServerIP(),
139+
},
140+
"ipv4": {
141+
Type: schema.TypeList,
142+
Computed: true,
143+
Description: "IPv4 addresses attached to the server",
144+
Elem: resourceScalewayBaremetalServerIP(),
145+
},
146+
"ipv6": {
147+
Type: schema.TypeList,
148+
Computed: true,
149+
Description: "IPv6 addresses attached to the server",
150+
Elem: resourceScalewayBaremetalServerIP(),
161151
},
162152
"domain": {
163153
Type: schema.TypeString,
@@ -235,6 +225,33 @@ If this behaviour is wanted, please set 'reinstall_on_ssh_key_changes' argument
235225
}
236226
}
237227

228+
func resourceScalewayBaremetalServerIP() *schema.Resource {
229+
return &schema.Resource{
230+
Schema: map[string]*schema.Schema{
231+
"id": {
232+
Type: schema.TypeString,
233+
Computed: true,
234+
Description: "The ID of the IPv6",
235+
},
236+
"version": {
237+
Type: schema.TypeString,
238+
Computed: true,
239+
Description: "The version of the IPv6",
240+
},
241+
"address": {
242+
Type: schema.TypeString,
243+
Computed: true,
244+
Description: "The IPv6 address",
245+
},
246+
"reverse": {
247+
Type: schema.TypeString,
248+
Computed: true,
249+
Description: "The Reverse of the IPv6",
250+
},
251+
},
252+
}
253+
}
254+
238255
func resourceScalewayBaremetalServerCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
239256
baremetalAPI, zone, err := baremetalAPIWithZone(d, meta)
240257
if err != nil {
@@ -396,6 +413,8 @@ func resourceScalewayBaremetalServerRead(ctx context.Context, d *schema.Resource
396413
_ = d.Set("tags", server.Tags)
397414
_ = d.Set("domain", server.Domain)
398415
_ = d.Set("ips", flattenBaremetalIPs(server.IPs))
416+
_ = d.Set("ipv4", flattenBaremetalIPv4s(server.IPs))
417+
_ = d.Set("ipv6", flattenBaremetalIPv6s(server.IPs))
399418
if server.Install != nil {
400419
_ = d.Set("os", newZonedIDString(server.Zone, os.ID))
401420
_ = d.Set("os_name", os.Name)

scaleway/resource_baremetal_server_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ func TestAccScalewayBaremetalServer_CreateServerWithOption(t *testing.T) {
212212
testAccCheckScalewayBaremetalServerExists(tt, "scaleway_baremetal_server.base"),
213213
testAccCheckScalewayBaremetalServerHasOptions(tt, "scaleway_baremetal_server.base"),
214214
resource.TestCheckResourceAttrPair("scaleway_baremetal_server.base", "options.0.id", "data.scaleway_baremetal_option.private_network", "option_id"),
215+
resource.TestCheckResourceAttr("scaleway_baremetal_server.base", "ips.#", "2"),
216+
resource.TestCheckResourceAttr("scaleway_baremetal_server.base", "ipv4.#", "1"),
217+
resource.TestCheckResourceAttr("scaleway_baremetal_server.base", "ipv4.0.version", "IPv4"),
218+
resource.TestCheckResourceAttr("scaleway_baremetal_server.base", "ipv6.#", "1"),
219+
resource.TestCheckResourceAttr("scaleway_baremetal_server.base", "ipv6.0.version", "IPv6"),
215220
),
216221
},
217222
},

0 commit comments

Comments
 (0)