Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions internal/services/baremetal/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1031,8 +1031,7 @@ func TestAccServer_WithIPAMPrivateNetwork(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckBaremetalServerExists(tt, "scaleway_baremetal_server.base"),
testAccCheckBaremetalServerHasPrivateNetwork(tt, "scaleway_baremetal_server.base"),
resource.TestCheckResourceAttrPair("scaleway_ipam_ip.ip01", "address", "data.scaleway_ipam_ips.base", "ips.0.address"),
resource.TestCheckResourceAttrPair("scaleway_ipam_ip.ip02", "address", "data.scaleway_ipam_ips.base", "ips.1.address"),
testIPAMIPs(tt, "scaleway_ipam_ip", "data.scaleway_ipam_ips.base"),
),
},
},
Expand Down Expand Up @@ -1256,3 +1255,42 @@ func testAccCheckBaremetalServerHasPrivateNetwork(tt *acctest.TestTools, n strin
return nil
}
}

func testIPAMIPs(_ *acctest.TestTools, ipamResourcePrefix, ipamDataSource string) resource.TestCheckFunc {
return func(s *terraform.State) error {
ipamData, ok := s.RootModule().Resources[ipamDataSource]
if !ok {
return fmt.Errorf("not found: %s", ipamDataSource)
}

ips := ipamData.Primary.Attributes
expectedIPs := make(map[string]bool)

for i := 0; ; i++ {
key := fmt.Sprintf("ips.%d.address", i)

ip, ok := ips[key]
if !ok {
break
}

expectedIPs[ip] = true
}

for y := 1; ; y++ {
resourceName := fmt.Sprintf("%s.ip0%d", ipamResourcePrefix, y)

rs, ok := s.RootModule().Resources[resourceName]
if !ok {
break
}

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

return nil
}
}
Loading
Loading