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