Skip to content

Commit

Permalink
feat(iam): Add TTL on IAM keys
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit-garcia committed Aug 13, 2024
1 parent 3db14c4 commit cf39bfe
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module "sdb" {
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement_terraform) | >= 0.13 |
| <a name="requirement_scaleway"></a> [scaleway](#requirement_scaleway) | >= 2.43.0 |
| <a name="requirement_time"></a> [time](#requirement_time) | 0.12.0 |

## Resources

Expand All @@ -39,13 +40,15 @@ module "sdb" {
| [scaleway_iam_policy.ro](https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/resources/iam_policy) | resource |
| [scaleway_iam_policy.rw](https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/resources/iam_policy) | resource |
| [scaleway_sdb_sql_database.main](https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/resources/sdb_sql_database) | resource |
| [time_rotating.keys_ttl](https://registry.terraform.io/providers/hashicorp/time/0.12.0/docs/resources/rotating) | resource |
| [scaleway_account_project.current](https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/data-sources/account_project) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_name"></a> [name](#input_name) | Name of the database. | `string` | n/a | yes |
| <a name="input_keys_ttl"></a> [keys_ttl](#input_keys_ttl) | TTL of IAM keys in days. | `number` | `0` | no |
| <a name="input_max_cpu"></a> [max_cpu](#input_max_cpu) | Maximum number of CPU units for your database. | `number` | `15` | no |
| <a name="input_min_cpu"></a> [min_cpu](#input_min_cpu) | Minimum number of CPU units for your database. | `number` | `0` | no |
| <a name="input_region"></a> [region](#input_region) | Region in which the resource exists. | `string` | `null` | no |
Expand Down
1 change: 1 addition & 0 deletions access_admin.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ resource "scaleway_iam_policy" "admin" {
resource "scaleway_iam_api_key" "admin" {
application_id = scaleway_iam_application.admin.id
default_project_id = data.scaleway_account_project.current.id
expires_at = var.keys_ttl > 0 ? time_rotating.keys_ttl[0].rotation_rfc3339 : null
}
1 change: 1 addition & 0 deletions access_ro.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ resource "scaleway_iam_policy" "ro" {
resource "scaleway_iam_api_key" "ro" {
application_id = scaleway_iam_application.ro.id
default_project_id = data.scaleway_account_project.current.id
expires_at = var.keys_ttl > 0 ? time_rotating.keys_ttl[0].rotation_rfc3339 : null
}
1 change: 1 addition & 0 deletions access_rw.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ resource "scaleway_iam_policy" "rw" {
resource "scaleway_iam_api_key" "rw" {
application_id = scaleway_iam_application.rw.id
default_project_id = data.scaleway_account_project.current.id
expires_at = var.keys_ttl > 0 ? time_rotating.keys_ttl[0].rotation_rfc3339 : null
}
5 changes: 5 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ resource "scaleway_sdb_sql_database" "main" {

region = var.region
}

resource "time_rotating" "keys_ttl" {
count = var.keys_ttl > 0 ? 1 : 0
rotation_days = var.keys_ttl
}
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ variable "name" {
type = string
}

variable "keys_ttl" {
description = "TTL of IAM keys in days."
type = number
default = 0
}

variable "min_cpu" {
description = "Minimum number of CPU units for your database."
type = number
Expand Down
4 changes: 4 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ terraform {
source = "scaleway/scaleway"
version = ">= 2.43.0"
}
time = {
source = "hashicorp/time"
version = "0.12.0"
}
}
}

0 comments on commit cf39bfe

Please sign in to comment.