Skip to content

Commit 53d2805

Browse files
authored
deprecate function token and document new auth with IAM (#3534)
1 parent f4b3d7c commit 53d2805

File tree

5 files changed

+126
-7
lines changed

5 files changed

+126
-7
lines changed

docs/resources/function.md

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ resource "scaleway_function_namespace" "main" {
2323
2424
resource "scaleway_function" "main" {
2525
namespace_id = scaleway_function_namespace.main.id
26-
runtime = "go118"
26+
runtime = "go124"
2727
handler = "Handle"
2828
privacy = "private"
2929
}
@@ -43,7 +43,7 @@ resource "scaleway_function" "main" {
4343
namespace_id = scaleway_function_namespace.main.id
4444
description = "function with zip file"
4545
tags = ["tag1", "tag2"]
46-
runtime = "go118"
46+
runtime = "go124"
4747
handler = "Handle"
4848
privacy = "private"
4949
timeout = 10
@@ -53,6 +53,62 @@ resource "scaleway_function" "main" {
5353
}
5454
```
5555

56+
### Managing authentication of private functions with IAM
57+
58+
```terraform
59+
# Project to be referenced in the IAM policy
60+
data "scaleway_account_project" "default" {
61+
name = "default"
62+
}
63+
64+
# IAM resources
65+
resource "scaleway_iam_application" "func_auth" {
66+
name = "function-auth"
67+
}
68+
resource "scaleway_iam_policy" "access_private_funcs" {
69+
application_id = scaleway_iam_application.func_auth.id
70+
rule {
71+
project_ids = [data.scaleway_account_project.default.id]
72+
permission_set_names = ["FunctionsPrivateAccess"]
73+
}
74+
}
75+
resource "scaleway_iam_api_key" "api_key" {
76+
application_id = scaleway_iam_application.func_auth.id
77+
}
78+
79+
# Function resources
80+
resource "scaleway_function_namespace" "private" {
81+
name = "private-function-namespace"
82+
}
83+
resource "scaleway_function" "private" {
84+
namespace_id = scaleway_function_namespace.private.id
85+
runtime = "go124"
86+
handler = "Handle"
87+
privacy = "private"
88+
zip_file = "function.zip"
89+
zip_hash = filesha256("function.zip")
90+
deploy = true
91+
}
92+
93+
# Output the secret key and the function's endpoint for the curl command
94+
output "secret_key" {
95+
value = scaleway_iam_api_key.api_key.secret_key
96+
sensitive = true
97+
}
98+
output "function_endpoint" {
99+
value = scaleway_function.private.domain_name
100+
}
101+
```
102+
103+
Then you can access your private function using the API key:
104+
105+
```shell
106+
$ curl -H "X-Auth-Token: $(terraform output -raw secret_key)" \
107+
"https://$(terraform output -raw function_endpoint)/"
108+
```
109+
110+
Keep in mind that you should revoke your legacy JWT tokens to ensure maximum security.
111+
56112
## Argument Reference
57113

58114
The following arguments are supported:

docs/resources/function_token.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ page_title: "Scaleway: scaleway_function_token"
55

66
# Resource: scaleway_function_token
77

8+
~> **Important:** The resource `scaleway_function_token` has been deprecated and will no longer be supported in v1 of the API.
9+
Please use IAM authentication instead. You will find an implementation example in the [IAM authentication](function.md#managing-authentication-of-private-functions-with-iam) section of the Function documentation.
10+
811
The `scaleway_function_token` resource allows you to create and manage authentication tokens for Scaleway [Serverless Functions](https://www.scaleway.com/en/docs/serverless/functions/).
912

1013
Refer to the Functions tokens [documentation](https://www.scaleway.com/en/docs/serverless/functions/how-to/create-auth-token-from-console/) and [API documentation](https://www.scaleway.com/en/developers/api/serverless-functions/#path-tokens-list-all-tokens) for more information.

internal/services/function/token.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ import (
2020

2121
func ResourceToken() *schema.Resource {
2222
return &schema.Resource{
23-
CreateContext: ResourceFunctionTokenCreate,
24-
ReadContext: ResourceFunctionTokenRead,
25-
DeleteContext: ResourceFunctionTokenDelete,
23+
CreateContext: ResourceFunctionTokenCreate,
24+
ReadContext: ResourceFunctionTokenRead,
25+
DeleteContext: ResourceFunctionTokenDelete,
26+
DeprecationMessage: "The \"scaleway_function_token\" resource is deprecated in favor of IAM authentication",
2627
Importer: &schema.ResourceImporter{
2728
StateContext: schema.ImportStatePassthroughContext,
2829
},

templates/resources/function.md.tmpl

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ resource "scaleway_function_namespace" "main" {
2424

2525
resource "scaleway_function" "main" {
2626
namespace_id = scaleway_function_namespace.main.id
27-
runtime = "go118"
27+
runtime = "go124"
2828
handler = "Handle"
2929
privacy = "private"
3030
}
@@ -44,7 +44,7 @@ resource "scaleway_function" "main" {
4444
namespace_id = scaleway_function_namespace.main.id
4545
description = "function with zip file"
4646
tags = ["tag1", "tag2"]
47-
runtime = "go118"
47+
runtime = "go124"
4848
handler = "Handle"
4949
privacy = "private"
5050
timeout = 10
@@ -54,6 +54,62 @@ resource "scaleway_function" "main" {
5454
}
5555
```
5656

57+
### Managing authentication of private functions with IAM
58+
59+
```terraform
60+
# Project to be referenced in the IAM policy
61+
data "scaleway_account_project" "default" {
62+
name = "default"
63+
}
64+
65+
# IAM resources
66+
resource "scaleway_iam_application" "func_auth" {
67+
name = "function-auth"
68+
}
69+
resource "scaleway_iam_policy" "access_private_funcs" {
70+
application_id = scaleway_iam_application.func_auth.id
71+
rule {
72+
project_ids = [data.scaleway_account_project.default.id]
73+
permission_set_names = ["FunctionsPrivateAccess"]
74+
}
75+
}
76+
resource "scaleway_iam_api_key" "api_key" {
77+
application_id = scaleway_iam_application.func_auth.id
78+
}
79+
80+
# Function resources
81+
resource "scaleway_function_namespace" "private" {
82+
name = "private-function-namespace"
83+
}
84+
resource "scaleway_function" "private" {
85+
namespace_id = scaleway_function_namespace.private.id
86+
runtime = "go124"
87+
handler = "Handle"
88+
privacy = "private"
89+
zip_file = "function.zip"
90+
zip_hash = filesha256("function.zip")
91+
deploy = true
92+
}
93+
94+
# Output the secret key and the function's endpoint for the curl command
95+
output "secret_key" {
96+
value = scaleway_iam_api_key.api_key.secret_key
97+
sensitive = true
98+
}
99+
output "function_endpoint" {
100+
value = scaleway_function.private.domain_name
101+
}
102+
```
103+
104+
Then you can access your private function using the API key:
105+
106+
```shell
107+
$ curl -H "X-Auth-Token: $(terraform output -raw secret_key)" \
108+
"https://$(terraform output -raw function_endpoint)/"
109+
```
110+
111+
Keep in mind that you should revoke your legacy JWT tokens to ensure maximum security.
112+
57113
## Argument Reference
58114

59115
The following arguments are supported:

templates/resources/function_token.md.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ page_title: "Scaleway: scaleway_function_token"
66

77
# Resource: scaleway_function_token
88

9+
~> **Important:** The resource `scaleway_function_token` has been deprecated and will no longer be supported in v1 of the API.
10+
Please use IAM authentication instead. You will find an implementation example in the [IAM authentication](function.md#managing-authentication-of-private-functions-with-iam) section of the Function documentation.
11+
912
The `scaleway_function_token` resource allows you to create and manage authentication tokens for Scaleway [Serverless Functions](https://www.scaleway.com/en/docs/serverless/functions/).
1013

1114
Refer to the Functions tokens [documentation](https://www.scaleway.com/en/docs/serverless/functions/how-to/create-auth-token-from-console/) and [API documentation](https://www.scaleway.com/en/developers/api/serverless-functions/#path-tokens-list-all-tokens) for more information.

0 commit comments

Comments
 (0)