Skip to content

Commit 4138acf

Browse files
authored
feat(serverless): add sandbox field (#2657)
* feat(container): add sandbox field * feat(function): add sandbox field * add cassettes * update doc
1 parent 45cddcd commit 4138acf

File tree

10 files changed

+5116
-0
lines changed

10 files changed

+5116
-0
lines changed

docs/data-sources/container.md

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ In addition to all arguments above, the following attributes are exported:
8686

8787
- `deploy` - Boolean indicating whether the container is on a production environment.
8888

89+
- `sandbox` - (Optional) Execution environment of the container.
90+
8991
- `status` - The container status.
9092

9193
- `cron_status` - The cron status of the container.

docs/resources/container.md

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ The following arguments are optional:
8686

8787
- `http_option` - (Optional) Allow both HTTP and HTTPS (enabled) or redirect HTTP to HTTPS (redirected). Defaults to enabled.
8888

89+
- `sandbox` - (Optional) Execution environment of the container.
90+
8991
- `port` - (Optional) The port to expose the container. Defaults to 8080.
9092

9193
- `deploy` - (Optional) Boolean controlling whether the container is on a production environment.

docs/resources/function.md

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ The following arguments are supported:
8484

8585
- `deploy` - Define if the function should be deployed, terraform will wait for function to be deployed. Function will get deployed if you change source zip
8686

87+
- `sandbox` - (Optional) Execution environment of the function.
88+
8789
- `region` - (Defaults to [provider](../index.md#region) `region`). The [region](../guides/regions_and_zones.md#regions) in which the namespace should be created.
8890

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

internal/services/container/container.go

+12
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ func ResourceContainer() *schema.Resource {
163163
Default: container.ContainerHTTPOptionEnabled.String(),
164164
ValidateDiagFunc: verify.ValidateEnum[container.ContainerHTTPOption](),
165165
},
166+
"sandbox": {
167+
Type: schema.TypeString,
168+
Optional: true,
169+
Computed: true,
170+
Description: "Execution environment of the container.",
171+
ValidateDiagFunc: verify.ValidateEnum[container.ContainerSandbox](),
172+
},
166173
// computed
167174
"status": {
168175
Type: schema.TypeString,
@@ -272,6 +279,7 @@ func ResourceContainerRead(ctx context.Context, d *schema.ResourceData, m interf
272279
_ = d.Set("port", int(co.Port))
273280
_ = d.Set("deploy", scw.BoolPtr(*types.ExpandBoolPtr(d.Get("deploy"))))
274281
_ = d.Set("http_option", co.HTTPOption)
282+
_ = d.Set("sandbox", co.Sandbox)
275283
_ = d.Set("region", co.Region.String())
276284

277285
return nil
@@ -363,6 +371,10 @@ func ResourceContainerUpdate(ctx context.Context, d *schema.ResourceData, m inte
363371
req.Redeploy = types.ExpandBoolPtr(d.Get("deploy"))
364372
}
365373

374+
if d.HasChanges("sandbox") {
375+
req.Sandbox = container.ContainerSandbox(d.Get("sandbox").(string))
376+
}
377+
366378
imageHasChanged := d.HasChanges("registry_sha256")
367379
if imageHasChanged {
368380
req.Redeploy = &imageHasChanged

internal/services/container/container_test.go

+70
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,76 @@ func TestAccContainer_HTTPOption(t *testing.T) {
330330
})
331331
}
332332

333+
func TestAccContainer_Sandbox(t *testing.T) {
334+
tt := acctest.NewTestTools(t)
335+
defer tt.Cleanup()
336+
resource.ParallelTest(t, resource.TestCase{
337+
PreCheck: func() { acctest.PreCheck(t) },
338+
ProviderFactories: tt.ProviderFactories,
339+
CheckDestroy: isContainerDestroyed(tt),
340+
Steps: []resource.TestStep{
341+
{
342+
Config: `
343+
resource scaleway_container_namespace main {}
344+
345+
resource scaleway_container main {
346+
namespace_id = scaleway_container_namespace.main.id
347+
deploy = false
348+
}
349+
`,
350+
Check: resource.ComposeTestCheckFunc(
351+
isContainerPresent(tt, "scaleway_container.main"),
352+
resource.TestCheckResourceAttrSet("scaleway_container.main", "sandbox"),
353+
),
354+
},
355+
{
356+
Config: `
357+
resource scaleway_container_namespace main {}
358+
359+
resource scaleway_container main {
360+
namespace_id = scaleway_container_namespace.main.id
361+
deploy = false
362+
sandbox = "v2"
363+
}
364+
`,
365+
Check: resource.ComposeTestCheckFunc(
366+
isContainerPresent(tt, "scaleway_container.main"),
367+
resource.TestCheckResourceAttr("scaleway_container.main", "sandbox", containerSDK.ContainerSandboxV2.String()),
368+
),
369+
},
370+
{
371+
Config: `
372+
resource scaleway_container_namespace main {}
373+
374+
resource scaleway_container main {
375+
namespace_id = scaleway_container_namespace.main.id
376+
deploy = false
377+
sandbox = "v1"
378+
}
379+
`,
380+
Check: resource.ComposeTestCheckFunc(
381+
isContainerPresent(tt, "scaleway_container.main"),
382+
resource.TestCheckResourceAttr("scaleway_container.main", "sandbox", containerSDK.ContainerSandboxV1.String()),
383+
),
384+
},
385+
{
386+
Config: `
387+
resource scaleway_container_namespace main {}
388+
389+
resource scaleway_container main {
390+
namespace_id = scaleway_container_namespace.main.id
391+
sandbox = "v2"
392+
}
393+
`,
394+
Check: resource.ComposeTestCheckFunc(
395+
isContainerPresent(tt, "scaleway_container.main"),
396+
resource.TestCheckResourceAttr("scaleway_container.main", "sandbox", containerSDK.ContainerSandboxV2.String()),
397+
),
398+
},
399+
},
400+
})
401+
}
402+
333403
func isContainerPresent(tt *acctest.TestTools, n string) resource.TestCheckFunc {
334404
return func(state *terraform.State) error {
335405
rs, ok := state.RootModule().Resources[n]

internal/services/container/helpers_container.go

+4
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ func setCreateContainerRequest(d *schema.ResourceData, region scw.Region) (*cont
111111
req.MaxConcurrency = scw.Uint32Ptr(uint32(maxConcurrency.(int)))
112112
}
113113

114+
if sandbox, ok := d.GetOk("sandbox"); ok {
115+
req.Sandbox = container.ContainerSandbox(sandbox.(string))
116+
}
117+
114118
return req, nil
115119
}
116120

0 commit comments

Comments
 (0)