Skip to content

Commit 9aea92a

Browse files
authored
feat(ipam_ip): move resource attribute to a block (#2103)
1 parent e8d1e37 commit 9aea92a

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

docs/data-sources/ipam_ip.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ data "scaleway_ipam_ip" "by_mac" {
2626
2727
# Find server private IPv4 using private-nic id
2828
data "scaleway_ipam_ip" "by_id" {
29-
resource_id = scaleway_instance_private_nic.nic.id
30-
resource_type = "instance_private_nic"
29+
resource {
30+
id = scaleway_instance_private_nic.nic.id
31+
type = "instance_private_nic"
32+
}
3133
type = "ipv4"
3234
}
3335
@@ -39,9 +41,9 @@ data "scaleway_ipam_ip" "by_id" {
3941

4042
- `private_network_id` - (Optional) The ID of the private network the IP belong to.
4143

42-
- `resource_id` - (Optional) The ID of the resource that the IP is bound to. Require `resource_type`
43-
44-
- `resource_type` - (Optional) The type of the resource to get the IP from. Required with `resource_id`. [Documentation](https://pkg.go.dev/github.com/scaleway/scaleway-sdk-go@master/api/ipam/v1alpha1#pkg-constants) with type list.
44+
- `resource` - (Optional) Filter by resource ID and type, both attributes must be set
45+
- `id` - The ID of the resource that the IP is bound to.
46+
- `type` - The type of the resource to get the IP from. [Documentation](https://pkg.go.dev/github.com/scaleway/scaleway-sdk-go@master/api/ipam/v1alpha1#pkg-constants) with type list.
4547

4648
- `mac_address` - (Optional) The Mac Address linked to the IP.
4749

scaleway/data_source_ipam_ip.go

+20-10
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,25 @@ func dataSourceScalewayIPAMIP() *schema.Resource {
2020
Type: schema.TypeString,
2121
Optional: true,
2222
},
23-
"resource_id": {
24-
Type: schema.TypeString,
23+
"resource": {
24+
Type: schema.TypeList,
2525
Optional: true,
26-
},
27-
"resource_type": {
28-
Type: schema.TypeString,
29-
Optional: true,
30-
RequiredWith: []string{"resource_id"},
31-
Default: ipam.ResourceTypeUnknownType,
26+
MaxItems: 1,
27+
Elem: &schema.Resource{
28+
Schema: map[string]*schema.Schema{
29+
"id": {
30+
Type: schema.TypeString,
31+
Optional: true,
32+
RequiredWith: []string{"resource.0.type"},
33+
},
34+
"type": {
35+
Type: schema.TypeString,
36+
Optional: true,
37+
RequiredWith: []string{"resource.0.id"},
38+
Default: ipam.ResourceTypeUnknownType,
39+
},
40+
},
41+
},
3242
},
3343
"mac_address": {
3444
Type: schema.TypeString,
@@ -77,8 +87,8 @@ func dataSourceScalewayIPAMIPRead(ctx context.Context, d *schema.ResourceData, m
7787
PrivateNetworkID: expandStringPtr(d.Get("private_network_id")),
7888
SubnetID: nil,
7989
Attached: nil,
80-
ResourceID: expandStringPtr(expandLastID(d.Get("resource_id"))),
81-
ResourceType: ipam.ResourceType(d.Get("resource_type").(string)),
90+
ResourceID: expandStringPtr(expandLastID(d.Get("resource.0.id"))),
91+
ResourceType: ipam.ResourceType(d.Get("resource.0.type").(string)),
8292
MacAddress: expandStringPtr(d.Get("mac_address")),
8393
ResourceName: nil,
8494
ResourceIDs: nil,

scaleway/data_source_ipam_ip_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ func TestAccScalewayDataSourceIPAMIP_Instance(t *testing.T) {
4343
}
4444
4545
data "scaleway_ipam_ip" "by_id" {
46-
resource_id = scaleway_instance_private_nic.main.id
47-
resource_type = "instance_private_nic"
46+
resource {
47+
id = scaleway_instance_private_nic.main.id
48+
type = "instance_private_nic"
49+
}
4850
type = "ipv4"
4951
}`,
5052
Check: resource.ComposeTestCheckFunc(

0 commit comments

Comments
 (0)