|
| 1 | +--- |
| 2 | +subcategory: "Key Manager" |
| 3 | +page_title: "Scaleway: scaleway_key_manager_key" |
| 4 | +--- |
| 5 | +# Resource: scaleway_key_manager_key |
| 6 | + |
| 7 | +Provides a Scaleway Key Manager Key resource. |
| 8 | +This resource allows you to create and manage cryptographic keys in Scaleway Key Manager (KMS). |
| 9 | + |
| 10 | +## Example Usage |
| 11 | + |
| 12 | +```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 |
| 21 | +
|
| 22 | + rotation_policy { |
| 23 | + rotation_period = "720h" # 30 days |
| 24 | + } |
| 25 | +} |
| 26 | +``` |
| 27 | + |
| 28 | +## Argument Reference |
| 29 | + |
| 30 | +The following arguments are supported: |
| 31 | + |
| 32 | +- `name` (String) – The name of the key. |
| 33 | +- `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` |
| 39 | +- `description` (String, Optional) – A description for the key. |
| 40 | +- `tags` (List of String, Optional) – A list of tags to assign to the key. |
| 41 | +- `unprotected` (Boolean, Optional) – If `true`, the key can be deleted. Defaults to `false` (protected). |
| 42 | +- `origin` (String, Optional) – The origin of the key. Valid values are: |
| 43 | + - `scaleway_kms` (default) |
| 44 | + - `external` |
| 45 | +- `rotation_policy` (Block, Optional) – Rotation policy for the key: |
| 46 | + - `rotation_period` (String, Optional) – The period between key rotations (e.g., `"720h"` for 30 days). |
| 47 | + |
| 48 | +## Attributes Reference |
| 49 | + |
| 50 | +In addition to all arguments above, the following attributes are exported: |
| 51 | + |
| 52 | +- `id` – The ID of the key. |
| 53 | +- `state` – The state of the key (e.g., `enabled`). |
| 54 | +- `created_at` – The date and time when the key was created. |
| 55 | +- `updated_at` – The date and time when the key was last updated. |
| 56 | +- `rotation_count` – The number of times the key has been rotated. |
| 57 | +- `protected` – Whether the key is protected from deletion. |
| 58 | +- `locked` – Whether the key is locked. |
| 59 | +- `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. |
| 62 | +- `rotation_policy` (Block) |
| 63 | + - `rotation_period` – The period between key rotations. |
| 64 | + - `next_rotation_at` – The date and time of the next scheduled rotation. |
| 65 | + |
| 66 | +## Import |
| 67 | + |
| 68 | +You can import a key using its ID and region: |
| 69 | + |
| 70 | +```shell |
| 71 | +terraform import scaleway_key_manager_key.main fr-par/11111111-2222-3333-4444-555555555555 |
| 72 | +``` |
| 73 | + |
| 74 | +## Notes |
| 75 | + |
| 76 | +- **Protection**: By default, keys are protected and cannot be deleted. To allow deletion, set `unprotected = true` when creating the key. |
| 77 | +- **Rotation Policy**: The `rotation_policy` block allows you to set automatic rotation for your key. |
| 78 | +- **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). |
| 79 | +- **Project and Region**: If not specified, `project_id` and `region` will default to the provider configuration. |
| 80 | + |
| 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 | +``` |
0 commit comments