Support per-replica tier override in modules/cloudsql-instance (#4014)
* Support per-replica tier override in modules/cloudsql-instance Replicas previously ignored any caller-provided tier and silently inherited the primary's tier. Add an optional `tier` field to the `replicas` map and use `coalesce(each.value.tier, var.tier)` in the replica resource so per-replica overrides take effect while preserving the inherit-from-primary default. * Update README --------- Co-authored-by: Julio Castillo <jccb@google.com>
This commit is contained in:
committed by
GitHub
parent
81e1a0c273
commit
e753344bd2
@@ -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.
|
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.<name>.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.
|
*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 = {
|
replicas = {
|
||||||
replica1 = { region = "europe-west3" }
|
replica1 = { region = "europe-west3" }
|
||||||
replica2 = { region = "us-central1" }
|
replica2 = { region = "us-central1", tier = "db-custom-2-7680" }
|
||||||
}
|
}
|
||||||
gcp_deletion_protection = false
|
gcp_deletion_protection = false
|
||||||
terraform_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. | <code>object({…})</code> | ✓ | |
|
| [network_config](variables.tf#L218) | Network configuration for the instance. Only one between private_network and psc_config can be used. | <code>object({…})</code> | ✓ | |
|
||||||
| [project_id](variables.tf#L278) | The ID of the project where this instances will be created. | <code>string</code> | ✓ | |
|
| [project_id](variables.tf#L278) | The ID of the project where this instances will be created. | <code>string</code> | ✓ | |
|
||||||
| [region](variables.tf#L283) | Region of the primary instance. | <code>string</code> | ✓ | |
|
| [region](variables.tf#L283) | Region of the primary instance. | <code>string</code> | ✓ | |
|
||||||
| [tier](variables.tf#L335) | The machine type to use for the instances. | <code>string</code> | ✓ | |
|
| [tier](variables.tf#L336) | The machine type to use for the instances. | <code>string</code> | ✓ | |
|
||||||
| [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. | <code>string</code> | | <code>"ALWAYS"</code> |
|
| [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. | <code>string</code> | | <code>"ALWAYS"</code> |
|
||||||
| [availability_type](variables.tf#L28) | Availability type for the primary replica. Either `ZONAL` or `REGIONAL`. | <code>string</code> | | <code>"ZONAL"</code> |
|
| [availability_type](variables.tf#L28) | Availability type for the primary replica. Either `ZONAL` or `REGIONAL`. | <code>string</code> | | <code>"ZONAL"</code> |
|
||||||
| [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. | <code>object({…})</code> | | <code>null</code> |
|
| [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. | <code>object({…})</code> | | <code>null</code> |
|
||||||
@@ -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. | <code>object({…})</code> | | <code>{}</code> |
|
| [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. | <code>object({…})</code> | | <code>{}</code> |
|
||||||
| [password_validation_policy](variables.tf#L254) | Password validation policy configuration for instances. | <code>object({…})</code> | | <code>null</code> |
|
| [password_validation_policy](variables.tf#L254) | Password validation policy configuration for instances. | <code>object({…})</code> | | <code>null</code> |
|
||||||
| [prefix](variables.tf#L268) | Optional prefix used to generate instance names. | <code>string</code> | | <code>null</code> |
|
| [prefix](variables.tf#L268) | Optional prefix used to generate instance names. | <code>string</code> | | <code>null</code> |
|
||||||
| [replicas](variables.tf#L288) | Map of NAME=> {REGION, KMS_KEY, AVAILABILITY_TYPE} for additional read replicas. Set to null to disable replica creation. | <code>map(object({…}))</code> | | <code>{}</code> |
|
| [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. | <code>map(object({…}))</code> | | <code>{}</code> |
|
||||||
| [root_password](variables.tf#L299) | Root password of the Cloud SQL instance, or flag to create a random password. Required for MS SQL Server. | <code>object({…})</code> | | <code>{}</code> |
|
| [root_password](variables.tf#L300) | Root password of the Cloud SQL instance, or flag to create a random password. Required for MS SQL Server. | <code>object({…})</code> | | <code>{}</code> |
|
||||||
| [ssl](variables.tf#L313) | Setting to enable SSL, set config and certificates. | <code>object({…})</code> | | <code>{}</code> |
|
| [ssl](variables.tf#L314) | Setting to enable SSL, set config and certificates. | <code>object({…})</code> | | <code>{}</code> |
|
||||||
| [terraform_deletion_protection](variables.tf#L328) | Prevent terraform from deleting instances. | <code>bool</code> | | <code>true</code> |
|
| [terraform_deletion_protection](variables.tf#L329) | Prevent terraform from deleting instances. | <code>bool</code> | | <code>true</code> |
|
||||||
| [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. | <code>string</code> | | <code>null</code> |
|
| [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. | <code>string</code> | | <code>null</code> |
|
||||||
| [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'. | <code>map(object({…}))</code> | | <code>{}</code> |
|
| [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'. | <code>map(object({…}))</code> | | <code>{}</code> |
|
||||||
|
|
||||||
## Outputs
|
## Outputs
|
||||||
|
|
||||||
|
|||||||
@@ -302,7 +302,7 @@ resource "google_sql_database_instance" "replicas" {
|
|||||||
master_instance_name = google_sql_database_instance.primary.name
|
master_instance_name = google_sql_database_instance.primary.name
|
||||||
|
|
||||||
settings {
|
settings {
|
||||||
tier = var.tier
|
tier = coalesce(each.value.tier, var.tier)
|
||||||
edition = var.edition
|
edition = var.edition
|
||||||
deletion_protection_enabled = var.gcp_deletion_protection
|
deletion_protection_enabled = var.gcp_deletion_protection
|
||||||
disk_autoresize = var.disk_size == null
|
disk_autoresize = var.disk_size == null
|
||||||
|
|||||||
@@ -286,11 +286,12 @@ variable "region" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
variable "replicas" {
|
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({
|
type = map(object({
|
||||||
region = string
|
region = string
|
||||||
encryption_key_name = optional(string)
|
encryption_key_name = optional(string)
|
||||||
availability_type = optional(string)
|
availability_type = optional(string)
|
||||||
|
tier = optional(string)
|
||||||
}))
|
}))
|
||||||
default = {}
|
default = {}
|
||||||
nullable = false
|
nullable = false
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ values:
|
|||||||
region: europe-west8
|
region: europe-west8
|
||||||
settings:
|
settings:
|
||||||
- edition: ENTERPRISE
|
- edition: ENTERPRISE
|
||||||
|
tier: db-g1-small
|
||||||
|
|
||||||
module.db.google_sql_database_instance.replicas["replica1"]:
|
module.db.google_sql_database_instance.replicas["replica1"]:
|
||||||
clone: []
|
clone: []
|
||||||
@@ -31,6 +32,7 @@ values:
|
|||||||
region: europe-west3
|
region: europe-west3
|
||||||
settings:
|
settings:
|
||||||
- edition: ENTERPRISE
|
- edition: ENTERPRISE
|
||||||
|
tier: db-g1-small
|
||||||
|
|
||||||
module.db.google_sql_database_instance.replicas["replica2"]:
|
module.db.google_sql_database_instance.replicas["replica2"]:
|
||||||
clone: []
|
clone: []
|
||||||
@@ -41,6 +43,7 @@ values:
|
|||||||
region: us-central1
|
region: us-central1
|
||||||
settings:
|
settings:
|
||||||
- edition: ENTERPRISE
|
- edition: ENTERPRISE
|
||||||
|
tier: db-custom-2-7680
|
||||||
|
|
||||||
counts:
|
counts:
|
||||||
google_sql_database_instance: 3
|
google_sql_database_instance: 3
|
||||||
|
|||||||
Reference in New Issue
Block a user