Skip to content

Commit f05880d

Browse files
committed
container test ok
1 parent 59ca314 commit f05880d

File tree

5 files changed

+3959
-471
lines changed

5 files changed

+3959
-471
lines changed

docs/resources/function.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ The following arguments are supported:
9999

100100
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the functions namespace is associated with.
101101

102+
- `private_network_id` (Optional) The ID of the Private Network the function is connected to.
103+
104+
~> **Important** This feature is currently in beta and requires a namespace with VPC integration activated by setting the `activate_vpc_integration` attribute to `true`.
102105

103106
## Attributes Reference
104107

internal/services/function/function.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ func ResourceFunctionRead(ctx context.Context, d *schema.ResourceData, m interfa
336336

337337
if f.PrivateNetworkID != nil {
338338
_ = d.Set("private_network_id", regional.NewID(region, types.FlattenStringPtr(f.PrivateNetworkID).(string)).String())
339+
} else {
340+
_ = d.Set("private_network_id", nil)
339341
}
340342

341343
return diags
@@ -430,12 +432,7 @@ func ResourceFunctionUpdate(ctx context.Context, d *schema.ResourceData, m inter
430432
}
431433

432434
if d.HasChanges("private_network_id") {
433-
if _, newPNID := d.GetChange("private_network_id"); newPNID != nil && newPNID.(string) != "" {
434-
req.PrivateNetworkID = types.ExpandUpdatedStringPtr(locality.ExpandID(newPNID.(string)))
435-
} else {
436-
req.PrivateNetworkID = nil
437-
}
438-
435+
req.PrivateNetworkID = types.ExpandUpdatedStringPtr(locality.ExpandID(d.Get("private_network_id")))
439436
updated = true
440437
}
441438

internal/services/function/function_test.go

Lines changed: 142 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

1718
func 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+
413554
func 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

Comments
 (0)