From 9aea92ac39b003974a58f455081a4aef6e7f26d0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jules=20Cast=C3=A9ran?= <jcasteran@scaleway.com>
Date: Mon, 21 Aug 2023 14:59:29 +0200
Subject: [PATCH] feat(ipam_ip): move resource attribute to a block (#2103)

---
 docs/data-sources/ipam_ip.md         | 12 ++++++-----
 scaleway/data_source_ipam_ip.go      | 30 ++++++++++++++++++----------
 scaleway/data_source_ipam_ip_test.go |  6 ++++--
 3 files changed, 31 insertions(+), 17 deletions(-)

diff --git a/docs/data-sources/ipam_ip.md b/docs/data-sources/ipam_ip.md
index 7ac9d71bc..71d68c402 100644
--- a/docs/data-sources/ipam_ip.md
+++ b/docs/data-sources/ipam_ip.md
@@ -26,8 +26,10 @@ data "scaleway_ipam_ip" "by_mac" {
 
 # Find server private IPv4 using private-nic id
 data "scaleway_ipam_ip" "by_id" {
-  resource_id = scaleway_instance_private_nic.nic.id
-  resource_type = "instance_private_nic"
+  resource {
+    id = scaleway_instance_private_nic.nic.id
+    type = "instance_private_nic"
+  }
   type = "ipv4"
 }
 
@@ -39,9 +41,9 @@ data "scaleway_ipam_ip" "by_id" {
 
 - `private_network_id` - (Optional) The ID of the private network the IP belong to.
 
-- `resource_id` - (Optional) The ID of the resource that the IP is bound to. Require `resource_type`
-
-- `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.
+- `resource` - (Optional) Filter by resource ID and type, both attributes must be set
+    - `id` - The ID of the resource that the IP is bound to.
+    - `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.
 
 - `mac_address` - (Optional) The Mac Address linked to the IP.
 
diff --git a/scaleway/data_source_ipam_ip.go b/scaleway/data_source_ipam_ip.go
index f4870e59b..38aee4339 100644
--- a/scaleway/data_source_ipam_ip.go
+++ b/scaleway/data_source_ipam_ip.go
@@ -20,15 +20,25 @@ func dataSourceScalewayIPAMIP() *schema.Resource {
 				Type:     schema.TypeString,
 				Optional: true,
 			},
-			"resource_id": {
-				Type:     schema.TypeString,
+			"resource": {
+				Type:     schema.TypeList,
 				Optional: true,
-			},
-			"resource_type": {
-				Type:         schema.TypeString,
-				Optional:     true,
-				RequiredWith: []string{"resource_id"},
-				Default:      ipam.ResourceTypeUnknownType,
+				MaxItems: 1,
+				Elem: &schema.Resource{
+					Schema: map[string]*schema.Schema{
+						"id": {
+							Type:         schema.TypeString,
+							Optional:     true,
+							RequiredWith: []string{"resource.0.type"},
+						},
+						"type": {
+							Type:         schema.TypeString,
+							Optional:     true,
+							RequiredWith: []string{"resource.0.id"},
+							Default:      ipam.ResourceTypeUnknownType,
+						},
+					},
+				},
 			},
 			"mac_address": {
 				Type:     schema.TypeString,
@@ -77,8 +87,8 @@ func dataSourceScalewayIPAMIPRead(ctx context.Context, d *schema.ResourceData, m
 		PrivateNetworkID: expandStringPtr(d.Get("private_network_id")),
 		SubnetID:         nil,
 		Attached:         nil,
-		ResourceID:       expandStringPtr(expandLastID(d.Get("resource_id"))),
-		ResourceType:     ipam.ResourceType(d.Get("resource_type").(string)),
+		ResourceID:       expandStringPtr(expandLastID(d.Get("resource.0.id"))),
+		ResourceType:     ipam.ResourceType(d.Get("resource.0.type").(string)),
 		MacAddress:       expandStringPtr(d.Get("mac_address")),
 		ResourceName:     nil,
 		ResourceIDs:      nil,
diff --git a/scaleway/data_source_ipam_ip_test.go b/scaleway/data_source_ipam_ip_test.go
index 50dc0adf9..30873ad57 100644
--- a/scaleway/data_source_ipam_ip_test.go
+++ b/scaleway/data_source_ipam_ip_test.go
@@ -43,8 +43,10 @@ func TestAccScalewayDataSourceIPAMIP_Instance(t *testing.T) {
 					}
 
 					data "scaleway_ipam_ip" "by_id" {
-						resource_id = scaleway_instance_private_nic.main.id
-						resource_type = "instance_private_nic"
+						resource {
+							id = scaleway_instance_private_nic.main.id
+							type = "instance_private_nic"
+						}
 						type = "ipv4"
 					}`,
 				Check: resource.ComposeTestCheckFunc(