Skip to content

Commit 3f5b763

Browse files
authored
chore: fix documentation and include a make docs (#3412)
* chore: fix documentation and include a make docs * Fix linter
1 parent c1a267a commit 3f5b763

File tree

3 files changed

+77
-30
lines changed

3 files changed

+77
-30
lines changed

GNUmakefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ test-compile:
5353
website:
5454
@echo "Use this site to preview markdown rendering: https://registry.terraform.io/tools/doc-preview"
5555

56-
.PHONY: build test testacc vet fmt fmtcheck errcheck test-compile website
56+
.PHONY: build test testacc vet fmt fmtcheck errcheck test-compile website docs
5757

5858
tfproviderlint:
5959
go tool tfproviderlint -R014=false -AT001.ignored-filename-suffixes=_data_source_test.go ./...
@@ -63,3 +63,8 @@ tfproviderdocs:
6363

6464
tfproviderlintx:
6565
go tool tfproviderlintx -XR001=false -XS002=false ./...
66+
67+
docs:
68+
go tool tfplugindocs validate
69+
rm -fr ./docs
70+
go tool tfplugindocs generate

docs/resources/key_manager_key.md

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,80 @@ This resource allows you to create and manage cryptographic keys in Scaleway Key
99

1010
## Example Usage
1111

12+
### Symmetric Encryption Key
13+
1214
```terraform
13-
resource "scaleway_key_manager_key" "main" {
14-
name = "my-kms-key"
15-
region = "fr-par"
16-
project_id = "your-project-id" # optional, will use provider default if omitted
17-
usage = "symmetric_encryption"
18-
description = "Key for encrypting secrets"
19-
tags = ["env:prod", "kms"]
20-
unprotected = true
15+
resource "scaleway_key_manager_key" "symmetric" {
16+
name = "my-kms-key"
17+
region = "fr-par"
18+
project_id = "your-project-id" # optional, will use provider default if omitted
19+
usage = "symmetric_encryption"
20+
algorithm = "aes_256_gcm"
21+
description = "Key for encrypting secrets"
22+
tags = ["env:prod", "kms"]
23+
unprotected = true
2124
2225
rotation_policy {
2326
rotation_period = "720h" # 30 days
2427
}
2528
}
2629
```
2730

31+
### Asymmetric Encryption Key with RSA-4096
32+
33+
```terraform
34+
resource "scaleway_key_manager_key" "rsa_4096" {
35+
name = "rsa-4096-key"
36+
region = "fr-par"
37+
usage = "asymmetric_encryption"
38+
algorithm = "rsa_oaep_4096_sha256"
39+
description = "Key for encrypting large files with RSA-4096"
40+
unprotected = true
41+
}
42+
```
43+
44+
### Asymmetric Signing Key
45+
46+
```terraform
47+
resource "scaleway_key_manager_key" "signing" {
48+
name = "signing-key"
49+
region = "fr-par"
50+
usage = "asymmetric_signing"
51+
algorithm = "rsa_pss_2048_sha256"
52+
description = "Key for signing documents"
53+
unprotected = true
54+
}
55+
```
56+
2857
## Argument Reference
2958

3059
The following arguments are supported:
3160

3261
- `name` (String) – The name of the key.
3362
- `region` (String) – The region in which to create the key (e.g., `fr-par`).
34-
- `project_id` (String, Optional) – The ID of the project the key belongs to.
35-
- `usage` (String, **Required**) – The usage of the key. Valid values are:
36-
- `symmetric_encryption`
37-
- `asymmetric_encryption`
38-
- `asymmetric_signing`
63+
- `project_id` (String, Optional) – The ID of the project the key belongs to.
64+
65+
**Key Usage and Algorithm (both required):**
66+
67+
- `usage` (String, Required) – The usage type of the key. Valid values:
68+
- `symmetric_encryption` – For symmetric encryption operations
69+
- `asymmetric_encryption` – For asymmetric encryption operations
70+
- `asymmetric_signing` – For digital signing operations
71+
72+
- `algorithm` (String, Required) – The cryptographic algorithm to use. Valid values depend on the `usage`:
73+
- For `symmetric_encryption`:
74+
- `aes_256_gcm`
75+
- For `asymmetric_encryption`:
76+
- `rsa_oaep_2048_sha256`
77+
- `rsa_oaep_3072_sha256`
78+
- `rsa_oaep_4096_sha256`
79+
- For `asymmetric_signing`:
80+
- `ec_p256_sha256`
81+
- `rsa_pss_2048_sha256`
82+
- `rsa_pkcs1_2048_sha256`
83+
84+
**Other arguments:**
85+
3986
- `description` (String, Optional) – A description for the key.
4087
- `tags` (List of String, Optional) – A list of tags to assign to the key.
4188
- `unprotected` (Boolean, Optional) – If `true`, the key can be deleted. Defaults to `false` (protected).
@@ -57,8 +104,6 @@ In addition to all arguments above, the following attributes are exported:
57104
- `protected` – Whether the key is protected from deletion.
58105
- `locked` – Whether the key is locked.
59106
- `rotated_at` – The date and time when the key was last rotated.
60-
- `origin_read` – The origin of the key as returned by the API.
61-
- `region_read` – The region of the key as returned by the API.
62107
- `rotation_policy` (Block)
63108
- `rotation_period` – The period between key rotations.
64109
- `next_rotation_at` – The date and time of the next scheduled rotation.
@@ -77,15 +122,5 @@ terraform import scaleway_key_manager_key.main fr-par/11111111-2222-3333-4444-55
77122
- **Rotation Policy**: The `rotation_policy` block allows you to set automatic rotation for your key.
78123
- **Origin**: The `origin` argument is optional and defaults to `scaleway_kms`. Use `external` if you want to import an external key (see Scaleway documentation for details).
79124
- **Project and Region**: If not specified, `project_id` and `region` will default to the provider configuration.
125+
- **Algorithm Validation**: The provider validates that the specified `algorithm` is compatible with the `usage` type at plan time, providing early feedback on configuration errors.
80126

81-
## Example: Asymmetric Key
82-
83-
```terraform
84-
resource "scaleway_key_manager_key" "asym" {
85-
name = "asymmetric-key"
86-
region = "fr-par"
87-
usage = "asymmetric_signing"
88-
description = "Key for signing documents"
89-
unprotected = true
90-
}
91-
```

templates/template_test.go renamed to internal/docs/template_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package template_test
1+
package docs_test
22

33
import (
44
"bufio"
@@ -13,23 +13,30 @@ import (
1313
var gotypeRE = regexp.MustCompile(`\{\{.*gotype:.*}}`)
1414

1515
func TestGoTypeDefined(t *testing.T) {
16-
err := filepath.WalkDir("resources", func(path string, _ fs.DirEntry, _ error) error {
16+
err := filepath.WalkDir("../../templates/resources", func(path string, _ fs.DirEntry, _ error) error {
1717
if isTemplate := strings.Contains(path, "tmpl"); isTemplate {
1818
f, err := os.Open(path)
1919
if err != nil {
2020
t.Fatalf("cannot open %s", path)
2121
}
22-
defer f.Close()
22+
defer func(f *os.File) {
23+
err := f.Close()
24+
if err != nil {
25+
t.Fatal(err.Error())
26+
}
27+
}(f)
2328

2429
scanner := bufio.NewScanner(f)
2530
if !scanner.Scan() {
2631
t.Logf("❌ %s: file is empty", path)
2732
t.Fail()
2833
}
34+
2935
firstLine := scanner.Text()
3036
if gotypeRE.MatchString(firstLine) {
3137
return nil
3238
}
39+
3340
t.Logf("gotype missing at top of file: %s", path)
3441
t.Fail()
3542
}

0 commit comments

Comments
 (0)