Skip to content

[Minor] Refactor to native-ize resources #7

Merged
merged 49 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
448c055
♻️ refactor(main.tf): native-ized scripts for tf execution
morga471 Apr 25, 2025
c1dbf52
add db config to config-job.tf
morga471 Apr 28, 2025
0c24e81
update config in server values to match
morga471 Apr 28, 2025
ee1e3bd
🐛 fix(outputs.tf): update namespace refs
morga471 Apr 28, 2025
ad51a17
🔧 config(keycloak): set replicas to 1 then update replicas after setu…
morga471 Apr 28, 2025
8a930f3
🐛 fix(config): move auth to top level to match chart
morga471 Apr 28, 2025
06df16d
static config
morga471 Apr 28, 2025
8620a62
Fix heredoc string
morga471 Apr 28, 2025
9796643
change config user
morga471 Apr 28, 2025
dc85b73
use secrets again
morga471 Apr 28, 2025
2ae8bd2
pass keys
morga471 Apr 28, 2025
5484acc
add auth username
morga471 Apr 28, 2025
1fa4388
try not to config db twice
morga471 Apr 28, 2025
29ea8e4
password
morga471 Apr 28, 2025
f47fb29
update chart values
morga471 Apr 28, 2025
c9e54aa
fix syntax in config_job.tf
morga471 Apr 28, 2025
783474d
fix metrics permissions
morga471 Apr 28, 2025
7839b1b
try admin port
morga471 Apr 28, 2025
9cc241b
exit codes
morga471 Apr 28, 2025
03a9143
healcheck
morga471 Apr 28, 2025
956b7a5
remove keycloak healthcheck which requires ingress to exist
morga471 Apr 28, 2025
cb32ed5
remove login_with_retry
morga471 Apr 28, 2025
f70a710
add functions change order
morga471 Apr 28, 2025
2faab13
update execute sql func
morga471 Apr 28, 2025
469c72d
update password usage for psql
morga471 Apr 28, 2025
70748d2
use export
morga471 Apr 28, 2025
bf176c8
fix sql
morga471 Apr 28, 2025
6069524
use bash
morga471 Apr 28, 2025
4d3f559
globbing
morga471 Apr 28, 2025
cc548f0
fix globbing and use a HEREDOC
morga471 Apr 28, 2025
920dcd3
try not to launch new shell
morga471 Apr 28, 2025
23b4c2a
typo
morga471 Apr 28, 2025
224eb2d
syntax
morga471 Apr 28, 2025
f49a33e
remove parens from password gen
morga471 Apr 28, 2025
1bc63bd
remove quotes
morga471 Apr 28, 2025
2e90c72
try ref existing var
morga471 Apr 28, 2025
bb7ad9a
assume keycloak is available
morga471 Apr 28, 2025
daff6ad
cleanup
morga471 Apr 28, 2025
ca9b417
fix syntax
morga471 Apr 28, 2025
66a3e2f
remove failed idea
morga471 Apr 28, 2025
e7c74fa
remove jq pieces
morga471 Apr 28, 2025
883eec2
remove jq
morga471 Apr 29, 2025
5d8954d
simplify more
morga471 Apr 29, 2025
092527f
more cleanup
morga471 Apr 29, 2025
08b1073
return codes
morga471 Apr 29, 2025
83184cb
add restart_server func again
morga471 Apr 29, 2025
c301b1e
remove restart
morga471 Apr 29, 2025
eaa00b7
refactor script
morga471 Apr 29, 2025
a1e8dca
revert
morga471 Apr 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .cz.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---
commitizen:
name: cz_conventional_commits
tag_format: v$version
version: 0.1.0
version_files:
- version.tf:module_version
bump_message: "bump: version $current_version → $new_version"
changelog_incremental: true
major_version_zero: true
name: cz_gitmoji
tag_format: $version
update_changelog_on_bump: true
version_files:
- version.tf:module_version
version_provider: scm
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ repos:

