diff --git a/README.md b/README.md index db05af9..2429c90 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,9 @@ The variable structure is the following: # If not specified, the kubernetes_namespace by default it is built as # --. kubernetes_namespace = optional(string, null) - # By default it corresponds to the Drupal PKG release that corresponds to + # Namespace labels added to default_k8s_labels + kubernetes_namespace_labels = optional(map(string), {}) + # The Helm release name by default corresponds to the Drupal PKG release that corresponds to # drupal-${CI_COMMIT_REF_SLUG}-${CI_PROJECT_ID} and is used for the name of secrets. helm_release_name = optional(string, null) # By default the name is ___dp, where dp stands for Drupal. @@ -143,6 +145,12 @@ the random suffix `bucket_append_random_suffix` for the bucket name. | [cloudsql\_dumps\_bucket\_name](#output\_cloudsql\_dumps\_bucket\_name) | CloudSQL dumps bucket name. | | [details\_of\_used\_tag\_keys](#output\_details\_of\_used\_tag\_keys) | Details of the tag keys passed to this module. | | [details\_of\_used\_tag\_values](#output\_details\_of\_used\_tag\_values) | Details of the tag values passed to this module. | +| [drupal\_apps\_all\_bucket\_credentials](#output\_drupal\_apps\_all\_bucket\_credentials) | Bucket credentials for each Drupal project | +| [drupal\_apps\_all\_bucket\_secrets](#output\_drupal\_apps\_all\_bucket\_secrets) | Bucket kubernetes secrets for each Drupal project | +| [drupal\_apps\_all\_data](#output\_drupal\_apps\_all\_data) | All data for each Drupal project. | +| [drupal\_apps\_all\_database\_credentials](#output\_drupal\_apps\_all\_database\_credentials) | Database credentials for each Drupal project | +| [drupal\_apps\_all\_database\_secrets](#output\_drupal\_apps\_all\_database\_secrets) | Database kubernetes secrets for each Drupal project | +| [drupal\_apps\_all\_namespaces](#output\_drupal\_apps\_all\_namespaces) | Namespace for each Drupal project | | [drupal\_apps\_bucket\_credentials](#output\_drupal\_apps\_bucket\_credentials) | Drupal apps bucket credentials for each Drupal project. | | [drupal\_apps\_database\_credentials](#output\_drupal\_apps\_database\_credentials) | Drupal apps database credentials for each Drupal project. | | [drupal\_buckets\_names\_list](#output\_drupal\_buckets\_names\_list) | The list with the names of the Drupal buckets managed by this module. | diff --git a/outputs.tf b/outputs.tf index f6bc838..a99105f 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,3 +1,90 @@ +locals { + 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) + } + } + + bucket_secrets_map = { + for o in local.drupal_buckets_list : replace(o.name, "-drupal", "") => { + secret_name = try( + kubernetes_secret.bucket_secret_name[o.name].metadata[0].name, + null + ) + namespace = try( + kubernetes_secret.bucket_secret_name[o.name].metadata[0].namespace, + null + ) + } + } + + database_secrets_map = { + for p in var.drupal_projects_list : "${p.project_name}-${p.gitlab_project_id}-${p.release_branch_name}" => { + 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) + namespace = try( + kubernetes_secret.database_secret_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 + value = { + for key, value in local.all_data : key => value.bucket_credentials + } +} + +output "drupal_apps_all_database_credentials" { + description = "Database credentials for each Drupal project" + sensitive = true + value = { + for key, value in local.all_data : key => value.database_credentials + } +} + +output "drupal_apps_all_bucket_secrets" { + description = "Bucket kubernetes secrets for each Drupal project" + sensitive = true + value = { + for key, value in local.all_data : key => value.kubernetes_bucket_secret + } +} + +output "drupal_apps_all_database_secrets" { + description = "Database kubernetes secrets for each Drupal project" + sensitive = true + value = { + for key, value in local.all_data : key => value.kubernetes_database_secret + } +} + +output "drupal_apps_all_namespaces" { + description = "Namespace for each Drupal project" + value = { + for key, value in local.all_data : key => value.namespace + } +} + output "drupal_apps_database_credentials" { sensitive = true description = "Drupal apps database credentials for each Drupal project."