Skip to content

Commit

Permalink
feat: Add allocated_ip_range property to CloudSQL modules (#277)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Minimum provider version increased to 4.4.
BREAKING CHANGE: `allocated_ip_range` must now be specified for instances; `allocated_ip_range = null` can be used to preserve old default.
  • Loading branch information
srs2210 committed Feb 11, 2022
1 parent 3d0e73d commit ab8c768
Show file tree
Hide file tree
Showing 24 changed files with 73 additions and 42 deletions.
14 changes: 8 additions & 6 deletions examples/mysql-ha/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

locals {
read_replica_ip_configuration = {
ipv4_enabled = true
require_ssl = false
private_network = null
ipv4_enabled = true
require_ssl = false
private_network = null
allocated_ip_range = null
authorized_networks = [
{
name = "${var.project_id}-cidr"
Expand Down Expand Up @@ -55,9 +56,10 @@ module "mysql" {
}

ip_configuration = {
ipv4_enabled = true
require_ssl = true
private_network = null
ipv4_enabled = true
require_ssl = true
private_network = null
allocated_ip_range = null
authorized_networks = [
{
name = "${var.project_id}-cidr"
Expand Down
7 changes: 4 additions & 3 deletions examples/mysql-private/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ locals {

module "network-safer-mysql-simple" {
source = "terraform-google-modules/network/google"
version = "~> 2.5"
version = "~> 4.0"

project_id = var.project_id
network_name = local.network_name
Expand Down Expand Up @@ -73,8 +73,9 @@ module "safer-mysql-db" {
},
]

assign_public_ip = "true"
vpc_network = module.network-safer-mysql-simple.network_self_link
assign_public_ip = "true"
vpc_network = module.network-safer-mysql-simple.network_self_link
allocated_ip_range = module.private-service-access.google_compute_global_address_name

// Optional: used to enforce ordering in the creation of resources.
module_depends_on = [module.private-service-access.peering_completed]
Expand Down
1 change: 1 addition & 0 deletions examples/mysql-public/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module "mysql-db" {
ipv4_enabled = true
private_network = null
require_ssl = true
allocated_ip_range = null
authorized_networks = var.authorized_networks
}

Expand Down
14 changes: 8 additions & 6 deletions examples/postgresql-ha/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

locals {
read_replica_ip_configuration = {
ipv4_enabled = true
require_ssl = false
private_network = null
ipv4_enabled = true
require_ssl = false
private_network = null
allocated_ip_range = null
authorized_networks = [
{
name = "${var.project_id}-cidr"
Expand Down Expand Up @@ -54,9 +55,10 @@ module "pg" {
}

ip_configuration = {
ipv4_enabled = true
require_ssl = true
private_network = null
ipv4_enabled = true
require_ssl = true
private_network = null
allocated_ip_range = null
authorized_networks = [
{
name = "${var.project_id}-cidr"
Expand Down
1 change: 1 addition & 0 deletions examples/postgresql-public-iam/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module "postgresql-db" {
ipv4_enabled = true
private_network = null
require_ssl = true
allocated_ip_range = null
authorized_networks = var.authorized_networks
}

Expand Down
1 change: 1 addition & 0 deletions examples/postgresql-public/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module "postgresql-db" {
ipv4_enabled = true
private_network = null
require_ssl = true
allocated_ip_range = null
authorized_networks = var.authorized_networks
}
}
2 changes: 1 addition & 1 deletion modules/mssql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The following dependency must be available for SQL Server module:
| disk\_size | The disk size for the master instance. | `number` | `10` | no |
| disk\_type | The disk type for the master instance. | `string` | `"PD_SSD"` | no |
| encryption\_key\_name | The full path to the encryption key used for the CMEK disk encryption | `string` | `null` | no |
| ip\_configuration | The ip configuration for the master instances. | <pre>object({<br> authorized_networks = list(map(string))<br> ipv4_enabled = bool<br> private_network = string<br> require_ssl = bool<br> })</pre> | <pre>{<br> "authorized_networks": [],<br> "ipv4_enabled": true,<br> "private_network": null,<br> "require_ssl": null<br>}</pre> | no |
| ip\_configuration | The ip configuration for the master instances. | <pre>object({<br> authorized_networks = list(map(string))<br> ipv4_enabled = bool<br> private_network = string<br> require_ssl = bool<br> allocated_ip_range = string<br> })</pre> | <pre>{<br> "allocated_ip_range": null,<br> "authorized_networks": [],<br> "ipv4_enabled": true,<br> "private_network": null,<br> "require_ssl": null<br>}</pre> | no |
| maintenance\_window\_day | The day of week (1-7) for the master instance maintenance. | `number` | `1` | no |
| maintenance\_window\_hour | The hour of day (0-23) maintenance window for the master instance maintenance. | `number` | `23` | no |
| maintenance\_window\_update\_track | The update track of maintenance window for the master instance maintenance.Can be either `canary` or `stable`. | `string` | `"canary"` | no |
Expand Down
7 changes: 4 additions & 3 deletions modules/mssql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ resource "google_sql_database_instance" "default" {
dynamic "ip_configuration" {
for_each = [local.ip_configurations[local.ip_configuration_enabled ? "enabled" : "disabled"]]
content {
ipv4_enabled = lookup(ip_configuration.value, "ipv4_enabled", null)
private_network = lookup(ip_configuration.value, "private_network", null)
require_ssl = lookup(ip_configuration.value, "require_ssl", null)
ipv4_enabled = lookup(ip_configuration.value, "ipv4_enabled", null)
private_network = lookup(ip_configuration.value, "private_network", null)
require_ssl = lookup(ip_configuration.value, "require_ssl", null)
allocated_ip_range = lookup(ip_configuration.value, "allocated_ip_range", null)

dynamic "authorized_networks" {
for_each = lookup(ip_configuration.value, "authorized_networks", [])
Expand Down
2 changes: 2 additions & 0 deletions modules/mssql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,14 @@ variable "ip_configuration" {
ipv4_enabled = bool
private_network = string
require_ssl = bool
allocated_ip_range = string
})
default = {
authorized_networks = []
ipv4_enabled = true
private_network = null
require_ssl = null
allocated_ip_range = null
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/mssql/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ terraform {

google-beta = {
source = "hashicorp/google-beta"
version = ">= 3.60, < 5.0"
version = ">= 4.4.0, < 5.0"
}
}

Expand Down
4 changes: 2 additions & 2 deletions modules/mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
| enable\_default\_db | Enable or disable the creation of the default database | `bool` | `true` | no |
| enable\_default\_user | Enable or disable the creation of the default user | `bool` | `true` | no |
| encryption\_key\_name | The full path to the encryption key used for the CMEK disk encryption | `string` | `null` | no |
| ip\_configuration | The ip\_configuration settings subblock | <pre>object({<br> authorized_networks = list(map(string))<br> ipv4_enabled = bool<br> private_network = string<br> require_ssl = bool<br> })</pre> | <pre>{<br> "authorized_networks": [],<br> "ipv4_enabled": true,<br> "private_network": null,<br> "require_ssl": null<br>}</pre> | no |
| ip\_configuration | The ip\_configuration settings subblock | <pre>object({<br> authorized_networks = list(map(string))<br> ipv4_enabled = bool<br> private_network = string<br> require_ssl = bool<br> allocated_ip_range = string<br> })</pre> | <pre>{<br> "allocated_ip_range": null,<br> "authorized_networks": [],<br> "ipv4_enabled": true,<br> "private_network": null,<br> "require_ssl": null<br>}</pre> | no |
| maintenance\_window\_day | The day of week (1-7) for the master instance maintenance. | `number` | `1` | no |
| maintenance\_window\_hour | The hour of day (0-23) maintenance window for the master instance maintenance. | `number` | `23` | no |
| maintenance\_window\_update\_track | The update track of maintenance window for the master instance maintenance. Can be either `canary` or `stable`. | `string` | `"canary"` | no |
Expand All @@ -37,7 +37,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
| random\_instance\_name | Sets random suffix at the end of the Cloud SQL resource name | `bool` | `false` | no |
| read\_replica\_deletion\_protection | Used to block Terraform from deleting replica SQL Instances. | `bool` | `false` | no |
| read\_replica\_name\_suffix | The optional suffix to add to the read instance name | `string` | `""` | no |
| read\_replicas | List of read replicas to create. Encryption key is required for replica in different region. For replica in same region as master set encryption\_key\_name = null | <pre>list(object({<br> name = string<br> tier = string<br> zone = string<br> disk_type = string<br> disk_autoresize = bool<br> disk_size = string<br> user_labels = map(string)<br> database_flags = list(object({<br> name = string<br> value = string<br> }))<br> ip_configuration = object({<br> authorized_networks = list(map(string))<br> ipv4_enabled = bool<br> private_network = string<br> require_ssl = bool<br> })<br> encryption_key_name = string<br> }))</pre> | `[]` | no |
| read\_replicas | List of read replicas to create. Encryption key is required for replica in different region. For replica in same region as master set encryption\_key\_name = null | <pre>list(object({<br> name = string<br> tier = string<br> zone = string<br> disk_type = string<br> disk_autoresize = bool<br> disk_size = string<br> user_labels = map(string)<br> database_flags = list(object({<br> name = string<br> value = string<br> }))<br> ip_configuration = object({<br> authorized_networks = list(map(string))<br> ipv4_enabled = bool<br> private_network = string<br> require_ssl = bool<br> allocated_ip_range = string<br> })<br> encryption_key_name = string<br> }))</pre> | `[]` | no |
| region | The region of the Cloud SQL resources | `string` | `"us-central1"` | no |
| tier | The tier for the master instance. | `string` | `"db-n1-standard-1"` | no |
| update\_timeout | The optional timout that is applied to limit long database updates. | `string` | `"10m"` | no |
Expand Down
7 changes: 4 additions & 3 deletions modules/mysql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ resource "google_sql_database_instance" "default" {
dynamic "ip_configuration" {
for_each = [local.ip_configurations[local.ip_configuration_enabled ? "enabled" : "disabled"]]
content {
ipv4_enabled = lookup(ip_configuration.value, "ipv4_enabled", null)
private_network = lookup(ip_configuration.value, "private_network", null)
require_ssl = lookup(ip_configuration.value, "require_ssl", null)
ipv4_enabled = lookup(ip_configuration.value, "ipv4_enabled", null)
private_network = lookup(ip_configuration.value, "private_network", null)
require_ssl = lookup(ip_configuration.value, "require_ssl", null)
allocated_ip_range = lookup(ip_configuration.value, "allocated_ip_range", null)

dynamic "authorized_networks" {
for_each = lookup(ip_configuration.value, "authorized_networks", [])
Expand Down
7 changes: 4 additions & 3 deletions modules/mysql/read_replica.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ resource "google_sql_database_instance" "replicas" {
dynamic "ip_configuration" {
for_each = [lookup(each.value, "ip_configuration", {})]
content {
ipv4_enabled = lookup(ip_configuration.value, "ipv4_enabled", null)
private_network = lookup(ip_configuration.value, "private_network", null)
require_ssl = lookup(ip_configuration.value, "require_ssl", null)
ipv4_enabled = lookup(ip_configuration.value, "ipv4_enabled", null)
private_network = lookup(ip_configuration.value, "private_network", null)
require_ssl = lookup(ip_configuration.value, "require_ssl", null)
allocated_ip_range = lookup(ip_configuration.value, "allocated_ip_range", null)

dynamic "authorized_networks" {
for_each = lookup(ip_configuration.value, "authorized_networks", [])
Expand Down
3 changes: 3 additions & 0 deletions modules/mysql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,14 @@ variable "ip_configuration" {
ipv4_enabled = bool
private_network = string
require_ssl = bool
allocated_ip_range = string
})
default = {
authorized_networks = []
ipv4_enabled = true
private_network = null
require_ssl = null
allocated_ip_range = null
}
}

Expand All @@ -183,6 +185,7 @@ variable "read_replicas" {
ipv4_enabled = bool
private_network = string
require_ssl = bool
allocated_ip_range = string
})
encryption_key_name = string
}))
Expand Down
2 changes: 1 addition & 1 deletion modules/mysql/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ terraform {
}
google = {
source = "hashicorp/google"
version = ">= 3.60, < 5.0"
version = ">= 4.4.0, < 5.0"
}
}

Expand Down
4 changes: 2 additions & 2 deletions modules/postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
| encryption\_key\_name | The full path to the encryption key used for the CMEK disk encryption | `string` | `null` | no |
| iam\_user\_emails | A list of IAM users to be created in your cluster | `list(string)` | `[]` | no |
| insights\_config | The insights\_config settings for the database. | <pre>object({<br> query_string_length = number<br> record_application_tags = bool<br> record_client_address = bool<br> })</pre> | `null` | no |
| ip\_configuration | The ip configuration for the master instances. | <pre>object({<br> authorized_networks = list(map(string))<br> ipv4_enabled = bool<br> private_network = string<br> require_ssl = bool<br> })</pre> | <pre>{<br> "authorized_networks": [],<br> "ipv4_enabled": true,<br> "private_network": null,<br> "require_ssl": null<br>}</pre> | no |
| ip\_configuration | The ip configuration for the master instances. | <pre>object({<br> authorized_networks = list(map(string))<br> ipv4_enabled = bool<br> private_network = string<br> require_ssl = bool<br> allocated_ip_range = string<br> })</pre> | <pre>{<br> "allocated_ip_range": null,<br> "authorized_networks": [],<br> "ipv4_enabled": true,<br> "private_network": null,<br> "require_ssl": null<br>}</pre> | no |
| maintenance\_window\_day | The day of week (1-7) for the master instance maintenance. | `number` | `1` | no |
| maintenance\_window\_hour | The hour of day (0-23) maintenance window for the master instance maintenance. | `number` | `23` | no |
| maintenance\_window\_update\_track | The update track of maintenance window for the master instance maintenance.Can be either `canary` or `stable`. | `string` | `"canary"` | no |
Expand All @@ -39,7 +39,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
| random\_instance\_name | Sets random suffix at the end of the Cloud SQL resource name | `bool` | `false` | no |
| read\_replica\_deletion\_protection | Used to block Terraform from deleting replica SQL Instances. | `bool` | `false` | no |
| read\_replica\_name\_suffix | The optional suffix to add to the read instance name | `string` | `""` | no |
| read\_replicas | List of read replicas to create. Encryption key is required for replica in different region. For replica in same region as master set encryption\_key\_name = null | <pre>list(object({<br> name = string<br> tier = string<br> zone = string<br> disk_type = string<br> disk_autoresize = bool<br> disk_size = string<br> user_labels = map(string)<br> database_flags = list(object({<br> name = string<br> value = string<br> }))<br> ip_configuration = object({<br> authorized_networks = list(map(string))<br> ipv4_enabled = bool<br> private_network = string<br> require_ssl = bool<br> })<br> encryption_key_name = string<br> }))</pre> | `[]` | no |
| read\_replicas | List of read replicas to create. Encryption key is required for replica in different region. For replica in same region as master set encryption\_key\_name = null | <pre>list(object({<br> name = string<br> tier = string<br> zone = string<br> disk_type = string<br> disk_autoresize = bool<br> disk_size = string<br> user_labels = map(string)<br> database_flags = list(object({<br> name = string<br> value = string<br> }))<br> ip_configuration = object({<br> authorized_networks = list(map(string))<br> ipv4_enabled = bool<br> private_network = string<br> require_ssl = bool<br> allocated_ip_range = string<br> })<br> encryption_key_name = string<br> }))</pre> | `[]` | no |
| region | The region of the Cloud SQL resources | `string` | `"us-central1"` | no |
| tier | The tier for the master instance. | `string` | `"db-f1-micro"` | no |
| update\_timeout | The optional timout that is applied to limit long database updates. | `string` | `"15m"` | no |
Expand Down
7 changes: 4 additions & 3 deletions modules/postgresql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ resource "google_sql_database_instance" "default" {
dynamic "ip_configuration" {
for_each = [local.ip_configurations[local.ip_configuration_enabled ? "enabled" : "disabled"]]
content {
ipv4_enabled = lookup(ip_configuration.value, "ipv4_enabled", null)
private_network = lookup(ip_configuration.value, "private_network", null)
require_ssl = lookup(ip_configuration.value, "require_ssl", null)
ipv4_enabled = lookup(ip_configuration.value, "ipv4_enabled", null)
private_network = lookup(ip_configuration.value, "private_network", null)
require_ssl = lookup(ip_configuration.value, "require_ssl", null)
allocated_ip_range = lookup(ip_configuration.value, "allocated_ip_range", null)

dynamic "authorized_networks" {
for_each = lookup(ip_configuration.value, "authorized_networks", [])
Expand Down
7 changes: 4 additions & 3 deletions modules/postgresql/read_replica.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ resource "google_sql_database_instance" "replicas" {
dynamic "ip_configuration" {
for_each = [lookup(each.value, "ip_configuration", {})]
content {
ipv4_enabled = lookup(ip_configuration.value, "ipv4_enabled", null)
private_network = lookup(ip_configuration.value, "private_network", null)
require_ssl = lookup(ip_configuration.value, "require_ssl", null)
ipv4_enabled = lookup(ip_configuration.value, "ipv4_enabled", null)
private_network = lookup(ip_configuration.value, "private_network", null)
require_ssl = lookup(ip_configuration.value, "require_ssl", null)
allocated_ip_range = lookup(ip_configuration.value, "allocated_ip_range", null)

dynamic "authorized_networks" {
for_each = lookup(ip_configuration.value, "authorized_networks", [])
Expand Down
3 changes: 3 additions & 0 deletions modules/postgresql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,14 @@ variable "ip_configuration" {
ipv4_enabled = bool
private_network = string
require_ssl = bool
allocated_ip_range = string
})
default = {
authorized_networks = []
ipv4_enabled = true
private_network = null
require_ssl = null
allocated_ip_range = null
}
}

Expand All @@ -190,6 +192,7 @@ variable "read_replicas" {
ipv4_enabled = bool
private_network = string
require_ssl = bool
allocated_ip_range = string
})
encryption_key_name = string
}))
Expand Down
2 changes: 1 addition & 1 deletion modules/postgresql/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ terraform {
}
google = {
source = "hashicorp/google"
version = ">= 3.60, < 5.0"
version = ">= 4.4.0, < 5.0"
}
}

Expand Down

0 comments on commit ab8c768

Please sign in to comment.