From fbfbcb212b1694354b1e7554b4fba93c3520caaa Mon Sep 17 00:00:00 2001 From: Anthony Lukach Date: Wed, 30 Oct 2024 18:54:28 -0700 Subject: [PATCH] Conditionally set admin env vars based on keycloak version --- deploy/lib/KeycloakService.ts | 12 ++++++++++-- deploy/lib/KeycloakStack.ts | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/deploy/lib/KeycloakService.ts b/deploy/lib/KeycloakService.ts index abcc55e..e0f7583 100644 --- a/deploy/lib/KeycloakService.ts +++ b/deploy/lib/KeycloakService.ts @@ -13,6 +13,7 @@ interface KeycloakServiceProps extends StackInputProps { vpc: ec2.IVpc; databaseName: string; databaseInstance: rds.DatabaseInstance; + version: string; } export class KeycloakService extends Construct { @@ -91,8 +92,15 @@ export class KeycloakService extends Construct { KC_DB_URL_PORT: ecsDbSecret("port"), // Admin - KEYCLOAK_ADMIN: ecsAdminSecret("username"), - KEYCLOAK_ADMIN_PASSWORD: ecsAdminSecret("password"), + ...(parseInt(props.version.split(".")[0]) >= 26 + ? { + KEYCLOAK_ADMIN: ecsAdminSecret("username"), + KEYCLOAK_ADMIN_PASSWORD: ecsAdminSecret("password"), + } + : { + KC_BOOTSTRAP_ADMIN_USERNAME: ecsAdminSecret("username"), + KC_BOOTSTRAP_ADMIN_PASSWORD: ecsAdminSecret("password"), + }), }, }, } diff --git a/deploy/lib/KeycloakStack.ts b/deploy/lib/KeycloakStack.ts index 52404ef..3c5fec4 100644 --- a/deploy/lib/KeycloakStack.ts +++ b/deploy/lib/KeycloakStack.ts @@ -36,6 +36,7 @@ export class KeycloakStack extends cdk.Stack { vpc, databaseName, databaseInstance: database, + version: props.keycloakVersion, ...props, });