From 84498bfaa180b407248491cd1e593d7e9d58a193 Mon Sep 17 00:00:00 2001 From: Jieyu Tian Date: Thu, 17 Oct 2024 02:07:04 +0000 Subject: [PATCH 1/6] Add Apphub URI output to Cloud SQL modules --- modules/mssql/metadata.yaml | 15 +++++++++++++++ modules/mssql/outputs.tf | 8 ++++++++ modules/mysql/metadata.yaml | 21 ++++++++++++++++++--- modules/mysql/outputs.tf | 8 ++++++++ modules/postgresql/metadata.yaml | 21 ++++++++++++++++++--- modules/postgresql/outputs.tf | 8 ++++++++ 6 files changed, 75 insertions(+), 6 deletions(-) diff --git a/modules/mssql/metadata.yaml b/modules/mssql/metadata.yaml index 516e7119..bc64fae5 100644 --- a/modules/mssql/metadata.yaml +++ b/modules/mssql/metadata.yaml @@ -304,6 +304,12 @@ spec: type: - tuple - [] + - name: apphub_service_uri + description: Service URI in CAIS style to be used by Apphub. + type: + - object + service_id: string + service_uri: string - name: generated_user_password description: The auto generated default user password if not input password was provided type: string @@ -564,3 +570,12 @@ spec: - serviceusage.googleapis.com - sqladmin.googleapis.com - workflows.googleapis.com + providerVersions: + - source: hashicorp/google + version: ">= 5.12, < 7" + - source: hashicorp/google-beta + version: ">= 5.12, < 7" + - source: hashicorp/null + version: ~> 3.2 + - source: hashicorp/random + version: ~> 3.4 diff --git a/modules/mssql/outputs.tf b/modules/mssql/outputs.tf index ca491a20..18518baa 100644 --- a/modules/mssql/outputs.tf +++ b/modules/mssql/outputs.tf @@ -85,3 +85,11 @@ output "primary" { description = "The `google_sql_database_instance` resource representing the primary instance" sensitive = true } + +output "apphub_service_uri" { + value = { + service_uri = google_sql_database_instance.default.self_link + service_id = google_sql_database_instance.default.name + } + description = "Service URI in CAIS style to be used by Apphub." +} diff --git a/modules/mysql/metadata.yaml b/modules/mysql/metadata.yaml index 45a71e52..30cf72df 100644 --- a/modules/mysql/metadata.yaml +++ b/modules/mysql/metadata.yaml @@ -221,7 +221,7 @@ spec: connections: - source: source: github.com/terraform-google-modules/terraform-google-network//modules/vpc - version: "~> 9.1.0" + version: ~> 9.1.0 spec: outputExpr: network_id inputPath: private_network @@ -339,12 +339,12 @@ spec: connections: - source: source: github.com/terraform-google-modules/terraform-google-service-accounts//modules/simple-sa - version: "~> 4.3.0" + version: ~> 4.3.0 spec: outputExpr: id - source: source: github.com/GoogleCloudPlatform/terraform-google-cloud-run//modules/v2 - version: "~> 0.13.0" + version: ~> 0.13.0 spec: outputExpr: service_account_id - name: create_timeout @@ -407,6 +407,12 @@ spec: type: - tuple - [] + - name: apphub_service_uri + description: Service URI in CAIS style to be used by Apphub. + type: + - object + - service_id: string + service_uri: string - name: env_vars description: Exported environment variables type: @@ -914,3 +920,12 @@ spec: - serviceusage.googleapis.com - sqladmin.googleapis.com - workflows.googleapis.com + providerVersions: + - source: hashicorp/google + version: ">= 5.25, < 7" + - source: hashicorp/google-beta + version: ">= 5.25, < 7" + - source: hashicorp/null + version: ~> 3.1 + - source: hashicorp/random + version: ~> 3.1 diff --git a/modules/mysql/outputs.tf b/modules/mysql/outputs.tf index 85f19065..39afb6ce 100644 --- a/modules/mysql/outputs.tf +++ b/modules/mysql/outputs.tf @@ -154,3 +154,11 @@ output "env_vars" { "CLOUD_SQL_DATABASE_NAME" : local.database_name } } + +output "apphub_service_uri" { + value = { + service_uri = google_sql_database_instance.default.self_link + service_id = google_sql_database_instance.default.name + } + description = "Service URI in CAIS style to be used by Apphub." +} diff --git a/modules/postgresql/metadata.yaml b/modules/postgresql/metadata.yaml index 44db0443..cfc74ebf 100644 --- a/modules/postgresql/metadata.yaml +++ b/modules/postgresql/metadata.yaml @@ -223,7 +223,7 @@ spec: connections: - source: source: github.com/terraform-google-modules/terraform-google-network//modules/vpc - version: "~> 9.1.0" + version: ~> 9.1.0 spec: outputExpr: network_id inputPath: private_network @@ -319,12 +319,12 @@ spec: connections: - source: source: github.com/terraform-google-modules/terraform-google-service-accounts//modules/simple-sa - version: "~> 4.3.0" + version: ~> 4.3.0 spec: outputExpr: id - source: source: github.com/GoogleCloudPlatform/terraform-google-cloud-run//modules/v2 - version: "~> 0.13.0" + version: ~> 0.13.0 spec: outputExpr: service_account_id - name: create_timeout @@ -397,6 +397,12 @@ spec: type: - tuple - [] + - name: apphub_service_uri + description: Service URI in CAIS style to be used by Apphub. + type: + - object + - service_id: string + service_uri: string - name: dns_name description: DNS name of the instance endpoint type: string @@ -904,3 +910,12 @@ spec: - serviceusage.googleapis.com - sqladmin.googleapis.com - workflows.googleapis.com + providerVersions: + - source: hashicorp/google + version: ">= 5.25, < 7" + - source: hashicorp/google-beta + version: ">= 5.25, < 7" + - source: hashicorp/null + version: ~> 3.1 + - source: hashicorp/random + version: ~> 3.1 diff --git a/modules/postgresql/outputs.tf b/modules/postgresql/outputs.tf index 4874c5af..d95364a8 100644 --- a/modules/postgresql/outputs.tf +++ b/modules/postgresql/outputs.tf @@ -152,3 +152,11 @@ output "env_vars" { "CLOUD_SQL_DATABASE_NAME" : local.database_name } } + +output "apphub_service_uri" { + value = { + service_uri = google_sql_database_instance.default.self_link + service_id = google_sql_database_instance.default.name + } + description = "Service URI in CAIS style to be used by Apphub." +} From 6145abb0214a9829ae48548d83d8ede8c822b2bf Mon Sep 17 00:00:00 2001 From: Jieyu Tian Date: Thu, 17 Oct 2024 02:12:30 +0000 Subject: [PATCH 2/6] modify README.md files --- modules/mssql/README.md | 1 + modules/mssql/outputs.tf | 2 +- modules/mysql/README.md | 1 + modules/postgresql/README.md | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/mssql/README.md b/modules/mssql/README.md index 52e81c9c..c8064516 100644 --- a/modules/mssql/README.md +++ b/modules/mssql/README.md @@ -87,6 +87,7 @@ module "mssql" { | Name | Description | |------|-------------| | additional\_users | List of maps of additional users and passwords | +| apphub\_service\_uri | Service URI in CAIS style to be used by Apphub. | | generated\_user\_password | The auto generated default user password if not input password was provided | | instance\_address | The IPv4 addesses assigned for the master instance | | instance\_connection\_name | The connection name of the master instance to be used in connection strings | diff --git a/modules/mssql/outputs.tf b/modules/mssql/outputs.tf index 18518baa..c6e2b026 100644 --- a/modules/mssql/outputs.tf +++ b/modules/mssql/outputs.tf @@ -87,7 +87,7 @@ output "primary" { } output "apphub_service_uri" { - value = { + value = { service_uri = google_sql_database_instance.default.self_link service_id = google_sql_database_instance.default.name } diff --git a/modules/mysql/README.md b/modules/mysql/README.md index 9d982795..50532852 100644 --- a/modules/mysql/README.md +++ b/modules/mysql/README.md @@ -72,6 +72,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq | Name | Description | |------|-------------| | additional\_users | List of maps of additional users and passwords | +| apphub\_service\_uri | Service URI in CAIS style to be used by Apphub. | | 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/postgresql/README.md b/modules/postgresql/README.md index 6d5e0b03..5bd1eab7 100644 --- a/modules/postgresql/README.md +++ b/modules/postgresql/README.md @@ -180,6 +180,7 @@ module "pg" { | Name | Description | |------|-------------| | additional\_users | List of maps of additional users and passwords | +| apphub\_service\_uri | Service URI in CAIS style to be used by Apphub. | | 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 | From 26ee67f072627e39544c0b1b6de25cd53942220b Mon Sep 17 00:00:00 2001 From: Jieyu Tian Date: Fri, 18 Oct 2024 16:36:00 +0000 Subject: [PATCH 3/6] Change uri and id per PR comment --- modules/mssql/outputs.tf | 4 ++-- modules/mysql/outputs.tf | 4 ++-- modules/postgresql/outputs.tf | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/mssql/outputs.tf b/modules/mssql/outputs.tf index c6e2b026..479118a8 100644 --- a/modules/mssql/outputs.tf +++ b/modules/mssql/outputs.tf @@ -88,8 +88,8 @@ output "primary" { output "apphub_service_uri" { value = { - service_uri = google_sql_database_instance.default.self_link - service_id = google_sql_database_instance.default.name + service_uri = "//cloudsql.googleapis.com/projects/${var.project_id}/instances/${var.name}" + service_id = substr("${var.name}-${md5("${var.project_id}")}", 0, 63) } description = "Service URI in CAIS style to be used by Apphub." } diff --git a/modules/mysql/outputs.tf b/modules/mysql/outputs.tf index 39afb6ce..a75b49f5 100644 --- a/modules/mysql/outputs.tf +++ b/modules/mysql/outputs.tf @@ -157,8 +157,8 @@ output "env_vars" { output "apphub_service_uri" { value = { - service_uri = google_sql_database_instance.default.self_link - service_id = google_sql_database_instance.default.name + service_uri = "//cloudsql.googleapis.com/projects/${var.project_id}/instances/${var.name}" + service_id = substr("${var.name}-${md5("${var.project_id}")}", 0, 63) } description = "Service URI in CAIS style to be used by Apphub." } diff --git a/modules/postgresql/outputs.tf b/modules/postgresql/outputs.tf index d95364a8..0e74600b 100644 --- a/modules/postgresql/outputs.tf +++ b/modules/postgresql/outputs.tf @@ -155,8 +155,8 @@ output "env_vars" { output "apphub_service_uri" { value = { - service_uri = google_sql_database_instance.default.self_link - service_id = google_sql_database_instance.default.name + service_uri = "//cloudsql.googleapis.com/projects/${var.project_id}/instances/${var.name}" + service_id = substr("${var.name}-${md5("${var.project_id}")}", 0, 63) } description = "Service URI in CAIS style to be used by Apphub." } From 2de6cdd0eb328359f96be1e4a56d4a0022063445 Mon Sep 17 00:00:00 2001 From: Jieyu Tian Date: Fri, 18 Oct 2024 18:22:44 +0000 Subject: [PATCH 4/6] fix lint errors --- modules/mssql/metadata.display.yaml | 3 +++ modules/mssql/metadata.yaml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/mssql/metadata.display.yaml b/modules/mssql/metadata.display.yaml index 31afb41c..c6b6ba6e 100644 --- a/modules/mssql/metadata.display.yaml +++ b/modules/mssql/metadata.display.yaml @@ -52,6 +52,9 @@ spec: create_timeout: name: create_timeout title: Create Timeout + data_cache_enabled: + name: data_cache_enabled + title: Data Cache Enabled database_flags: name: database_flags title: Database Flags diff --git a/modules/mssql/metadata.yaml b/modules/mssql/metadata.yaml index bc64fae5..4d694f5d 100644 --- a/modules/mssql/metadata.yaml +++ b/modules/mssql/metadata.yaml @@ -308,7 +308,7 @@ spec: description: Service URI in CAIS style to be used by Apphub. type: - object - service_id: string + - service_id: string service_uri: string - name: generated_user_password description: The auto generated default user password if not input password was provided From 45ab60182a226f9e2e169e2a03b71d88d00cb348 Mon Sep 17 00:00:00 2001 From: Jieyu Tian Date: Mon, 21 Oct 2024 17:42:48 +0000 Subject: [PATCH 5/6] modify string formatting to make linter happy --- modules/mssql/outputs.tf | 2 +- modules/mysql/outputs.tf | 2 +- modules/postgresql/outputs.tf | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/mssql/outputs.tf b/modules/mssql/outputs.tf index 479118a8..f69a9524 100644 --- a/modules/mssql/outputs.tf +++ b/modules/mssql/outputs.tf @@ -89,7 +89,7 @@ output "primary" { output "apphub_service_uri" { value = { service_uri = "//cloudsql.googleapis.com/projects/${var.project_id}/instances/${var.name}" - service_id = substr("${var.name}-${md5("${var.project_id}")}", 0, 63) + service_id = substr(format("%s-%s", var.name, md5(var.project_id)), 0, 63) } description = "Service URI in CAIS style to be used by Apphub." } diff --git a/modules/mysql/outputs.tf b/modules/mysql/outputs.tf index a75b49f5..f0086545 100644 --- a/modules/mysql/outputs.tf +++ b/modules/mysql/outputs.tf @@ -158,7 +158,7 @@ output "env_vars" { output "apphub_service_uri" { value = { service_uri = "//cloudsql.googleapis.com/projects/${var.project_id}/instances/${var.name}" - service_id = substr("${var.name}-${md5("${var.project_id}")}", 0, 63) + service_id = substr(format("%s-%s", var.name, md5(var.project_id)), 0, 63) } description = "Service URI in CAIS style to be used by Apphub." } diff --git a/modules/postgresql/outputs.tf b/modules/postgresql/outputs.tf index 0e74600b..b41124ab 100644 --- a/modules/postgresql/outputs.tf +++ b/modules/postgresql/outputs.tf @@ -156,7 +156,7 @@ output "env_vars" { output "apphub_service_uri" { value = { service_uri = "//cloudsql.googleapis.com/projects/${var.project_id}/instances/${var.name}" - service_id = substr("${var.name}-${md5("${var.project_id}")}", 0, 63) + service_id = substr(format("%s-%s", var.name, md5(var.project_id)), 0, 63) } description = "Service URI in CAIS style to be used by Apphub." } From 4188ede7a78b39f8e0da6d227571c9248bd4d604 Mon Sep 17 00:00:00 2001 From: Jieyu Tian Date: Mon, 21 Oct 2024 20:27:46 +0000 Subject: [PATCH 6/6] extract apphub uri from self_link instead of interpolating. --- modules/mssql/outputs.tf | 2 +- modules/mysql/outputs.tf | 2 +- modules/postgresql/outputs.tf | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/mssql/outputs.tf b/modules/mssql/outputs.tf index f69a9524..e44e6e96 100644 --- a/modules/mssql/outputs.tf +++ b/modules/mssql/outputs.tf @@ -88,7 +88,7 @@ output "primary" { output "apphub_service_uri" { value = { - service_uri = "//cloudsql.googleapis.com/projects/${var.project_id}/instances/${var.name}" + service_uri = "//cloudsql.googleapis.com/projects${element(split("/projects", google_sql_database_instance.default.self_link), 1)}" service_id = substr(format("%s-%s", var.name, md5(var.project_id)), 0, 63) } description = "Service URI in CAIS style to be used by Apphub." diff --git a/modules/mysql/outputs.tf b/modules/mysql/outputs.tf index f0086545..3f10fa8e 100644 --- a/modules/mysql/outputs.tf +++ b/modules/mysql/outputs.tf @@ -157,7 +157,7 @@ output "env_vars" { output "apphub_service_uri" { value = { - service_uri = "//cloudsql.googleapis.com/projects/${var.project_id}/instances/${var.name}" + service_uri = "//cloudsql.googleapis.com/projects${element(split("/projects", google_sql_database_instance.default.self_link), 1)}" service_id = substr(format("%s-%s", var.name, md5(var.project_id)), 0, 63) } description = "Service URI in CAIS style to be used by Apphub." diff --git a/modules/postgresql/outputs.tf b/modules/postgresql/outputs.tf index b41124ab..020570b1 100644 --- a/modules/postgresql/outputs.tf +++ b/modules/postgresql/outputs.tf @@ -155,7 +155,7 @@ output "env_vars" { output "apphub_service_uri" { value = { - service_uri = "//cloudsql.googleapis.com/projects/${var.project_id}/instances/${var.name}" + service_uri = "//cloudsql.googleapis.com/projects${element(split("/projects", google_sql_database_instance.default.self_link), 1)}" service_id = substr(format("%s-%s", var.name, md5(var.project_id)), 0, 63) } description = "Service URI in CAIS style to be used by Apphub."