Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace extraneous label with module dependency. #78

Merged
merged 3 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Removed

- Removed variable `peering_completed`. [#78]

### Added

- Added variable `module_depends_on`. [#78]

## [2.0.0] - 2019-09-26

2.0.0 is a backward incompatible release. Review the
Expand Down Expand Up @@ -52,3 +60,4 @@ project adheres to [Semantic Versioning](http://semver.org/).
[#56]: https://github.com/terraform-google-modules/terraform-google-sql-db/pull/56
[#53]: https://github.com/terraform-google-modules/terraform-google-sql-db/pull/53
[#43]: https://github.com/terraform-google-modules/terraform-google-sql-db/pull/43
[#78]: https://github.com/terraform-google-modules/terraform-google-sql-db/pull/78
2 changes: 1 addition & 1 deletion examples/mysql-and-postgres-private/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ module "safer-mysql-db" {
vpc_network = google_compute_network.default.self_link

// Used to enforce ordering in the creation of resources.
peering_completed = module.private-service-access.peering_completed
module_depends_on = [module.private-service-access.peering_completed]
}


1 change: 1 addition & 0 deletions modules/mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
| 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 |
| module\_depends\_on | List of modules or resources this module depends on. | list(any) | `<list>` | no |
| name | The name of the Cloud SQL resources | string | n/a | yes |
| pricing\_plan | The pricing plan for the master instance. | string | `"PER_USE"` | no |
| project\_id | The project ID to manage the Cloud SQL resources | string | n/a | yes |
Expand Down
17 changes: 12 additions & 5 deletions modules/mysql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ resource "google_sql_database_instance" "default" {
update = var.update_timeout
delete = var.delete_timeout
}

depends_on = [null_resource.module_depends_on]
}

resource "google_sql_database" "default" {
Expand All @@ -104,7 +106,7 @@ resource "google_sql_database" "default" {
instance = google_sql_database_instance.default.name
charset = var.db_charset
collation = var.db_collation
depends_on = [google_sql_database_instance.default]
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
}

resource "google_sql_database" "additional_databases" {
Expand All @@ -114,7 +116,7 @@ resource "google_sql_database" "additional_databases" {
charset = lookup(var.additional_databases[count.index], "charset", null)
collation = lookup(var.additional_databases[count.index], "collation", null)
instance = google_sql_database_instance.default.name
depends_on = [google_sql_database_instance.default]
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
}

resource "random_id" "user-password" {
Expand All @@ -123,7 +125,7 @@ resource "random_id" "user-password" {
}

byte_length = 8
depends_on = [google_sql_database_instance.default]
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
}

resource "google_sql_user" "default" {
Expand All @@ -132,7 +134,7 @@ resource "google_sql_user" "default" {
instance = google_sql_database_instance.default.name
host = var.user_host
password = var.user_password == "" ? random_id.user-password.hex : var.user_password
depends_on = [google_sql_database_instance.default]
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
}

resource "google_sql_user" "additional_users" {
Expand All @@ -146,6 +148,11 @@ resource "google_sql_user" "additional_users" {
)
host = lookup(var.additional_users[count.index], "host", var.user_host)
instance = google_sql_database_instance.default.name
depends_on = [google_sql_database_instance.default]
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
}

resource "null_resource" "module_depends_on" {
triggers = {
value = length(var.module_depends_on)
}
}
5 changes: 5 additions & 0 deletions modules/mysql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -522,3 +522,8 @@ variable "delete_timeout" {
default = "10m"
}

variable "module_depends_on" {
description = "List of modules or resources this module depends on."
type = list(any)
default = []
}
2 changes: 1 addition & 1 deletion modules/postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
| 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 |
| module\_depends\_on | List of modules or resources this module depends on. | list(any) | `<list>` | no |
| name | The name of the Cloud SQL resources | string | n/a | yes |
| peering\_completed | Optional. This is used to ensure that resources are created in the proper order when using private IPs and service network peering. | string | `""` | no |
| pricing\_plan | The pricing plan for the master instance. | string | `"PER_USE"` | no |
| project\_id | The project ID to manage the Cloud SQL resources | string | n/a | yes |
| read\_replica\_activation\_policy | The activation policy for the read replica instances.Can be either `ALWAYS`, `NEVER` or `ON_DEMAND`. | string | `"ALWAYS"` | no |
Expand Down
30 changes: 14 additions & 16 deletions modules/postgresql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ locals {
enabled = var.ip_configuration
disabled = {}
}

peering_completed_enabled = var.peering_completed != "" ? true : false

user_labels_including_tf_dependency = {
enabled = merge(map("tf_dependency", var.peering_completed), var.user_labels)
disabled = var.user_labels
}
}

resource "google_sql_database_instance" "default" {
Expand Down Expand Up @@ -79,10 +72,7 @@ resource "google_sql_database_instance" "default" {
}
}

// Define a label to force a dependency to the creation of the network peering.
// Substitute this with a module dependency once the module is migrated to
// Terraform 0.12
user_labels = local.user_labels_including_tf_dependency["${local.peering_completed_enabled ? "enabled" : "disabled"}"]
user_labels = var.user_labels

location_preference {
zone = "${var.region}-${var.zone}"
Expand All @@ -106,6 +96,8 @@ resource "google_sql_database_instance" "default" {
update = var.update_timeout
delete = var.delete_timeout
}

depends_on = [null_resource.module_depends_on]
}

resource "google_sql_database" "default" {
Expand All @@ -114,7 +106,7 @@ resource "google_sql_database" "default" {
instance = google_sql_database_instance.default.name
charset = var.db_charset
collation = var.db_collation
depends_on = [google_sql_database_instance.default]
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
}

resource "google_sql_database" "additional_databases" {
Expand All @@ -124,7 +116,7 @@ resource "google_sql_database" "additional_databases" {
charset = lookup(var.additional_databases[count.index], "charset", "")
collation = lookup(var.additional_databases[count.index], "collation", "")
instance = google_sql_database_instance.default.name
depends_on = [google_sql_database_instance.default]
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
}

resource "random_id" "user-password" {
Expand All @@ -133,15 +125,15 @@ resource "random_id" "user-password" {
}

byte_length = 8
depends_on = [google_sql_database_instance.default]
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
}

resource "google_sql_user" "default" {
name = var.user_name
project = var.project_id
instance = google_sql_database_instance.default.name
password = var.user_password == "" ? random_id.user-password.hex : var.user_password
depends_on = [google_sql_database_instance.default]
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
}

resource "google_sql_user" "additional_users" {
Expand All @@ -154,5 +146,11 @@ resource "google_sql_user" "additional_users" {
random_id.user-password.hex,
)
instance = google_sql_database_instance.default.name
depends_on = [google_sql_database_instance.default]
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
}

resource "null_resource" "module_depends_on" {
triggers = {
value = length(var.module_depends_on)
}
}
12 changes: 6 additions & 6 deletions modules/postgresql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ variable "zone" {
description = "The zone for the master instance, it should be something like: `a`, `c`."
}

variable "peering_completed" {
description = "Optional. This is used to ensure that resources are created in the proper order when using private IPs and service network peering."
type = string
default = ""
}

variable "activation_policy" {
description = "The activation policy for the master instance.Can be either `ALWAYS`, `NEVER` or `ON_DEMAND`."
type = string
Expand Down Expand Up @@ -363,3 +357,9 @@ variable "delete_timeout" {
type = string
default = "10m"
}

variable "module_depends_on" {
description = "List of modules or resources this module depends on."
type = list(any)
default = []
}
2 changes: 1 addition & 1 deletion modules/safer_mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ mysql -S $HOME/mysql_sockets/myproject:region:instance -u user -p
| 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 | `"stable"` | no |
| module\_depends\_on | List of modules or resources this module depends on. | list(any) | `<list>` | no |
| name | The name of the Cloud SQL resources | string | n/a | yes |
| peering\_completed | Optional. This is used to ensure that resources are created in the proper order when using private IPs and service network peering. | string | `""` | no |
| pricing\_plan | The pricing plan for the master instance. | string | `"PER_USE"` | no |
| project\_id | The project ID to manage the Cloud SQL resources | string | n/a | yes |
| read\_replica\_activation\_policy | The activation policy for the read replica instances. Can be either `ALWAYS`, `NEVER` or `ON_DEMAND`. | string | `"ALWAYS"` | no |
Expand Down
17 changes: 5 additions & 12 deletions modules/safer_mysql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,7 @@ module "safer_mysql" {
maintenance_window_update_track = var.maintenance_window_update_track
database_flags = var.database_flags

// Define a label to force a dependency to the creation of the network peering.
// Substitute this with a module dependency once the module is migrated to
// Terraform 0.12
user_labels = merge(
{
"tf_dependency" = var.peering_completed
},
var.user_labels,
)
user_labels = var.user_labels

backup_configuration = var.backup_configuration

Expand Down Expand Up @@ -119,7 +111,8 @@ module "safer_mysql" {
private_network = var.vpc_network
require_ssl = true
}
create_timeout = var.create_timeout
update_timeout = var.update_timeout
delete_timeout = var.delete_timeout
create_timeout = var.create_timeout
update_timeout = var.update_timeout
delete_timeout = var.delete_timeout
module_depends_on = var.module_depends_on
}
12 changes: 6 additions & 6 deletions modules/safer_mysql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ variable "vpc_network" {
type = string
}

variable "peering_completed" {
description = "Optional. This is used to ensure that resources are created in the proper order when using private IPs and service network peering."
type = string
default = ""
}

// Master
variable "tier" {
description = "The tier for the master instance."
Expand Down Expand Up @@ -482,3 +476,9 @@ variable "delete_timeout" {
type = string
default = "15m"
}

variable "module_depends_on" {
description = "List of modules or resources this module depends on."
type = list(any)
default = []
}
2 changes: 1 addition & 1 deletion test/fixtures/safer-mysql-simple/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@ module "safer-mysql-db" {
vpc_network = module.network-safer-mysql-simple.network_self_link

// Optional: used to enforce ordering in the creation of resources.
peering_completed = module.private-service-access.peering_completed
module_depends_on = [module.private-service-access.peering_completed]
}