Skip to content

Commit

Permalink
feat(ipam_ip): move resource attribute to a block (#2103)
Browse files Browse the repository at this point in the history
  • Loading branch information
Codelax authored Aug 21, 2023
1 parent e8d1e37 commit 9aea92a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
12 changes: 7 additions & 5 deletions docs/data-sources/ipam_ip.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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.

Expand Down
30 changes: 20 additions & 10 deletions scaleway/data_source_ipam_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions scaleway/data_source_ipam_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 9aea92a

Please sign in to comment.