@@ -12,6 +12,7 @@ import (
1212 "github.com/scaleway/terraform-provider-scaleway/v2/internal/acctest"
1313 "github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
1414 "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/function"
15+ vpcchecks "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/vpc/testfuncs"
1516)
1617
1718func TestAccFunction_Basic (t * testing.T ) {
@@ -410,6 +411,146 @@ func TestAccFunction_Sandbox(t *testing.T) {
410411 })
411412}
412413
414+ func TestAccFunction_PrivateNetwork (t * testing.T ) {
415+ tt := acctest .NewTestTools (t )
416+ defer tt .Cleanup ()
417+ resource .ParallelTest (t , resource.TestCase {
418+ PreCheck : func () { acctest .PreCheck (t ) },
419+ ProviderFactories : tt .ProviderFactories ,
420+ CheckDestroy : resource .ComposeTestCheckFunc (
421+ testAccCheckFunctionNamespaceDestroy (tt ),
422+ testAccCheckFunctionDestroy (tt ),
423+ vpcchecks .CheckPrivateNetworkDestroy (tt ),
424+ ),
425+ Steps : []resource.TestStep {
426+ {
427+ Config : `
428+ resource scaleway_vpc_private_network pn00 {}
429+ resource scaleway_vpc_private_network pn01 {}
430+
431+ resource scaleway_function_namespace main {
432+ activate_vpc_integration = true
433+ }
434+
435+ resource scaleway_function c00 {
436+ name = "test-acc-function-pn-00"
437+ namespace_id = scaleway_function_namespace.main.id
438+ privacy = "private"
439+ runtime = "go123"
440+ handler = "Handle"
441+ sandbox = "v1"
442+ private_network_id = scaleway_vpc_private_network.pn00.id
443+ }
444+ ` ,
445+ Check : resource .ComposeTestCheckFunc (
446+ testAccCheckFunctionExists (tt , "scaleway_function.c00" ),
447+ resource .TestCheckResourceAttr ("scaleway_function_namespace.main" , "activate_vpc_integration" , "true" ),
448+ resource .TestCheckResourceAttr ("scaleway_function.c00" , "sandbox" , "v1" ),
449+ resource .TestCheckResourceAttrPair ("scaleway_function.c00" , "private_network_id" , "scaleway_vpc_private_network.pn00" , "id" ),
450+ ),
451+ },
452+ {
453+ Config : `
454+ resource scaleway_vpc_private_network pn00 {}
455+ resource scaleway_vpc_private_network pn01 {}
456+
457+ resource scaleway_function_namespace main {
458+ activate_vpc_integration = true
459+ }
460+
461+ resource scaleway_function c00 {
462+ name = "test-acc-function-pn-00"
463+ namespace_id = scaleway_function_namespace.main.id
464+ privacy = "private"
465+ runtime = "go123"
466+ handler = "Handle"
467+ sandbox = "v1"
468+ private_network_id = scaleway_vpc_private_network.pn00.id
469+ }
470+
471+ resource scaleway_function c01 {
472+ name = "test-acc-function-pn-01"
473+ namespace_id = scaleway_function_namespace.main.id
474+ privacy = "private"
475+ runtime = "go123"
476+ handler = "Handle"
477+ sandbox = "v1"
478+ private_network_id = scaleway_vpc_private_network.pn00.id
479+ }
480+
481+ resource scaleway_function c02 {
482+ name = "test-acc-function-pn-02"
483+ namespace_id = scaleway_function_namespace.main.id
484+ privacy = "private"
485+ runtime = "go123"
486+ handler = "Handle"
487+ sandbox = "v1"
488+ private_network_id = scaleway_vpc_private_network.pn00.id
489+ }
490+ ` ,
491+ Check : resource .ComposeTestCheckFunc (
492+ testAccCheckFunctionExists (tt , "scaleway_function.c00" ),
493+ testAccCheckFunctionExists (tt , "scaleway_function.c01" ),
494+ testAccCheckFunctionExists (tt , "scaleway_function.c02" ),
495+ resource .TestCheckResourceAttr ("scaleway_function.c00" , "sandbox" , "v1" ),
496+ resource .TestCheckResourceAttr ("scaleway_function.c01" , "sandbox" , "v1" ),
497+ resource .TestCheckResourceAttr ("scaleway_function.c02" , "sandbox" , "v1" ),
498+ resource .TestCheckResourceAttrPair ("scaleway_function.c00" , "private_network_id" , "scaleway_vpc_private_network.pn00" , "id" ),
499+ resource .TestCheckResourceAttrPair ("scaleway_function.c01" , "private_network_id" , "scaleway_vpc_private_network.pn00" , "id" ),
500+ resource .TestCheckResourceAttrPair ("scaleway_function.c02" , "private_network_id" , "scaleway_vpc_private_network.pn00" , "id" ),
501+ ),
502+ },
503+ {
504+ Config : `
505+ resource scaleway_vpc_private_network pn00 {}
506+ resource scaleway_vpc_private_network pn01 {}
507+
508+ resource scaleway_function_namespace main {
509+ activate_vpc_integration = true
510+ }
511+
512+ resource scaleway_function c00 {
513+ name = "test-acc-function-pn-00"
514+ namespace_id = scaleway_function_namespace.main.id
515+ privacy = "private"
516+ runtime = "go123"
517+ handler = "Handle"
518+ sandbox = "v1"
519+ }
520+
521+ resource scaleway_function c01 {
522+ name = "test-acc-function-pn-01"
523+ namespace_id = scaleway_function_namespace.main.id
524+ privacy = "private"
525+ runtime = "go123"
526+ handler = "Handle"
527+ sandbox = "v1"
528+ private_network_id = scaleway_vpc_private_network.pn01.id
529+ }
530+
531+ resource scaleway_function c02 {
532+ name = "test-acc-function-pn-02"
533+ namespace_id = scaleway_function_namespace.main.id
534+ privacy = "private"
535+ runtime = "go123"
536+ handler = "Handle"
537+ sandbox = "v1"
538+ private_network_id = scaleway_vpc_private_network.pn00.id
539+ }
540+ ` ,
541+ Check : resource .ComposeTestCheckFunc (
542+ testAccCheckFunctionExists (tt , "scaleway_function.c00" ),
543+ testAccCheckFunctionExists (tt , "scaleway_function.c01" ),
544+ testAccCheckFunctionExists (tt , "scaleway_function.c02" ),
545+ resource .TestCheckResourceAttr ("scaleway_function.c00" , "private_network_id" , "" ),
546+ resource .TestCheckResourceAttrPair ("scaleway_function.c01" , "private_network_id" , "scaleway_vpc_private_network.pn01" , "id" ),
547+ resource .TestCheckResourceAttrPair ("scaleway_function.c02" , "private_network_id" , "scaleway_vpc_private_network.pn00" , "id" ),
548+ ),
549+ },
550+ },
551+ })
552+ }
553+
413554func testAccCheckFunctionExists (tt * acctest.TestTools , n string ) resource.TestCheckFunc {
414555 return func (state * terraform.State ) error {
415556 rs , ok := state .RootModule ().Resources [n ]
@@ -468,7 +609,7 @@ func passwordMatchHash(parent string, key string, password string) resource.Test
468609 return func (state * terraform.State ) error {
469610 rs , ok := state .RootModule ().Resources [parent ]
470611 if ! ok {
471- return fmt .Errorf ("resource container not found: %s" , parent )
612+ return fmt .Errorf ("resource not found: %s" , parent )
472613 }
473614
474615 match , err := argon2id .ComparePasswordAndHash (password , rs .Primary .Attributes [key ])
0 commit comments