Skip to content

Commit 9040d89

Browse files
committed
Add support for psc_auto_connections feature to mysql and postgres
1 parent eb9b52f commit 9040d89

File tree

8 files changed

+45
-5
lines changed

8 files changed

+45
-5
lines changed

modules/mysql/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ module "mysql-db" {
7979
| iam\_users | 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) | <pre>list(object({<br> id = string,<br> email = string,<br> type = optional(string)<br> }))</pre> | `[]` | no |
8080
| insights\_config | The insights\_config settings for the database. | <pre>object({<br> query_plans_per_minute = number<br> query_string_length = number<br> record_application_tags = bool<br> record_client_address = bool<br> })</pre> | `null` | no |
8181
| instance\_type | Users can upgrade a read replica instance to a stand-alone Cloud SQL instance with the help of instance\_type. To promote, users have to set the instance\_type property as CLOUD\_SQL\_INSTANCE and remove/unset master\_instance\_name and replica\_configuration from instance configuration. This operation might cause your instance to restart. | `string` | `null` | no |
82-
| ip\_configuration | The ip\_configuration settings subblock | <pre>object({<br> authorized_networks = optional(list(map(string)), [])<br> ipv4_enabled = optional(bool, true)<br> private_network = optional(string)<br> ssl_mode = optional(string)<br> allocated_ip_range = optional(string)<br> enable_private_path_for_google_cloud_services = optional(bool, false)<br> psc_enabled = optional(bool, false)<br> psc_allowed_consumer_projects = optional(list(string), [])<br> })</pre> | `{}` | no |
82+
| ip\_configuration | The ip\_configuration settings subblock | <pre>object({<br> authorized_networks = optional(list(map(string)), [])<br> ipv4_enabled = optional(bool, true)<br> private_network = optional(string)<br> ssl_mode = optional(string)<br> allocated_ip_range = optional(string)<br> enable_private_path_for_google_cloud_services = optional(bool, false)<br> psc_enabled = optional(bool, false)<br> psc_allowed_consumer_projects = optional(list(string), [])<br> psc_auto_connections = optional(list(object({<br> consumer_network = string<br> consumer_service_project_id = string<br> })), [])<br> })</pre> | `{}` | no |
8383
| maintenance\_version | The current software version on the instance. This attribute can not be set during creation. Refer to available\_maintenance\_versions attribute to see what maintenance\_version are available for upgrade. When this attribute gets updated, it will cause an instance restart. Setting a maintenance\_version value that is older than the current one on the instance will be ignored | `string` | `null` | no |
8484
| maintenance\_window\_day | The day of week (1-7) for the master instance maintenance. | `number` | `1` | no |
8585
| maintenance\_window\_hour | The hour of day (0-23) maintenance window for the master instance maintenance. | `number` | `23` | no |

modules/mysql/main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ resource "google_sql_database_instance" "default" {
160160
content {
161161
psc_enabled = ip_configuration.value.psc_enabled
162162
allowed_consumer_projects = ip_configuration.value.psc_allowed_consumer_projects
163+
164+
dynamic "psc_auto_connections" {
165+
for_each = lookup(ip_configuration.value, "psc_auto_connections", [])
166+
content {
167+
consumer_network = psc_auto_connections.value.consumer_network
168+
consumer_service_project_id = psc_auto_connections.value.consumer_service_project_id
169+
}
170+
}
163171
}
164172
}
165173

modules/mysql/read_replica.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ resource "google_sql_database_instance" "replicas" {
9292
content {
9393
psc_enabled = ip_configuration.value.psc_enabled
9494
allowed_consumer_projects = ip_configuration.value.psc_allowed_consumer_projects
95+
96+
dynamic "psc_auto_connections" {
97+
for_each = lookup(ip_configuration.value, "psc_auto_connections", [])
98+
content {
99+
consumer_network = psc_auto_connections.value.consumer_network
100+
consumer_service_project_id = psc_auto_connections.value.consumer_service_project_id
101+
}
102+
}
95103
}
96104
}
97105
}

modules/mysql/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ variable "ip_configuration" {
342342
enable_private_path_for_google_cloud_services = optional(bool, false)
343343
psc_enabled = optional(bool, false)
344344
psc_allowed_consumer_projects = optional(list(string), [])
345+
psc_auto_connections = optional(list(object({
346+
consumer_network = string
347+
consumer_service_project_id = string
348+
})), [])
345349
})
346350
default = {}
347351
}

