Skip to content

Commit f91eb44

Browse files
committed
support custom resource
1 parent 4204b3a commit f91eb44

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

internal/services/ipam/ip.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,27 @@ func ResourceIP() *schema.Resource {
6868
},
6969
},
7070
},
71+
"custom_resource": {
72+
Type: schema.TypeList,
73+
Optional: true,
74+
ForceNew: true,
75+
Description: "The custom resource in which to book the IP",
76+
Elem: &schema.Resource{
77+
Schema: map[string]*schema.Schema{
78+
"mac_address": {
79+
Type: schema.TypeString,
80+
Required: true,
81+
Description: "MAC address of the custom resource",
82+
ValidateFunc: validation.IsMACAddress,
83+
},
84+
"name": {
85+
Type: schema.TypeString,
86+
Optional: true,
87+
Description: "When the resource is in a Private Network, a DNS record is available to resolve the resource name",
88+
},
89+
},
90+
},
91+
},
7192
"is_ipv6": {
7293
Type: schema.TypeBool,
7394
Optional: true,
@@ -179,6 +200,10 @@ func ResourceIPAMIPCreate(ctx context.Context, d *schema.ResourceData, m interfa
179200
req.Source = expandIPSource(source)
180201
}
181202

203+
if customResource, ok := d.GetOk("custom_resource"); ok {
204+
req.Resource = expandCustomResource(customResource)
205+
}
206+
182207
res, err := ipamAPI.BookIP(req, scw.WithContext(ctx))
183208
if err != nil {
184209
return diag.FromErr(err)

internal/services/ipam/types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ func expandIPSource(raw interface{}) *ipam.Source {
4141
}
4242
}
4343

44+
func expandCustomResource(raw interface{}) *ipam.CustomResource {
45+
if raw == nil || len(raw.([]interface{})) != 1 {
46+
return nil
47+
}
48+
49+
rawMap := raw.([]interface{})[0].(map[string]interface{})
50+
return &ipam.CustomResource{
51+
MacAddress: rawMap["mac_address"].(string),
52+
Name: types.ExpandStringPtr(rawMap["name"].(string)),
53+
}
54+
}
55+
4456
func flattenIPSource(source *ipam.Source, privateNetworkID string) interface{} {
4557
if source == nil {
4658
return nil

0 commit comments

Comments
 (0)