|
| 1 | +/** |
| 2 | + * Copyright 2025 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +# [START cloud_sql_mysql_instance_managed_connection_pooling_creation] |
| 18 | +# This example shows creating an instance with Managed Connection Pooling. |
| 19 | +resource "google_sql_database_instance" "mysql_managed_connection_pooling_creation" { |
| 20 | + name = "mysql-instance-managed-connection-pooling-creation" |
| 21 | + region = "us-central1" |
| 22 | + database_version = "MYSQL_8_0" |
| 23 | + deletion_protection = false |
| 24 | + |
| 25 | + settings { |
| 26 | + tier = "db-perf-optimized-N-2" |
| 27 | + edition = "ENTERPRISE_PLUS" |
| 28 | + connection_pool_config { |
| 29 | + connection_pooling_enabled = true |
| 30 | + } |
| 31 | + } |
| 32 | +} |
| 33 | +# [END cloud_sql_mysql_instance_managed_connection_pooling_creation] |
| 34 | + |
| 35 | +# [START cloud_sql_mysql_instance_managed_connection_pooling_enable] |
| 36 | +# This example shows creating an instance with Managed Connection Pooling enabled and custom flags set. |
| 37 | +resource "google_sql_database_instance" "mysql_managed_connection_pooling_enable" { |
| 38 | + name = "mysql-instance-managed-connection-pooling-enable" |
| 39 | + region = "us-central1" |
| 40 | + database_version = "MYSQL_8_0" |
| 41 | + deletion_protection = false |
| 42 | + |
| 43 | + settings { |
| 44 | + tier = "db-perf-optimized-N-2" |
| 45 | + edition = "ENTERPRISE_PLUS" |
| 46 | + connection_pool_config { |
| 47 | + connection_pooling_enabled = true |
| 48 | + } |
| 49 | + } |
| 50 | +} |
| 51 | +# [END cloud_sql_mysql_instance_managed_connection_pooling_enable] |
| 52 | + |
| 53 | +# [START cloud_sql_mysql_instance_managed_connection_pooling_modify] |
| 54 | +# This example shows modifying the flags of an existing Managed Connection Pooling configuration. |
| 55 | +resource "google_sql_database_instance" "mysql_managed_connection_pooling_modify" { |
| 56 | + name = "mysql-instance-managed-connection-pooling-modify" |
| 57 | + region = "us-central1" |
| 58 | + database_version = "MYSQL_8_0" |
| 59 | + deletion_protection = false |
| 60 | + |
| 61 | + settings { |
| 62 | + tier = "db-perf-optimized-N-2" |
| 63 | + edition = "ENTERPRISE_PLUS" |
| 64 | + connection_pool_config { |
| 65 | + connection_pooling_enabled = true |
| 66 | + flags { |
| 67 | + name = "max_pool_size" # Modify or add the name and value of an flag |
| 68 | + value = "10" |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | +} |
| 73 | +# [END cloud_sql_mysql_instance_managed_connection_pooling_modify] |
| 74 | + |
| 75 | +# [START cloud_sql_mysql_instance_managed_connection_pooling_disable] |
| 76 | +# This example shows disabling Managed Connection Pooling on an existing instance. |
| 77 | +resource "google_sql_database_instance" "mysql_managed_connection_pooling_disable" { |
| 78 | + name = "mysql-instance-managed-connection-pooling-disable" |
| 79 | + region = "us-central1" |
| 80 | + database_version = "MYSQL_8_0" |
| 81 | + deletion_protection = false |
| 82 | + |
| 83 | + settings { |
| 84 | + tier = "db-perf-optimized-N-2" |
| 85 | + edition = "ENTERPRISE_PLUS" |
| 86 | + connection_pool_config { |
| 87 | + # Set to false to disable Managed Connection Pooling. You can also remove the block entirely. |
| 88 | + connection_pooling_enabled = false |
| 89 | + } |
| 90 | + } |
| 91 | +} |
| 92 | +# [END cloud_sql_mysql_instance_managed_connection_pooling_disable] |
0 commit comments