@@ -1031,8 +1031,7 @@ func TestAccServer_WithIPAMPrivateNetwork(t *testing.T) {
1031
1031
Check : resource .ComposeTestCheckFunc (
1032
1032
testAccCheckBaremetalServerExists (tt , "scaleway_baremetal_server.base" ),
1033
1033
testAccCheckBaremetalServerHasPrivateNetwork (tt , "scaleway_baremetal_server.base" ),
1034
- resource .TestCheckResourceAttrPair ("scaleway_ipam_ip.ip01" , "address" , "data.scaleway_ipam_ips.base" , "ips.0.address" ),
1035
- resource .TestCheckResourceAttrPair ("scaleway_ipam_ip.ip02" , "address" , "data.scaleway_ipam_ips.base" , "ips.1.address" ),
1034
+ testIPAMIPs (tt , "scaleway_ipam_ip" , "data.scaleway_ipam_ips.base" ),
1036
1035
),
1037
1036
},
1038
1037
},
@@ -1256,3 +1255,42 @@ func testAccCheckBaremetalServerHasPrivateNetwork(tt *acctest.TestTools, n strin
1256
1255
return nil
1257
1256
}
1258
1257
}
1258
+
1259
+ func testIPAMIPs (_ * acctest.TestTools , ipamResourcePrefix , ipamDataSource string ) resource.TestCheckFunc {
1260
+ return func (s * terraform.State ) error {
1261
+ ipamData , ok := s .RootModule ().Resources [ipamDataSource ]
1262
+ if ! ok {
1263
+ return fmt .Errorf ("not found: %s" , ipamDataSource )
1264
+ }
1265
+
1266
+ ips := ipamData .Primary .Attributes
1267
+ expectedIPs := make (map [string ]bool )
1268
+
1269
+ for i := 0 ; ; i ++ {
1270
+ key := fmt .Sprintf ("ips.%d.address" , i )
1271
+
1272
+ ip , ok := ips [key ]
1273
+ if ! ok {
1274
+ break
1275
+ }
1276
+
1277
+ expectedIPs [ip ] = true
1278
+ }
1279
+
1280
+ for y := 1 ; ; y ++ {
1281
+ resourceName := fmt .Sprintf ("%s.ip0%d" , ipamResourcePrefix , y )
1282
+
1283
+ rs , ok := s .RootModule ().Resources [resourceName ]
1284
+ if ! ok {
1285
+ break
1286
+ }
1287
+
1288
+ ip := rs .Primary .Attributes ["address" ]
1289
+ if ! expectedIPs [ip ] {
1290
+ return fmt .Errorf ("IP %q from resource %s not found in data source %s" , ip , resourceName , ipamDataSource )
1291
+ }
1292
+ }
1293
+
1294
+ return nil
1295
+ }
1296
+ }
0 commit comments