Skip to content

Commit f580872

Browse files
authored
feat(serverless): add tags to container and function resources (#3117)
1 parent 8d39c05 commit f580872

File tree

11 files changed

+871
-616
lines changed

11 files changed

+871
-616
lines changed

docs/resources/container.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ resource "scaleway_container_namespace" "main" {
2222
resource "scaleway_container" "main" {
2323
name = "my-container-02"
2424
description = "environment variables test"
25+
tags = ["tag1", "tag2"]
2526
namespace_id = scaleway_container_namespace.main.id
2627
registry_image = "${scaleway_container_namespace.main.registry_endpoint}/alpine:test"
2728
port = 9997
@@ -56,6 +57,8 @@ The following arguments are supported:
5657

5758
- `description` (Optional) The description of the container.
5859

60+
- `tags` - (Optional) The list of tags associated with the container.
61+
5962
- `environment_variables` - (Optional) The [environment variables](https://www.scaleway.com/en/docs/serverless-containers/concepts/#environment-variables) of the container.
6063

6164
- `secret_environment_variables` - (Optional) The [secret environment variables](https://www.scaleway.com/en/docs/serverless-containers/concepts/#secrets) of the container.
@@ -99,7 +102,7 @@ The following arguments are supported:
99102

100103
- `deploy` - (Optional) Boolean indicating whether the container is in a production environment.
101104

102-
- `local_storage_limit` - Local storage limit of the container (in MB)
105+
- `local_storage_limit` - (Optional) Local storage limit of the container (in MB)
103106

104107
Note that if you want to use your own configuration, you must consult our configuration [restrictions](https://www.scaleway.com/en/docs/serverless-containers/reference-content/containers-limitations/#configuration-restrictions) section.
105108

docs/resources/container_namespace.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Refer to the Containers namespace [documentation](https://www.scaleway.com/en/do
1616
resource "scaleway_container_namespace" "main" {
1717
name = "main-container-namespace"
1818
description = "Main container namespace"
19+
tags = ["tag1", "tag2"]
1920
}
2021
```
2122

@@ -27,15 +28,17 @@ The following arguments are supported:
2728

2829
~> **Important** Updates to the `name` argument will recreate the namespace.
2930

30-
- `description` (Optional) The description of the namespace.
31+
- `description` - (Optional) The description of the namespace.
32+
33+
- `tags` - (Optional) The list of tags associated with the namespace.
3134

3235
- `region` - (Defaults to [provider](../index.md#region) `region`). The [region](../guides/regions_and_zones.md#regions) in which the namespace is created.
3336

3437
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The unique identifier of the project that contains the namespace.
3538

36-
- `environment_variables` - The environment variables of the namespace.
39+
- `environment_variables` - (Optional) The environment variables of the namespace.
3740

38-
- `secret_environment_variables` - The secret environment variables of the namespace.
41+
- `secret_environment_variables` - (Optional) The secret environment variables of the namespace.
3942

4043
## Attributes Reference
4144

docs/resources/function.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ resource "scaleway_function_namespace" "main" {
4141
4242
resource "scaleway_function" "main" {
4343
namespace_id = scaleway_function_namespace.main.id
44+
description = "function with zip file"
45+
tags = ["tag1", "tag2"]
4446
runtime = "go118"
4547
handler = "Handle"
4648
privacy = "private"
@@ -63,29 +65,31 @@ The following arguments are supported:
6365

6466
- `description` (Optional) The description of the function.
6567

68+
- `tags` - (Optional) The list of tags associated with the function.
69+
6670
- `environment_variables` - (Optional) The [environment variables](https://www.scaleway.com/en/docs/compute/functions/concepts/#environment-variables) of the function.
6771

6872
- `secret_environment_variables` - (Optional) The [secret environment variables](https://www.scaleway.com/en/docs/compute/functions/concepts/#secrets) of the function.
6973

7074
- `privacy` - (Optional) The privacy type defines the way to authenticate to your function. Please check our dedicated [section](https://www.scaleway.com/en/developers/api/serverless-functions/#protocol-9dd4c8).
7175

72-
- `runtime` - Runtime of the function. Runtimes can be fetched using [specific route](https://www.scaleway.com/en/developers/api/serverless-functions/#path-functions-get-a-function)
76+
- `runtime` - (Required) Runtime of the function. Runtimes can be fetched using [specific route](https://www.scaleway.com/en/developers/api/serverless-functions/#path-functions-get-a-function)
7377

7478
- `min_scale` - (Optional) The minimum number of function instances running continuously. Defaults to 0. Functions are billed when executed, and using a `min_scale` greater than 0 will cause your function to run constantly.
7579

7680
- `max_scale` - (Optional) The maximum number of instances this function can scale to. Default to 20. Your function will scale automatically based on the incoming workload, but will never exceed the configured `max_scale` value.
7781

7882
- `memory_limit` - (Optional) The memory resources in MB to allocate to each function. Defaults to 256 MB.
7983

80-
- `handler` - Handler of the function, depends on the runtime. Refer to the [dedicated documentation](https://www.scaleway.com/en/developers/api/serverless-functions/#path-functions-create-a-new-function) for the list of supported runtimes.
84+
- `handler` - (Required) Handler of the function, depends on the runtime. Refer to the [dedicated documentation](https://www.scaleway.com/en/developers/api/serverless-functions/#path-functions-create-a-new-function) for the list of supported runtimes.
8185

8286
- `timeout` - (Optional) The maximum amount of time your function can spend processing a request before being stopped. Defaults to 300s.
8387

84-
- `zip_file` - Path to the zip file containing your function sources to upload.
88+
- `zip_file` - (Optional) Path to the zip file containing your function sources to upload.
8589

86-
- `zip_hash` - The hash of your source zip file, changing it will redeploy the function. Can be any string, changing it will simply trigger a state change. You can use any Terraform hash function to trigger a change on your zip change (see examples).
90+
- `zip_hash` - (Optional) The hash of your source zip file, changing it will redeploy the function. Can be any string, changing it will simply trigger a state change. You can use any Terraform hash function to trigger a change on your zip change (see examples).
8791

88-
- `deploy` - Define whether the function should be deployed. Terraform will wait for the function to be deployed. Your function will be redeployed if you update the source zip file.
92+
- `deploy` - (Optional, defaults to `false`) Define whether the function should be deployed. Terraform will wait for the function to be deployed. Your function will be redeployed if you update the source zip file.
8993

9094
- `http_option` - (Optional) Allows both HTTP and HTTPS (`enabled`) or redirect HTTP to HTTPS (`redirected`). Defaults to `enabled`.
9195

docs/resources/function_namespace.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Refer to the Functions namespace [documentation](https://www.scaleway.com/en/doc
1616
resource "scaleway_function_namespace" "main" {
1717
name = "main-function-namespace"
1818
description = "Main function namespace"
19+
tags = ["tag1", "tag2"]
1920
}
2021
```
2122

@@ -29,13 +30,15 @@ The following arguments are supported:
2930

3031
- `description` (Optional) The description of the namespace.
3132

33+
- `tags` - (Optional) The list of tags associated with the namespace.
34+
3235
- `region` - (Defaults to [provider](../index.md#region) `region`). The [region](../guides/regions_and_zones.md#regions) in which the namespace is created.
3336

3437
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The unique identifier of the project that contains the namespace.
3538

36-
- `environment_variables` - The environment variables of the namespace.
39+
- `environment_variables` - (Optional) The environment variables of the namespace.
3740

38-
- `secret_environment_variables` - The secret environment variables of the namespace.
41+
- `secret_environment_variables` - (Optional) The secret environment variables of the namespace.
3942

4043
## Attributes Reference
4144

internal/services/container/container.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ func ResourceContainer() *schema.Resource {
5555
Required: true,
5656
Description: "The container namespace associated",
5757
},
58+
"tags": {
59+
Type: schema.TypeList,
60+
Elem: &schema.Schema{
61+
Type: schema.TypeString,
62+
},
63+
Optional: true,
64+
Description: "List of tags [\"tag1\", \"tag2\", ...] attached to the container.",
65+
},
5866
"environment_variables": {
5967
Type: schema.TypeMap,
6068
Optional: true,
@@ -361,6 +369,7 @@ func ResourceContainerRead(ctx context.Context, d *schema.ResourceData, m interf
361369
_ = d.Set("region", co.Region.String())
362370
_ = d.Set("local_storage_limit", int(co.LocalStorageLimit))
363371
_ = d.Set("secret_environment_variables", flattenContainerSecrets(co.SecretEnvironmentVariables))
372+
_ = d.Set("tags", types.FlattenSliceString(co.Tags))
364373

365374
return nil
366375
}
@@ -400,6 +409,10 @@ func ResourceContainerUpdate(ctx context.Context, d *schema.ResourceData, m inte
400409
req.SecretEnvironmentVariables = filterSecretEnvsToPatch(expandContainerSecrets(oldEnv), expandContainerSecrets(newEnv))
401410
}
402411

412+
if d.HasChange("tags") {
413+
req.Tags = types.ExpandUpdatedStringsPtr(d.Get("tags"))
414+
}
415+
403416
if d.HasChanges("min_scale") {
404417
req.MinScale = scw.Uint32Ptr(uint32(d.Get("min_scale").(int)))
405418
}

internal/services/container/container_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func TestAccContainer_Basic(t *testing.T) {
3030
3131
resource scaleway_container main {
3232
namespace_id = scaleway_container_namespace.main.id
33+
tags = ["tag1", "tag2"]
3334
}
3435
`,
3536
Check: resource.ComposeTestCheckFunc(
@@ -49,6 +50,9 @@ func TestAccContainer_Basic(t *testing.T) {
4950
resource.TestCheckResourceAttrSet("scaleway_container.main", "min_scale"),
5051
resource.TestCheckResourceAttrSet("scaleway_container.main", "privacy"),
5152
resource.TestCheckResourceAttrSet("scaleway_container.main", "local_storage_limit"),
53+
resource.TestCheckResourceAttr("scaleway_container.main", "tags.#", "2"),
54+
resource.TestCheckResourceAttr("scaleway_container.main", "tags.0", "tag1"),
55+
resource.TestCheckResourceAttr("scaleway_container.main", "tags.1", "tag2"),
5256
),
5357
},
5458
{
@@ -67,6 +71,7 @@ func TestAccContainer_Basic(t *testing.T) {
6771
timeout = 300
6872
deploy = false
6973
local_storage_limit = 1000
74+
tags = ["tag"]
7075
}
7176
`,
7277
Check: resource.ComposeTestCheckFunc(
@@ -84,6 +89,8 @@ func TestAccContainer_Basic(t *testing.T) {
8489
resource.TestCheckResourceAttr("scaleway_container.main", "privacy", containerSDK.ContainerPrivacyPublic.String()),
8590
resource.TestCheckResourceAttr("scaleway_container.main", "protocol", containerSDK.ContainerProtocolHTTP1.String()),
8691
resource.TestCheckResourceAttr("scaleway_container.main", "local_storage_limit", "1000"),
92+
resource.TestCheckResourceAttr("scaleway_container.main", "tags.#", "1"),
93+
resource.TestCheckResourceAttr("scaleway_container.main", "tags.0", "tag"),
8794
),
8895
},
8996
{
@@ -118,6 +125,7 @@ func TestAccContainer_Basic(t *testing.T) {
118125
resource.TestCheckResourceAttr("scaleway_container.main", "deploy", "false"),
119126
resource.TestCheckResourceAttr("scaleway_container.main", "protocol", containerSDK.ContainerProtocolHTTP1.String()),
120127
resource.TestCheckResourceAttr("scaleway_container.main", "local_storage_limit", "1500"),
128+
resource.TestCheckResourceAttr("scaleway_container.main", "tags.#", "0"),
121129
),
122130
},
123131
},

internal/services/container/helpers_container.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ func setCreateContainerRequest(d *schema.ResourceData, region scw.Region) (*cont
140140
req.LocalStorageLimit = scw.Uint32Ptr(uint32(localStorageLimit.(int)))
141141
}
142142

143+
if tags, ok := d.GetOk("tags"); ok {
144+
req.Tags = types.ExpandStrings(tags)
145+
}
146+
143147
return req, nil
144148
}
145149

0 commit comments

Comments
 (0)