Skip to content

Commit

Permalink
feat: add key rotation
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Lefevre <[email protected]>
  • Loading branch information
ArchiFleKs committed Jan 24, 2025
1 parent ba869e7 commit 88b3429
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,15 @@ resource "google_organization_iam_member" "organization_viewer" {
resource "google_service_account_key" "keys" {
for_each = var.generate_keys ? local.names : toset([])
service_account_id = google_service_account.service_accounts[each.value].email
keepers = {
rotation_time = var.key_rotation_days == null ? null : time_rotating.key_rotation["key_rotation_days"].rotation_rfc3339
}

}

resource "time_rotating" "key_rotation" {
for_each = var.key_rotation_days == null ? {} : {
"key_rotation_days" = var.key_rotation_days
}
rotation_days = var.key_rotation_days
}
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,9 @@ variable "descriptions" {
description = "List of descriptions for the created service accounts (elements default to the value of `description`)"
default = []
}

variable "key_rotation_days" {
type = number
description = "Number of days after which the service account key is rotated"
default = null
}
4 changes: 4 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ terraform {
source = "hashicorp/google"
version = ">= 3.53, < 7"
}
time = {
source = "hashicorp/time"
version = "~> 0.12"
}
}

provider_meta "google" {
Expand Down

0 comments on commit 88b3429

Please sign in to comment.