modules/postgresql/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ module "pg" {
151151
| iam\_users | 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) | <pre>list(object({<br> id = string,<br> email = string,<br> type = optional(string)<br> }))</pre> | `[]` | no |
152152
| insights\_config | The insights\_config settings for the database. | <pre>object({<br> query_plans_per_minute = optional(number, 5)<br> query_string_length = optional(number, 1024)<br> record_application_tags = optional(bool, false)<br> record_client_address = optional(bool, false)<br> })</pre> | `null` | no |
153153
| instance\_type | The type of the instance. The supported values are SQL\_INSTANCE\_TYPE\_UNSPECIFIED, CLOUD\_SQL\_INSTANCE, ON\_PREMISES\_INSTANCE and READ\_REPLICA\_INSTANCE. Set to READ\_REPLICA\_INSTANCE if master\_instance\_name value is provided | `string` | `"CLOUD_SQL_INSTANCE"` | no |
154-
| ip\_configuration | The ip configuration for the Cloud SQL instances. | <pre>object({<br> authorized_networks = optional(list(map(string)), [])<br> ipv4_enabled = optional(bool, true)<br> private_network = optional(string)<br> ssl_mode = optional(string)<br> allocated_ip_range = optional(string)<br> enable_private_path_for_google_cloud_services = optional(bool, false)<br> psc_enabled = optional(bool, false)<br> psc_allowed_consumer_projects = optional(list(string), [])<br> server_ca_mode = optional(string)<br> server_ca_pool = optional(string)<br> custom_subject_alternative_names = optional(list(string), [])<br> })</pre> | `{}` | no |
154+
| ip\_configuration | The ip configuration for the Cloud SQL instances. | <pre>object({<br> authorized_networks = optional(list(map(string)), [])<br> ipv4_enabled = optional(bool, true)<br> private_network = optional(string)<br> ssl_mode = optional(string)<br> allocated_ip_range = optional(string)<br> enable_private_path_for_google_cloud_services = optional(bool, false)<br> psc_enabled = optional(bool, false)<br> psc_allowed_consumer_projects = optional(list(string), [])<br> psc_auto_connections = optional(list(object({<br> consumer_network = string<br> consumer_service_project_id = string<br> })), [])<br> server_ca_mode = optional(string)<br> server_ca_pool = optional(string)<br> custom_subject_alternative_names = optional(list(string), [])<br> })</pre> | `{}` | no |
155155
| maintenance\_version | The current software version on the instance. This attribute can not be set during creation. Refer to available\_maintenance\_versions attribute to see what maintenance\_version are available for upgrade. When this attribute gets updated, it will cause an instance restart. Setting a maintenance\_version value that is older than the current one on the instance will be ignored | `string` | `null` | no |
156156
| maintenance\_window\_day | The day of week (1-7) for the Cloud SQL instance maintenance. | `number` | `1` | no |
157157
| maintenance\_window\_hour | The hour of day (0-23) maintenance window for the Cloud SQL instance maintenance. | `number` | `23` | no |

modules/postgresql/main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ resource "google_sql_database_instance" "default" {
145145
content {
146146
psc_enabled = ip_configuration.value.psc_enabled
147147
allowed_consumer_projects = ip_configuration.value.psc_allowed_consumer_projects
148+
149+
dynamic "psc_auto_connections" {
150+
for_each = lookup(ip_configuration.value, "psc_auto_connections", [])
151+
content {
152+
consumer_network = psc_auto_connections.value.consumer_network
153+
consumer_service_project_id = psc_auto_connections.value.consumer_service_project_id
154+
}
155+
}
148156
}
149157
}
150158

modules/postgresql/read_replica.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ resource "google_sql_database_instance" "replicas" {
6767
content {
6868
psc_enabled = ip_configuration.value.psc_enabled
6969
allowed_consumer_projects = ip_configuration.value.psc_enabled ? ip_configuration.value.psc_allowed_consumer_projects : []
70+
71+
dynamic "psc_auto_connections" {
72+
for_each = lookup(ip_configuration.value, "psc_auto_connections", [])
73+
content {
74+
consumer_network = psc_auto_connections.value.consumer_network
75+
consumer_service_project_id = psc_auto_connections.value.consumer_service_project_id
76+
}
77+
}
7078
}
7179
}
7280
}

modules/postgresql/variables.tf

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,13 @@ variable "ip_configuration" {
330330
enable_private_path_for_google_cloud_services = optional(bool, false)
331331
psc_enabled = optional(bool, false)
332332
psc_allowed_consumer_projects = optional(list(string), [])
333-
server_ca_mode = optional(string)
334-
server_ca_pool = optional(string)
335-
custom_subject_alternative_names = optional(list(string), [])
333+
psc_auto_connections = optional(list(object({
334+
consumer_network = string
335+
consumer_service_project_id = string
336+
})), [])
337+
server_ca_mode = optional(string)
338+
server_ca_pool = optional(string)
339+
custom_subject_alternative_names = optional(list(string), [])
336340
})
337341
default = {}
338342
}

0 commit comments

Comments
 (0)