Skip to content

Commit

Permalink
Merge pull request #45 from sparkfabrik/3237-enhance-output-of-module…
Browse files Browse the repository at this point in the history
…-terraform-google-gcp-cloud-native-drupal-resources

3237 enhance output of module terraform google gcp cloud native drupal resources
  • Loading branch information
Stevesibilia authored Nov 29, 2024
2 parents 373f402 + e678d44 commit 23d239f
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ The variable structure is the following:
# If not specified, the kubernetes_namespace by default it is built as
# <project_name>-<gitlab_project_id>-<release_branch_name>.
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 <project_name>_<gitlab_project_id>_<release_branch_name>_dp, where dp stands for Drupal.
Expand Down Expand Up @@ -143,6 +145,12 @@ the random suffix `bucket_append_random_suffix` for the bucket name.
| <a name="output_cloudsql_dumps_bucket_name"></a> [cloudsql\_dumps\_bucket\_name](#output\_cloudsql\_dumps\_bucket\_name) | CloudSQL dumps bucket name. |
| <a name="output_details_of_used_tag_keys"></a> [details\_of\_used\_tag\_keys](#output\_details\_of\_used\_tag\_keys) | Details of the tag keys passed to this module. |
| <a name="output_details_of_used_tag_values"></a> [details\_of\_used\_tag\_values](#output\_details\_of\_used\_tag\_values) | Details of the tag values passed to this module. |
| <a name="output_drupal_apps_all_bucket_credentials"></a> [drupal\_apps\_all\_bucket\_credentials](#output\_drupal\_apps\_all\_bucket\_credentials) | Bucket credentials for each Drupal project |
| <a name="output_drupal_apps_all_bucket_secrets"></a> [drupal\_apps\_all\_bucket\_secrets](#output\_drupal\_apps\_all\_bucket\_secrets) | Bucket kubernetes secrets for each Drupal project |
| <a name="output_drupal_apps_all_data"></a> [drupal\_apps\_all\_data](#output\_drupal\_apps\_all\_data) | All data for each Drupal project. |
| <a name="output_drupal_apps_all_database_credentials"></a> [drupal\_apps\_all\_database\_credentials](#output\_drupal\_apps\_all\_database\_credentials) | Database credentials for each Drupal project |
| <a name="output_drupal_apps_all_database_secrets"></a> [drupal\_apps\_all\_database\_secrets](#output\_drupal\_apps\_all\_database\_secrets) | Database kubernetes secrets for each Drupal project |
| <a name="output_drupal_apps_all_namespaces"></a> [drupal\_apps\_all\_namespaces](#output\_drupal\_apps\_all\_namespaces) | Namespace for each Drupal project |
| <a name="output_drupal_apps_bucket_credentials"></a> [drupal\_apps\_bucket\_credentials](#output\_drupal\_apps\_bucket\_credentials) | Drupal apps bucket credentials for each Drupal project. |
| <a name="output_drupal_apps_database_credentials"></a> [drupal\_apps\_database\_credentials](#output\_drupal\_apps\_database\_credentials) | Drupal apps database credentials for each Drupal project. |
| <a name="output_drupal_buckets_names_list"></a> [drupal\_buckets\_names\_list](#output\_drupal\_buckets\_names\_list) | The list with the names of the Drupal buckets managed by this module. |
Expand Down
87 changes: 87 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -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."
Expand Down

0 comments on commit 23d239f

Please sign in to comment.