|
| 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_postgres_read_pool_auto_scale] |
| 18 | + |
| 19 | +resource "google_sql_database_instance" "primary" { |
| 20 | + name = "postgres-primary" |
| 21 | + database_version = "POSTGRES_17" |
| 22 | + region = "europe-west4" |
| 23 | + |
| 24 | + instance_type = "CLOUD_SQL_INSTANCE" |
| 25 | + |
| 26 | + settings { |
| 27 | + tier = "db-perf-optimized-N-2" |
| 28 | + edition = "ENTERPRISE_PLUS" |
| 29 | + |
| 30 | + backup_configuration { |
| 31 | + enabled = true |
| 32 | + } |
| 33 | + |
| 34 | + ip_configuration { |
| 35 | + ipv4_enabled = true |
| 36 | + } |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +resource "google_sql_database_instance" "replica" { |
| 41 | + name = "postgres-replica" |
| 42 | + database_version = "POSTGRES_17" |
| 43 | + region = "europe-west4" |
| 44 | + |
| 45 | + master_instance_name = google_sql_database_instance.primary.name |
| 46 | + instance_type = "READ_POOL_INSTANCE" |
| 47 | + node_count = 2 |
| 48 | + |
| 49 | + settings { |
| 50 | + tier = "db-perf-optimized-N-2" |
| 51 | + edition = "ENTERPRISE_PLUS" |
| 52 | + |
| 53 | + ip_configuration { |
| 54 | + ipv4_enabled = true |
| 55 | + } |
| 56 | + read_pool_auto_scale_config { |
| 57 | + enabled = true |
| 58 | + disable_scale_in = false |
| 59 | + max_node_count = 20 |
| 60 | + min_node_count = 2 |
| 61 | + scale_in_cooldown_seconds = 600 |
| 62 | + scale_out_cooldown_seconds = 600 |
| 63 | + target_metrics { |
| 64 | + metric = "AVERAGE_CPU_UTILIZATION" |
| 65 | + target_value = 0.5 |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +# [END cloud_sql_postgres_read_pool_auto_scale] |
0 commit comments