@@ -2,6 +2,7 @@ package scaleway
22
33import (
44 "fmt"
5+ "strings"
56 "testing"
67
78 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -402,7 +403,7 @@ func TestAccScalewayK8SCluster_PrivateNetwork(t *testing.T) {
402403 Check : resource .ComposeTestCheckFunc (
403404 testAccCheckScalewayK8SClusterExists (tt , "scaleway_k8s_cluster.private_network" ),
404405 testAccCheckScalewayVPCPrivateNetworkExists (tt , "scaleway_vpc_private_network.private_network" ),
405- resource . TestCheckResourceAttrPair ( "scaleway_k8s_cluster.private_network" , "private_network_id" , " scaleway_vpc_private_network.private_network" , "id " ),
406+ testAccCheckScalewayK8sClusterPrivateNetworkID ( tt , "scaleway_k8s_cluster.private_network" , "scaleway_vpc_private_network.private_network" ),
406407 ),
407408 },
408409 },
@@ -488,6 +489,49 @@ func testAccCheckScalewayK8SClusterExists(tt *TestTools, n string) resource.Test
488489 }
489490}
490491
492+ func testAccCheckScalewayK8sClusterPrivateNetworkID (tt * TestTools , clusterName , pnName string ) resource.TestCheckFunc {
493+ return func (s * terraform.State ) error {
494+ rs , ok := s .RootModule ().Resources [clusterName ]
495+ if ! ok {
496+ return fmt .Errorf ("resource not found: %s" , clusterName )
497+ }
498+
499+ k8sAPI , region , clusterID , err := k8sAPIWithRegionAndID (tt .Meta , rs .Primary .ID )
500+ if err != nil {
501+ return err
502+ }
503+
504+ cluster , err := k8sAPI .GetCluster (& k8s.GetClusterRequest {
505+ Region : region ,
506+ ClusterID : clusterID ,
507+ })
508+ if err != nil {
509+ return err
510+ }
511+
512+ clusterPNID := cluster .PrivateNetworkID
513+
514+ rs , ok = s .RootModule ().Resources [pnName ]
515+ if ! ok {
516+ return fmt .Errorf ("resource not found: %s" , pnName )
517+ }
518+
519+ _ , zone , pnID , err := vpcAPIWithZoneAndID (tt .Meta , rs .Primary .ID )
520+ if err != nil {
521+ return err
522+ }
523+
524+ if clusterPNID == nil {
525+ return fmt .Errorf ("expected %s private_network_id to be %s, got nil" , clusterName , strings .TrimLeft (pnID , zone .String ()+ "/" ))
526+ }
527+ if * clusterPNID != strings .TrimLeft (pnID , zone .String ()+ "/" ) {
528+ return fmt .Errorf ("expected %s private_network_id to be %s, got %s" , clusterName , strings .TrimLeft (pnID , zone .String ()+ "/" ), * clusterPNID )
529+ }
530+
531+ return nil
532+ }
533+ }
534+
491535func testAccCheckScalewayK8SClusterConfigMinimal (version string ) string {
492536 return fmt .Sprintf (`
493537resource "scaleway_k8s_cluster" "minimal" {
0 commit comments