From 2bc634ec7ce209c4eeb9ffc60f71aa3b8c851ce7 Mon Sep 17 00:00:00 2001 From: Abhishek Tiwari Date: Wed, 30 Oct 2024 19:28:44 +0000 Subject: [PATCH] feat: Add new output variable called database_names --- modules/mysql/README.md | 1 + modules/mysql/metadata.yaml | 18 ++++++++++++------ modules/mysql/outputs.tf | 9 +++++++++ modules/postgresql/README.md | 1 + modules/postgresql/metadata.yaml | 18 ++++++++++++------ modules/postgresql/outputs.tf | 9 +++++++++ 6 files changed, 44 insertions(+), 12 deletions(-) diff --git a/modules/mysql/README.md b/modules/mysql/README.md index d488eacb..aea6c3cb 100644 --- a/modules/mysql/README.md +++ b/modules/mysql/README.md @@ -111,6 +111,7 @@ module "mysql-db" { |------|-------------| | additional\_users | List of maps of additional users and passwords | | apphub\_service\_uri | Service URI in CAIS style to be used by Apphub. | +| database\_names | List of all database names created. | | env\_vars | Exported environment variables | | generated\_user\_password | The auto generated default user password if not input password was provided | | iam\_users | The list of the IAM users with access to the CloudSQL instance | diff --git a/modules/mysql/metadata.yaml b/modules/mysql/metadata.yaml index 8da7525f..ec5333be 100644 --- a/modules/mysql/metadata.yaml +++ b/modules/mysql/metadata.yaml @@ -329,11 +329,12 @@ spec: })) defaultValue: [] - name: iam_users - description: A list of IAM users to be created in your CloudSQL instance + description: A list of IAM users to be created in your CloudSQL instance. iam.users.type can be CLOUD_IAM_USER, CLOUD_IAM_SERVICE_ACCOUNT, CLOUD_IAM_GROUP and is required for type CLOUD_IAM_GROUP (IAM groups) varType: |- list(object({ id = string, - email = string + email = string, + type = optional(string) })) defaultValue: [] connections: @@ -341,12 +342,12 @@ spec: source: github.com/terraform-google-modules/terraform-google-service-accounts//modules/simple-sa version: ~> 4.4 spec: - outputExpr: account_details + outputExpr: '{"id": account_details.id, "email": account_details.email, "type": "CLOUD_IAM_SERVICE_ACCOUNT"}' - source: source: github.com/GoogleCloudPlatform/terraform-google-cloud-run//modules/v2 version: ~> 0.13 spec: - outputExpr: service_account_id + outputExpr: '{"id": service_account_id.id, "email": service_account_id.email, "type": "CLOUD_IAM_SERVICE_ACCOUNT"}' - name: create_timeout description: The optional timout that is applied to limit long database creates. varType: string @@ -413,6 +414,11 @@ spec: - object - service_id: string service_uri: string + - name: database_names + description: List of all database names created. + type: + - list + - - string - name: env_vars description: Exported environment variables type: @@ -922,9 +928,9 @@ spec: - workflows.googleapis.com providerVersions: - source: hashicorp/google - version: ">= 5.25, < 7" + version: ">= 6.1, < 7" - source: hashicorp/google-beta - version: ">= 5.25, < 7" + version: ">= 6.1, < 7" - source: hashicorp/null version: ~> 3.1 - source: hashicorp/random diff --git a/modules/mysql/outputs.tf b/modules/mysql/outputs.tf index 3f10fa8e..149edf10 100644 --- a/modules/mysql/outputs.tf +++ b/modules/mysql/outputs.tf @@ -146,6 +146,15 @@ output "instances" { sensitive = true } +output "database_names" { + value = concat([ + for db in google_sql_database.default : db.name + ], [ + for db in google_sql_database.additional_databases : db.name + ]) + description = "List of all database names created." +} + output "env_vars" { description = "Exported environment variables" value = { diff --git a/modules/postgresql/README.md b/modules/postgresql/README.md index ff7afe61..fb785d95 100644 --- a/modules/postgresql/README.md +++ b/modules/postgresql/README.md @@ -181,6 +181,7 @@ module "pg" { |------|-------------| | additional\_users | List of maps of additional users and passwords | | apphub\_service\_uri | Service URI in CAIS style to be used by Apphub. | +| database\_names | List of all database names created. | | dns\_name | DNS name of the instance endpoint | | env\_vars | Exported environment variables | | generated\_user\_password | The auto generated default user password if not input password was provided | diff --git a/modules/postgresql/metadata.yaml b/modules/postgresql/metadata.yaml index e60b0e5c..8c18b9af 100644 --- a/modules/postgresql/metadata.yaml +++ b/modules/postgresql/metadata.yaml @@ -309,11 +309,12 @@ spec: })) defaultValue: [] - name: iam_users - description: A list of IAM users to be created in your CloudSQL instance + description: A list of IAM users to be created in your CloudSQL instance. iam.users.type can be CLOUD_IAM_USER, CLOUD_IAM_SERVICE_ACCOUNT, CLOUD_IAM_GROUP and is required for type CLOUD_IAM_GROUP (IAM groups) varType: |- list(object({ id = string, - email = string + email = string, + type = optional(string) })) defaultValue: [] connections: @@ -321,12 +322,12 @@ spec: source: github.com/terraform-google-modules/terraform-google-service-accounts//modules/simple-sa version: ~> 4.4 spec: - outputExpr: account_details + outputExpr: '{"id": account_details.id, "email": account_details.email, "type": "CLOUD_IAM_SERVICE_ACCOUNT"}' - source: source: github.com/GoogleCloudPlatform/terraform-google-cloud-run//modules/v2 version: ~> 0.13 spec: - outputExpr: service_account_id + outputExpr: '{"id": service_account_id.id, "email": service_account_id.email, "type": "CLOUD_IAM_SERVICE_ACCOUNT"}' - name: create_timeout description: The optional timout that is applied to limit long database creates. varType: string @@ -403,6 +404,11 @@ spec: - object - service_id: string service_uri: string + - name: database_names + description: List of all database names created. + type: + - list + - - string - name: dns_name description: DNS name of the instance endpoint type: string @@ -912,9 +918,9 @@ spec: - workflows.googleapis.com providerVersions: - source: hashicorp/google - version: ">= 5.25, < 7" + version: ">= 6.1, < 7" - source: hashicorp/google-beta - version: ">= 5.25, < 7" + version: ">= 6.1, < 7" - source: hashicorp/null version: ~> 3.1 - source: hashicorp/random diff --git a/modules/postgresql/outputs.tf b/modules/postgresql/outputs.tf index 020570b1..dd9755da 100644 --- a/modules/postgresql/outputs.tf +++ b/modules/postgresql/outputs.tf @@ -144,6 +144,15 @@ output "dns_name" { description = "DNS name of the instance endpoint" } +output "database_names" { + value = concat([ + for db in google_sql_database.default : db.name + ], [ + for db in google_sql_database.additional_databases : db.name + ]) + description = "List of all database names created." +} + output "env_vars" { description = "Exported environment variables" value = {