Skip to content

Commit 83bbaa3

Browse files
authored
feat!: Add enable_google_ml_integration setting for database instance and configurable project roles for default database service account (#615)
1 parent 2d5b115 commit 83bbaa3

File tree

5 files changed

+40
-10
lines changed

5 files changed

+40
-10
lines changed

modules/postgresql/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ module "pg" {
126126
| data\_cache\_enabled | Whether data cache is enabled for the instance. Defaults to false. Feature is only available for ENTERPRISE\_PLUS tier and supported database\_versions | `bool` | `false` | no |
127127
| database\_deletion\_policy | The deletion policy for the database. Setting ABANDON allows the resource to be abandoned rather than deleted. This is useful for Postgres, where databases cannot be deleted from the API if there are users other than cloudsqlsuperuser with access. Possible values are: "ABANDON". | `string` | `null` | no |
128128
| database\_flags | The database flags for the Cloud SQL instance. See [more details](https://cloud.google.com/sql/docs/postgres/flags) | <pre>list(object({<br> name = string<br> value = string<br> }))</pre> | `[]` | no |
129+
| database\_integration\_roles | The roles required by default database instance service account for integration with GCP services | `list(string)` | `[]` | no |
129130
| database\_version | The database version to use | `string` | n/a | yes |
130131
| db\_charset | The charset for the default database | `string` | `""` | no |
131132
| db\_collation | The collation for the default database. Example: 'en\_US.UTF8' | `string` | `""` | no |
@@ -141,6 +142,7 @@ module "pg" {
141142
| edition | The edition of the Cloud SQL instance, can be ENTERPRISE or ENTERPRISE\_PLUS. | `string` | `null` | no |
142143
| enable\_default\_db | Enable or disable the creation of the default database | `bool` | `true` | no |
143144
| enable\_default\_user | Enable or disable the creation of the default user | `bool` | `true` | no |
145+
| enable\_google\_ml\_integration | Enable database ML integration | `bool` | `false` | no |
144146
| enable\_random\_password\_special | Enable special characters in generated random passwords. | `bool` | `false` | no |
145147
| encryption\_key\_name | The full path to the encryption key used for the CMEK disk encryption | `string` | `null` | no |
146148
| follow\_gae\_application | A Google App Engine application whose zone to remain in. Must be in the same region as this instance. | `string` | `null` | no |
@@ -209,5 +211,5 @@ module "pg" {
209211
### Installation Dependencies
210212

211213
- [Terraform](https://www.terraform.io/downloads.html) >= 1.3.0
212-
- [terraform-provider-google](https://github.com/terraform-providers/terraform-provider-google) plugin v5.12+
213-
- [Terraform Provider Beta for GCP](https://github.com/terraform-providers/terraform-provider-google-beta) plugin v5.12+
214+
- [terraform-provider-google](https://github.com/terraform-providers/terraform-provider-google) plugin v5.25+
215+
- [Terraform Provider Beta for GCP](https://github.com/terraform-providers/terraform-provider-google-beta) plugin v5.25+

modules/postgresql/main.tf

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,13 @@ resource "google_sql_database_instance" "default" {
6767
instance_type = local.is_secondary_instance ? "READ_REPLICA_INSTANCE" : var.instance_type
6868

6969
settings {
70-
tier = var.tier
71-
edition = var.edition
72-
activation_policy = var.activation_policy
73-
availability_type = var.availability_type
74-
deletion_protection_enabled = var.deletion_protection_enabled
75-
connector_enforcement = local.connector_enforcement
70+
tier = var.tier
71+
edition = var.edition
72+
activation_policy = var.activation_policy
73+
availability_type = var.availability_type
74+
deletion_protection_enabled = var.deletion_protection_enabled
75+
connector_enforcement = local.connector_enforcement
76+
enable_google_ml_integration = var.enable_google_ml_integration
7677

7778
dynamic "backup_configuration" {
7879
for_each = local.is_secondary_instance ? [] : [var.backup_configuration]
@@ -319,6 +320,13 @@ resource "google_sql_user" "iam_account" {
319320
deletion_policy = var.user_deletion_policy
320321
}
321322

323+
resource "google_project_iam_member" "database_integration" {
324+
for_each = toset(var.database_integration_roles)
325+
project = var.project_id
326+
role = each.value
327+
member = "serviceAccount:${google_sql_database_instance.default.service_account_email_address}"
328+
}
329+
322330
resource "null_resource" "module_depends_on" {
323331
triggers = {
324332
value = length(var.module_depends_on)

modules/postgresql/metadata.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ spec:
122122
value = string
123123
}))
124124
defaultValue: []
125+
- name: database_integration_roles
126+
description: The roles required by default database instance service account for integration with GCP services
127+
varType: list(string)
128+
defaultValue: []
125129
- name: database_version
126130
description: The database version to use
127131
varType: string
@@ -186,6 +190,10 @@ spec:
186190
description: Enable or disable the creation of the default user
187191
varType: bool
188192
defaultValue: true
193+
- name: enable_google_ml_integration
194+
description: Enable database ML integration
195+
varType: bool
196+
defaultValue: false
189197
- name: enable_random_password_special
190198
description: Enable special characters in generated random passwords.
191199
varType: bool

modules/postgresql/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,3 +439,15 @@ variable "data_cache_enabled" {
439439
type = bool
440440
default = false
441441
}
442+
443+
variable "enable_google_ml_integration" {
444+
description = "Enable database ML integration"
445+
type = bool
446+
default = false
447+
}
448+
449+
variable "database_integration_roles" {
450+
description = "The roles required by default database instance service account for integration with GCP services"
451+
type = list(string)
452+
default = []
453+
}

modules/postgresql/versions.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ terraform {
2727
}
2828
google = {
2929
source = "hashicorp/google"
30-
version = ">= 5.12, < 6"
30+
version = ">= 5.25, < 6"
3131
}
3232
google-beta = {
3333
source = "hashicorp/google-beta"
34-
version = ">= 5.12, < 6"
34+
version = ">= 5.25, < 6"
3535
}
3636
}
3737

0 commit comments

Comments
 (0)