Add support for KMS key creation to project factory (#3518)

* initial implementation

* context

* tfdoc

* add support for autokey to projects

* fix typo
This commit is contained in:
Ludovico Magnocavallo
2025-11-11 07:23:50 +01:00
committed by GitHub
parent 15a5486a1e
commit fc7aa71ada
20 changed files with 905 additions and 49 deletions

File diff suppressed because one or more lines are too long

View File

@@ -150,6 +150,16 @@ resource "google_resource_manager_lien" "lien" {
reason = var.lien_reason
}
resource "google_kms_key_handle" "default" {
for_each = var.kms_autokeys
project = local.project.project_id
name = each.key
location = try(
local.ctx.locations[each.value.location], each.value.location
)
resource_type_selector = each.value.resource_type_selector
}
resource "google_essential_contacts_contact" "contact" {
provider = google-beta
for_each = var.contacts

View File

@@ -66,6 +66,13 @@ output "id" {
]
}
output "kms_autokeys" {
description = "KMS Autokey key ids."
value = {
for k, v in google_kms_key_handle.default : k => v.kms_key
}
}
output "name" {
description = "Project name."
value = local.project.name

View File

@@ -166,6 +166,24 @@ variable "factories_config" {
default = {}
}
variable "kms_autokeys" {
description = "KMS Autokey key handles."
type = map(object({
location = string
resource_type_selector = optional(string, "compute.googleapis.com/Disk")
}))
nullable = false
default = {}
validation {
condition = alltrue([
for k, v in var.kms_autokeys : k == try(regex(
"^[a-z][a-z0-9-]+[a-z0-9]$", k
), null)
])
error_message = "Autokey keys need to be valid GCP resource names."
}
}
variable "labels" {
description = "Resource labels."
type = map(string)