# Terraform Hooks
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.98.0 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases
rev: v1.99.0 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases
hooks:
- id: terraform_fmt
args:
Expand Down
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ Common issues and solutions:

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.95.0 |
| <a name="provider_aws.eecr"></a> [aws.eecr](#provider\_aws.eecr) | 5.95.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.96.0 |
| <a name="provider_aws.eecr"></a> [aws.eecr](#provider\_aws.eecr) | 5.96.0 |
| <a name="provider_helm"></a> [helm](#provider\_helm) | 2.17.0 |
| <a name="provider_kubernetes"></a> [kubernetes](#provider\_kubernetes) | 2.36.0 |
| <a name="provider_null"></a> [null](#provider\_null) | 3.2.4 |
Expand All @@ -89,9 +89,7 @@ Common issues and solutions:
|------|--------|---------|
| <a name="module_images"></a> [images](#module\_images) | git::https://github.e.it.census.gov/terraform-modules/aws-ecr-copy-images.git/ | tf-upgrade |
| <a name="module_ingress_resources"></a> [ingress\_resources](#module\_ingress\_resources) | git::https://github.e.it.census.gov/SCT-Engineering/tfmod-istio-service-ingress.git | n/a |
| <a name="module_keycloak_db_config"></a> [keycloak\_db\_config](#module\_keycloak\_db\_config) | git::https://github.e.it.census.gov/SCT-Engineering/tfmod-config-job.git//config-job | n/a |
| <a name="module_post_install"></a> [post\_install](#module\_post\_install) | git::https://github.e.it.census.gov/SCT-Engineering/tfmod-config-job.git//config-job | n/a |
| <a name="module_pre_install"></a> [pre\_install](#module\_pre\_install) | git::https://github.e.it.census.gov/SCT-Engineering/tfmod-config-job.git//config-job | n/a |
| <a name="module_service_account"></a> [service\_account](#module\_service\_account) | git::https://github.e.it.census.gov/SCT-Engineering/tfmod-config-job.git//service-account | n/a |

## Resources
Expand All @@ -101,11 +99,12 @@ Common issues and solutions:
| [helm_release.keycloak](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [helm_release.keycloak-db](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [kubernetes_namespace.keycloak](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/namespace) | resource |
| [kubernetes_secret.keycloak_secrets](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/secret) | resource |
| [null_resource.git_version](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
| [random_password.passwords](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
| [random_uuid.user_secret](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/uuid) | resource |
| [aws_ecr_authorization_token.ecr_token](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ecr_authorization_token) | data source |
| [aws_ecr_authorization_token.token](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ecr_authorization_token) | data source |
| [kubernetes_secret.db-secrets](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/data-sources/secret) | data source |

## Inputs

Expand All @@ -118,10 +117,9 @@ Common issues and solutions:
| <a name="input_default_realm"></a> [default\_realm](#input\_default\_realm) | The default realm to use to configure the environment. | `string` | `"cluster-user"` | no |
| <a name="input_eecr_info"></a> [eecr\_info](#input\_eecr\_info) | Enterprise ECR source information | <pre>object({<br/> account_id = string<br/> alias = string<br/> profile = string<br/> region = string<br/> })</pre> | <pre>{<br/> "account_id": "269222635945",<br/> "alias": "lab-gov-shared-nonprod",<br/> "profile": "269222635945-lab-gov-shared-nonprod",<br/> "region": "us-gov-east-1"<br/>}</pre> | no |
| <a name="input_keycloak_chart_version"></a> [keycloak\_chart\_version](#input\_keycloak\_chart\_version) | The version of the helm chart to install | `string` | `"7.0.1"` | no |
| <a name="input_keycloak_hostname"></a> [keycloak\_hostname](#input\_keycloak\_hostname) | The hostname used to access the keycloak service. | `string` | `"keycloak"` | no |
| <a name="input_keycloak_namespace"></a> [keycloak\_namespace](#input\_keycloak\_namespace) | The namespace which will be created and into which keycloak will be deployed. | `string` | `"keycloak"` | no |
| <a name="input_keycloak_tag"></a> [keycloak\_tag](#input\_keycloak\_tag) | The image tag associated with the keycloak\_chart\_version | `string` | `"26.0.7"` | no |
| <a name="input_keycloak_user"></a> [keycloak\_user](#input\_keycloak\_user) | The username for the database. | `string` | `"keycloak"` | no |
| <a name="input_namespace"></a> [namespace](#input\_namespace) | The namespace which will be created and into which keycloak will be deployed. | `string` | `"keycloak"` | no |
| <a name="input_postgres_exporter_tag"></a> [postgres\_exporter\_tag](#input\_postgres\_exporter\_tag) | The tag of the postgres exporter image to use. | `string` | `"17.4.0"` | no |
| <a name="input_postgresql_chart_version"></a> [postgresql\_chart\_version](#input\_postgresql\_chart\_version) | The helm chart version of postgresql to use. | `string` | `"17.4.0"` | no |
| <a name="input_postgresql_tag"></a> [postgresql\_tag](#input\_postgresql\_tag) | The tag of the postgresql image to use. | `string` | `"17.4.0"` | no |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ database:
vendor: postgres
hostname: keycloak-db-postgresql
port: 5432
username: dbusername
password: dbpassword
username: keycloak
password: keycloak
existingSecret: ${secret_name}
existingSecretKey: ${database_password_key}
database: keycloak

secrets:
Expand Down
23 changes: 23 additions & 0 deletions config_job.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
locals {
config_job_script = <<CONFIG
rootUrl=""
redirectUrl="https://*"
login && \
create_realm ${var.default_realm} && \
create_admin_user ${var.default_realm} \
"$(kc_user)" "$(kc_passwd)" "${var.admin_email}" && \
create_realm_role ${var.default_realm} admin \
"Admin role for ${var.default_realm}" && \
create_realm_role ${var.default_realm} user \
"User role for ${var.default_realm}" && \
add_realm_role_to_user ${var.default_realm} user user && \
create_client "${var.default_realm}" "${local.user_client_id}" \
"${random_uuid.user_secret.result}" "$rootUrl" "" \
"[ \"$redirectUrl\" ]" "" 1 && \
add_mapper_to_client "${var.default_realm}" \
"$(get_client_id "${var.default_realm}" "${local.user_client_id}")" \
"realm roles" "openid-connect" "oidc-usermodel-realm-role-mapper" \
"{ \"multivalued\": \"true\", \"userinfo.token.claim\": \"true\", \"user.attribute\": \"foo\", \"id.token.claim\": \"true\", \"access.token.claim\": \"true\", \"claim.name\": \"realm_access.roles\", \"jsonType.label\": \"String\" }" && \
restart_server
CONFIG
}
26 changes: 18 additions & 8 deletions keycloak-db-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@ global:
security:
allowInsecureImages: true
postgresql:
architecture: replication
auth:
database: keycloak
existingSecret: keycloak-db-creds
postgresPassword: ${postgres_password_key}
username: ${database_user}
database: ${database_name}
existingSecret: ${secret_name}
secretKeys:
adminPasswordKey: password
userPasswordKey: postgres-password
replicationPasswordKey: replication-password
adminPasswordKey: ${postgres_password_key}
replicationPasswordKey: ${replication_password_key}
userPasswordKey: ${database_password_key}

architecture: standalone

replication:
applicationName: ${database_name}

image:
registry:
registry: ${image_registry}
repository: ${image_repository}
tag: ${image_tag}

volumePermissions:
image:
Expand All @@ -23,7 +31,9 @@ volumePermissions:
metrics:
enabled: true
image:
registry:
registry: ${metrics_registry}
repository: ${metrics_repository}
tag: ${metrics_tag}

primary:
resources:
Expand Down
34 changes: 25 additions & 9 deletions keycloak-server-values.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# See https://www.keycloak.org/server/configuration
# See https://www.keycloak.org/server/all-config

replicas: 3
image:
repository: "${image_registry}/${image_repository}"
tag: "${image_tag}"

skipInitContainers: true
autoscaling:
enabled: ${autoscaling}
minReplicas: 1
maxReplicas: 1

command:
- "/opt/keycloak/bin/kc.sh"
Expand All @@ -20,12 +26,12 @@ extraEnv: |
- name: KC_BOOTSTRAP_ADMIN_USERNAME
valueFrom:
secretKeyRef:
name: keycloak-user-creds
name: ${keycloak_user_creds}
key: username
- name: KC_BOOTSTRAP_ADMIN_PASSWORD
valueFrom:
secretKeyRef:
name: keycloak-user-creds
name: ${keycloak_user_creds}
key: password
- name: JAVA_OPTS_APPEND
value: >-
Expand All @@ -34,8 +40,12 @@ extraEnv: |
-Djava.awt.headless=true
-Djgroups.dns.query={{ include "keycloak.fullname" . }}-headless
# dbchecker:
# enabled: true
# Requires utilities
dbchecker:
enabled: true
image:
repository: ${db_checker_image_repo}
tag: ${db_checker_tag}
resources:
requests:
cpu: 500m
Expand All @@ -48,11 +58,17 @@ database:
vendor: postgres
hostname: ${database_hostname}
port: 5432
username: ${database_username}
# password: dbpassword
existingSecret: keycloak-db-creds
existingSecretKey: password
database: ${database_name}
existingSecret: ${secret_name}
secretKeys:
adminPasswordKey: ${database_password_key}
userPasswordKey: ${postgres_password_key}
replicationPasswordKey: ${replication_password_key}
# username: keycloak
# password: keycloak
# password: dbpassword
# existingSecret: ${secret_name}
# existingSecretKey: ${database_password_key}

http:
relativePath: "/"
Expand Down
Loading