Skip to content

Commit 12d4c8c

Browse files
yfodiljremy42remyleone
authored
feat(ipam): add address_cidr field (#3468)
* feat(ipam): add address_cidr field * update cassettes --------- Co-authored-by: Jonathan R. <jremy@scaleway.com> Co-authored-by: Rémy Léone <rleone@scaleway.com>
1 parent f4a52e4 commit 12d4c8c

File tree

12 files changed

+5715
-4784
lines changed

12 files changed

+5715
-4784
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/baremetal/server_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ func TestAccServer_WithIPAMPrivateNetwork(t *testing.T) {
996996
Check: resource.ComposeTestCheckFunc(
997997
testAccCheckBaremetalServerExists(tt, "scaleway_baremetal_server.base"),
998998
testAccCheckBaremetalServerHasPrivateNetwork(tt, "scaleway_baremetal_server.base"),
999-
resource.TestCheckResourceAttrPair("scaleway_ipam_ip.ip01", "address", "data.scaleway_ipam_ip.base", "address_cidr"),
999+
resource.TestCheckResourceAttrPair("scaleway_ipam_ip.ip01", "address_cidr", "data.scaleway_ipam_ip.base", "address_cidr"),
10001000
),
10011001
},
10021002
{
@@ -1328,7 +1328,7 @@ func testIPAMIPs(_ *acctest.TestTools, ipamResourcePrefix, ipamDataSource string
13281328
break
13291329
}
13301330

1331-
ip := rs.Primary.Attributes["address"]
1331+
ip := rs.Primary.Attributes["address_cidr"]
13321332
if !expectedIPs[ip] {
13331333
return fmt.Errorf("IP %q from resource %s not found in data source %s", ip, resourceName, ipamDataSource)
13341334
}

internal/services/baremetal/testdata/server-with-ipam-private-network.cassette.yaml

Lines changed: 1735 additions & 1686 deletions
Large diffs are not rendered by default.

internal/services/instance/private_nic_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func TestAccPrivateNIC_WithIPAM(t *testing.T) {
218218
"scaleway_instance_private_nic.pnic01", "ipam_ip_ids.0",
219219
"scaleway_ipam_ip.ip01", "id"),
220220
resource.TestCheckResourceAttrPair(
221-
"scaleway_ipam_ip.ip01", "address",
221+
"scaleway_ipam_ip.ip01", "address_cidr",
222222
"data.scaleway_ipam_ip.by_id", "address_cidr"),
223223
),
224224
},

internal/services/instance/testdata/private-nic-with-ipam.cassette.yaml

Lines changed: 3360 additions & 2387 deletions
Large diffs are not rendered by default.

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
},

internal/services/ipam/testdata/ipamip-basic.cassette.yaml

Lines changed: 147 additions & 198 deletions
Large diffs are not rendered by default.

internal/services/ipam/testdata/ipamip-with-standalone-address.cassette.yaml

Lines changed: 147 additions & 198 deletions
Large diffs are not rendered by default.

internal/services/lb/lb_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ func TestAccLB_WithPrivateNetworksIPAMIDs(t *testing.T) {
417417
"scaleway_lb.lb01", "private_network.0.ipam_ids.0",
418418
"scaleway_ipam_ip.ip01", "id"),
419419
resource.TestCheckResourceAttrPair(
420-
"scaleway_ipam_ip.ip01", "address",
420+
"scaleway_ipam_ip.ip01", "address_cidr",
421421
"data.scaleway_ipam_ip.by_name", "address_cidr"),
422422
resource.TestCheckResourceAttrSet("scaleway_lb.lb01", "private_ips.0.id"),
423423
resource.TestCheckResourceAttrSet("scaleway_lb.lb01", "private_ips.0.address"),

0 commit comments

Comments
 (0)