Resolve the shared Keycloak collection by its exact Vaultwarden name
This commit is contained in:
1 parent
dd591ecd1d
commit
62480ceed7
3 files changed
+25
-22
No files matched your search
@@ -52,8 +52,6 @@ jobs:
|
||||
TF_VAR_keycloak_client_secret: ${{ secrets.KEYCLOAK_CLIENT_SECRET }}
|
||||
TF_VAR_google_client_id: ${{ secrets.GOOGLE_CLIENT_ID }}
|
||||
TF_VAR_google_client_secret: ${{ secrets.GOOGLE_CLIENT_SECRET }}
|
||||
TF_VAR_vaultwarden_organization_id: ${{ vars.VAULTWARDEN_ORGANIZATION_ID }}
|
||||
TF_VAR_vaultwarden_collection_id: ${{ vars.VAULTWARDEN_COLLECTION_ID }}
|
||||
BW_CLIENTID: ${{ secrets.BW_CLIENTID }}
|
||||
BW_CLIENTSECRET: ${{ secrets.BW_CLIENTSECRET }}
|
||||
BW_PASSWORD: ${{ secrets.BW_PASSWORD }}
|
||||
|
||||
@@ -274,14 +274,37 @@ resource "keycloak_openid_client" "oauth2_app" {
|
||||
access_token_lifespan = each.value.access_token_lifespan
|
||||
}
|
||||
|
||||
data "bitwarden_organization" "homelab" {
|
||||
search = "Hexor Lab"
|
||||
|
||||
lifecycle {
|
||||
postcondition {
|
||||
condition = self.name == self.search
|
||||
error_message = "The Vaultwarden organization must match exactly."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data "bitwarden_org_collection" "keycloak_apps" {
|
||||
organization_id = data.bitwarden_organization.homelab.id
|
||||
search = "K8S-Secrets/Keycloak apps"
|
||||
|
||||
lifecycle {
|
||||
postcondition {
|
||||
condition = self.name == self.search
|
||||
error_message = "The Vaultwarden collection must match exactly."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "bitwarden_item_login" "oauth2_app" {
|
||||
for_each = { for key, app in var.oauth2_applications : key => app if app.publish_to_vaultwarden }
|
||||
|
||||
name = "keycloak/${each.key}"
|
||||
username = keycloak_openid_client.oauth2_app[each.key].client_id
|
||||
password = keycloak_openid_client.oauth2_app[each.key].client_secret
|
||||
organization_id = var.vaultwarden_organization_id
|
||||
collection_ids = [var.vaultwarden_collection_id]
|
||||
organization_id = data.bitwarden_organization.homelab.id
|
||||
collection_ids = [data.bitwarden_org_collection.keycloak_apps.id]
|
||||
}
|
||||
|
||||
resource "keycloak_openid_group_membership_protocol_mapper" "oauth2_app_groups" {
|
||||
|
||||
@@ -57,21 +57,3 @@ variable "oauth2_applications" {
|
||||
}))
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "vaultwarden_organization_id" {
|
||||
description = "Vaultwarden organization receiving published Keycloak client credentials"
|
||||
type = string
|
||||
validation {
|
||||
condition = can(regex("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$", var.vaultwarden_organization_id))
|
||||
error_message = "Set the UUID of the target Vaultwarden organization."
|
||||
}
|
||||
}
|
||||
|
||||
variable "vaultwarden_collection_id" {
|
||||
description = "Vaultwarden collection shared by the Terraform writer and application secret reader"
|
||||
type = string
|
||||
validation {
|
||||
condition = can(regex("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$", var.vaultwarden_collection_id))
|
||||
error_message = "Set the UUID of the target Vaultwarden collection."
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user