diff --git a/modules/cloudsql-instance/README.md b/modules/cloudsql-instance/README.md index 660a9972f..15660ed98 100644 --- a/modules/cloudsql-instance/README.md +++ b/modules/cloudsql-instance/README.md @@ -2,7 +2,7 @@ This module manages the creation of Cloud SQL instances with potential read replicas in other regions. It can also create an initial set of users and databases via the `users` and `databases` parameters. -Note that this module assumes that some options are the same for both the primary instance and all the replicas (e.g. tier, disks, labels, flags, etc). +Note that this module assumes that some options are the same for both the primary instance and all the replicas (e.g. disks, labels, flags, etc). The `tier` can be overridden per-replica via `replicas..tier`; if unset, replicas inherit the primary's tier. *Warning:* if you use the `users` field, you terraform state will contain each user's password in plain text. @@ -109,7 +109,7 @@ module "db" { replicas = { replica1 = { region = "europe-west3" } - replica2 = { region = "us-central1" } + replica2 = { region = "us-central1", tier = "db-custom-2-7680" } } gcp_deletion_protection = false terraform_deletion_protection = false @@ -455,7 +455,7 @@ module "db" { | [network_config](variables.tf#L218) | Network configuration for the instance. Only one between private_network and psc_config can be used. | object({…}) | ✓ | | | [project_id](variables.tf#L278) | The ID of the project where this instances will be created. | string | ✓ | | | [region](variables.tf#L283) | Region of the primary instance. | string | ✓ | | -| [tier](variables.tf#L335) | The machine type to use for the instances. | string | ✓ | | +| [tier](variables.tf#L336) | The machine type to use for the instances. | string | ✓ | | | [activation_policy](variables.tf#L17) | This variable specifies when the instance should be active. Can be either ALWAYS, NEVER or ON_DEMAND. Default is ALWAYS. | string | | "ALWAYS" | | [availability_type](variables.tf#L28) | Availability type for the primary replica. Either `ZONAL` or `REGIONAL`. | string | | "ZONAL" | | [backup_configuration](variables.tf#L34) | Backup settings for primary instance. Set to null to leave existing GCP backup settings unmanaged. When set, all fields are managed by Terraform including disabling backups when enabled=false. | object({…}) | | null | @@ -478,12 +478,12 @@ module "db" { | [managed_connection_pooling_config](variables.tf#L203) | Configuration for Managed Connection Pooling. NOTE: This feature is only available for PostgreSQL on Enterprise Plus edition instances. | object({…}) | | {} | | [password_validation_policy](variables.tf#L254) | Password validation policy configuration for instances. | object({…}) | | null | | [prefix](variables.tf#L268) | Optional prefix used to generate instance names. | string | | null | -| [replicas](variables.tf#L288) | Map of NAME=> {REGION, KMS_KEY, AVAILABILITY_TYPE} for additional read replicas. Set to null to disable replica creation. | map(object({…})) | | {} | -| [root_password](variables.tf#L299) | Root password of the Cloud SQL instance, or flag to create a random password. Required for MS SQL Server. | object({…}) | | {} | -| [ssl](variables.tf#L313) | Setting to enable SSL, set config and certificates. | object({…}) | | {} | -| [terraform_deletion_protection](variables.tf#L328) | Prevent terraform from deleting instances. | bool | | true | -| [time_zone](variables.tf#L340) | The time_zone to be used by the database engine (supported only for SQL Server), in SQL Server timezone format. | string | | null | -| [users](variables.tf#L346) | Map of users to create in the primary instance (and replicated to other replicas). For MySQL, anything after the first `@` (if present) will be used as the user's host. Set PASSWORD to null if you want to get an autogenerated password. The user types available are: 'BUILT_IN', 'CLOUD_IAM_USER' or 'CLOUD_IAM_SERVICE_ACCOUNT'. | map(object({…})) | | {} | +| [replicas](variables.tf#L288) | Map of NAME=> {REGION, KMS_KEY, AVAILABILITY_TYPE, TIER} for additional read replicas. Set TIER to override the primary's machine type per replica. Set to null to disable replica creation. | map(object({…})) | | {} | +| [root_password](variables.tf#L300) | Root password of the Cloud SQL instance, or flag to create a random password. Required for MS SQL Server. | object({…}) | | {} | +| [ssl](variables.tf#L314) | Setting to enable SSL, set config and certificates. | object({…}) | | {} | +| [terraform_deletion_protection](variables.tf#L329) | Prevent terraform from deleting instances. | bool | | true | +| [time_zone](variables.tf#L341) | The time_zone to be used by the database engine (supported only for SQL Server), in SQL Server timezone format. | string | | null | +| [users](variables.tf#L347) | Map of users to create in the primary instance (and replicated to other replicas). For MySQL, anything after the first `@` (if present) will be used as the user's host. Set PASSWORD to null if you want to get an autogenerated password. The user types available are: 'BUILT_IN', 'CLOUD_IAM_USER' or 'CLOUD_IAM_SERVICE_ACCOUNT'. | map(object({…})) | | {} | ## Outputs diff --git a/modules/cloudsql-instance/main.tf b/modules/cloudsql-instance/main.tf index 5df33cd29..0914f2b5e 100644 --- a/modules/cloudsql-instance/main.tf +++ b/modules/cloudsql-instance/main.tf @@ -302,7 +302,7 @@ resource "google_sql_database_instance" "replicas" { master_instance_name = google_sql_database_instance.primary.name settings { - tier = var.tier + tier = coalesce(each.value.tier, var.tier) edition = var.edition deletion_protection_enabled = var.gcp_deletion_protection disk_autoresize = var.disk_size == null diff --git a/modules/cloudsql-instance/variables.tf b/modules/cloudsql-instance/variables.tf index cb5008599..c106e94a9 100644 --- a/modules/cloudsql-instance/variables.tf +++ b/modules/cloudsql-instance/variables.tf @@ -286,11 +286,12 @@ variable "region" { } variable "replicas" { - description = "Map of NAME=> {REGION, KMS_KEY, AVAILABILITY_TYPE} for additional read replicas. Set to null to disable replica creation." + description = "Map of NAME=> {REGION, KMS_KEY, AVAILABILITY_TYPE, TIER} for additional read replicas. Set TIER to override the primary's machine type per replica. Set to null to disable replica creation." type = map(object({ region = string encryption_key_name = optional(string) availability_type = optional(string) + tier = optional(string) })) default = {} nullable = false diff --git a/tests/modules/cloudsql_instance/examples/replicas.yaml b/tests/modules/cloudsql_instance/examples/replicas.yaml index a27e1fd27..3d2dcedac 100644 --- a/tests/modules/cloudsql_instance/examples/replicas.yaml +++ b/tests/modules/cloudsql_instance/examples/replicas.yaml @@ -21,6 +21,7 @@ values: region: europe-west8 settings: - edition: ENTERPRISE + tier: db-g1-small module.db.google_sql_database_instance.replicas["replica1"]: clone: [] @@ -31,6 +32,7 @@ values: region: europe-west3 settings: - edition: ENTERPRISE + tier: db-g1-small module.db.google_sql_database_instance.replicas["replica2"]: clone: [] @@ -41,6 +43,7 @@ values: region: us-central1 settings: - edition: ENTERPRISE + tier: db-custom-2-7680 counts: google_sql_database_instance: 3