Skip to content

Commit e6169c3

Browse files
committed
feat(ipam): add address_cidr field
1 parent 122b030 commit e6169c3

File tree

6 files changed

+307
-398
lines changed

6 files changed

+307
-398
lines changed

docs/resources/ipam_ip.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ The following arguments are supported:
126126
In addition to all arguments above, the following attributes are exported:
127127

128128
- `id` - The ID of the IP in IPAM.
129+
- `address_cidr` - the IP address in CIDR notation.
129130
- `resource` - The IP resource.
130131
- `id` - The ID of the resource that the IP is attached to.
131132
- `type` - The type of resource the IP is attached to.

internal/services/ipam/ip.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ func ResourceIP() *schema.Resource {
4040
ValidateFunc: validation.IsIPAddress,
4141
DiffSuppressFunc: dsf.DiffSuppressFuncStandaloneIPandCIDR,
4242
},
43+
"address_cidr": {
44+
Type: schema.TypeString,
45+
Computed: true,
46+
Description: "The IP address with a CIDR notation",
47+
},
4348
"source": {
4449
Type: schema.TypeList,
4550
Required: true,
@@ -269,12 +274,14 @@ func ResourceIPAMIPRead(ctx context.Context, d *schema.ResourceData, m any) diag
269274
}
270275
}
271276

272-
address, err := types.FlattenIPNet(res.Address)
277+
addressCidr, err := types.FlattenIPNet(res.Address)
273278
if err != nil {
274279
return diag.FromErr(err)
275280
}
276281

282+
address := res.Address.IP.String()
277283
_ = d.Set("address", address)
284+
_ = d.Set("address_cidr", addressCidr)
278285
_ = d.Set("source", flattenIPSource(res.Source, privateNetworkID))
279286
_ = d.Set("resource", flattenIPResource(res.Resource))
280287
_ = d.Set("project_id", res.ProjectID)

internal/services/ipam/ip_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func TestAccIPAMIP_Basic(t *testing.T) {
4545
acctest.CheckResourceRawIDMatches("scaleway_ipam_ip.ip01", "source.0.private_network_id", "scaleway_vpc_private_network.pn01", "id"),
4646
resource.TestCheckResourceAttrSet("scaleway_ipam_ip.ip01", "source.0.subnet_id"),
4747
resource.TestCheckResourceAttrSet("scaleway_ipam_ip.ip01", "address"),
48+
resource.TestCheckResourceAttrSet("scaleway_ipam_ip.ip01", "address_cidr"),
4849
resource.TestCheckResourceAttrSet("scaleway_ipam_ip.ip01", "created_at"),
4950
resource.TestCheckResourceAttrSet("scaleway_ipam_ip.ip01", "updated_at"),
5051
),
@@ -83,7 +84,8 @@ func TestAccIPAMIP_WithStandaloneAddress(t *testing.T) {
8384
`,
8485
Check: resource.ComposeTestCheckFunc(
8586
testAccCheckIPAMIPExists(tt, "scaleway_ipam_ip.ip01"),
86-
resource.TestCheckResourceAttr("scaleway_ipam_ip.ip01", "address", "172.16.32.7/22"),
87+
resource.TestCheckResourceAttr("scaleway_ipam_ip.ip01", "address", "172.16.32.7"),
88+
resource.TestCheckResourceAttr("scaleway_ipam_ip.ip01", "address_cidr", "172.16.32.7/22"),
8789
),
8890
},
8991
},

0 commit comments

Comments
 (0)