diff --git a/CHANGELOG.md b/CHANGELOG.md index 87eba86..0fd92bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [0.19.0] - 2024-12-3 + +[Compare with previous version](https://github.com/sparkfabrik/terraform-google-gcp-cloud-native-drupal-resources/compare/0.18.0...0.19.0) + +- Refactor of `drupal_apps_all_data` to handle multiple deployment in same `project_name - project-id - release-branch-name` + ## [0.18.0] - 2024-11-29 [Compare with previous version](https://github.com/sparkfabrik/terraform-google-gcp-cloud-native-drupal-resources/compare/0.17.1...0.18.0) diff --git a/outputs.tf b/outputs.tf index a99105f..1d84b6b 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,20 +1,27 @@ locals { + grouped_resources = { + for p in var.drupal_projects_list : "${p.project_name}-${p.gitlab_project_id}-${p.release_branch_name}" => p... + } + all_data = { - for p in var.drupal_projects_list : "${p.project_name}-${p.gitlab_project_id}-${p.release_branch_name}" => { - # Add the values you want to store for each project here - # Example: - namespace = p.kubernetes_namespace == null ? "${p.project_name}-${p.gitlab_project_id}-${p.release_branch_name}" : p.kubernetes_namespace - helm_release_name = p.helm_release_name == null ? "drupal-${p.release_branch_name}-${p.gitlab_project_id}" : p.helm_release_name - bucket_credentials = try(module.drupal_buckets[0].buckets_access_credentials["${p.project_name}-${p.gitlab_project_id}-${p.release_branch_name}-drupal"], null) - database_credentials = try( - [for cred in module.drupal_databases_and_users[0].sql_users_creds : cred - if cred.database == replace("${p.project_name}_${p.gitlab_project_id}_${p.release_branch_name}_dp", "-", "_")][0], null) - kubernetes_bucket_secret = try(local.bucket_secrets_map["${p.project_name}-${p.gitlab_project_id}-${p.release_branch_name}"], null) - kubernetes_database_secret = try(local.database_secrets_map["${p.project_name}-${p.gitlab_project_id}-${p.release_branch_name}"], null) + for key, resources in local.grouped_resources : key => { + for r in resources : (r.helm_release_name != null ? r.helm_release_name : "drupal-${r.release_branch_name}-${r.gitlab_project_id}") => { + namespace = r.kubernetes_namespace == null ? "${r.project_name}-${r.gitlab_project_id}-${r.release_branch_name}" : r.kubernetes_namespace + bucket_credentials = try(module.drupal_buckets[0].buckets_access_credentials["${r.project_name}-${r.gitlab_project_id}-${r.release_branch_name}-drupal"], null) + database_credentials = try( + [for cred in module.drupal_databases_and_users[0].sql_users_creds : cred + if cred.database == ( + r.database_name != null ? + r.database_name : + replace("${r.project_name}_${r.gitlab_project_id}_${r.release_branch_name}_dp", "-", "_") + )][0], null) + kubernetes_bucket_secret = try(local.bucket_secrets_map["${r.project_name}-${r.gitlab_project_id}-${r.release_branch_name}"], null) + kubernetes_database_secret = try(local.database_secrets_map["${r.project_name}-${r.gitlab_project_id}-${r.release_branch_name}-${r.helm_release_name != null ? r.helm_release_name : "drupal-${r.release_branch_name}-${r.gitlab_project_id}"}"], null) + } } } - bucket_secrets_map = { + bucket_secrets_map = var.create_buckets ? { for o in local.drupal_buckets_list : replace(o.name, "-drupal", "") => { secret_name = try( kubernetes_secret.bucket_secret_name[o.name].metadata[0].name, @@ -25,63 +32,77 @@ locals { null ) } - } + } : {} database_secrets_map = { - for p in var.drupal_projects_list : "${p.project_name}-${p.gitlab_project_id}-${p.release_branch_name}" => { + for p in var.drupal_projects_list : "${p.project_name}-${p.gitlab_project_id}-${p.release_branch_name}-${p.helm_release_name != null ? p.helm_release_name : "drupal-${p.release_branch_name}-${p.gitlab_project_id}"}" => { secret_name = try( - kubernetes_secret.database_secret_name[replace("${p.project_name}_${p.gitlab_project_id}_${p.release_branch_name}_dp", "-", "_")].metadata[0].name, - null) + kubernetes_secret.database_secret_name[ + p.helm_release_name != null ? p.helm_release_name : replace("${p.project_name}_${p.gitlab_project_id}_${p.release_branch_name}_dp", "-", "_") + ].metadata[0].name, + null + ) namespace = try( - kubernetes_secret.database_secret_name[replace("${p.project_name}_${p.gitlab_project_id}_${p.release_branch_name}_dp", "-", "_")].metadata[0].namespace, + kubernetes_secret.database_secret_name[ + p.helm_release_name != null ? p.helm_release_name : replace("${p.project_name}_${p.gitlab_project_id}_${p.release_branch_name}_dp", "-", "_") + ].metadata[0].namespace, null ) } } } - output "drupal_apps_all_data" { description = "All data for each Drupal project." value = local.all_data } -output "drupal_apps_all_bucket_credentials" { - description = "Bucket credentials for each Drupal project" - sensitive = true +output "drupal_apps_all_namespaces" { + description = "Map of all Kubernetes namespaces used by Drupal apps, indexed same as all_data" value = { - for key, value in local.all_data : key => value.bucket_credentials + for key, values in local.all_data : key => { + for helm_release, data in values : helm_release => data.namespace + } } } -output "drupal_apps_all_database_credentials" { - description = "Database credentials for each Drupal project" +output "drupal_apps_all_bucket_credentials" { + description = "Bucket credentials for each Drupal project, indexed same as all_data" sensitive = true value = { - for key, value in local.all_data : key => value.database_credentials + for key, values in local.all_data : key => { + for helm_release, data in values : helm_release => data.bucket_credentials + } } } output "drupal_apps_all_bucket_secrets" { - description = "Bucket kubernetes secrets for each Drupal project" + description = "Bucket kubernetes secrets for each Drupal project, indexed same as all_data" sensitive = true value = { - for key, value in local.all_data : key => value.kubernetes_bucket_secret + for key, values in local.all_data : key => { + for helm_release, data in values : helm_release => data.kubernetes_bucket_secret + } } } -output "drupal_apps_all_database_secrets" { - description = "Database kubernetes secrets for each Drupal project" +output "drupal_apps_all_database_credentials" { + description = "Database credentials for each Drupal project, indexed same as all_data" sensitive = true value = { - for key, value in local.all_data : key => value.kubernetes_database_secret + for key, values in local.all_data : key => { + for helm_release, data in values : helm_release => data.database_credentials + } } } -output "drupal_apps_all_namespaces" { - description = "Namespace for each Drupal project" +output "drupal_apps_all_database_secrets" { + description = "Database kubernetes secrets for each Drupal project, indexed same as all_data" + sensitive = true value = { - for key, value in local.all_data : key => value.namespace + for key, values in local.all_data : key => { + for helm_release, data in values : helm_release => data.kubernetes_database_secret + } } }