Skip to content

Commit add13c3

Browse files
authored
Merge pull request #78 from omazin/module-depends-on
Replace extraneous label with module dependency.
2 parents d0277dc + 274d09a commit add13c3

File tree

12 files changed

+62
-49
lines changed

12 files changed

+62
-49
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Removed
11+
12+
- Removed variable `peering_completed`. [#78]
13+
14+
### Added
15+
16+
- Added variable `module_depends_on`. [#78]
17+
1018
## [2.0.0] - 2019-09-26
1119

1220
2.0.0 is a backward incompatible release. Review the
@@ -52,3 +60,4 @@ project adheres to [Semantic Versioning](http://semver.org/).
5260
[#56]: https://github.com/terraform-google-modules/terraform-google-sql-db/pull/56
5361
[#53]: https://github.com/terraform-google-modules/terraform-google-sql-db/pull/53
5462
[#43]: https://github.com/terraform-google-modules/terraform-google-sql-db/pull/43
63+
[#78]: https://github.com/terraform-google-modules/terraform-google-sql-db/pull/78

examples/mysql-and-postgres-private/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ module "safer-mysql-db" {
130130
vpc_network = google_compute_network.default.self_link
131131

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

136136

modules/mysql/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
| maintenance\_window\_day | The day of week (1-7) for the master instance maintenance. | number | `"1"` | no |
4343
| maintenance\_window\_hour | The hour of day (0-23) maintenance window for the master instance maintenance. | number | `"23"` | no |
4444
| maintenance\_window\_update\_track | The update track of maintenance window for the master instance maintenance. Can be either `canary` or `stable`. | string | `"canary"` | no |
45+
| module\_depends\_on | List of modules or resources this module depends on. | list(any) | `<list>` | no |
4546
| name | The name of the Cloud SQL resources | string | n/a | yes |
4647
| pricing\_plan | The pricing plan for the master instance. | string | `"PER_USE"` | no |
4748
| project\_id | The project ID to manage the Cloud SQL resources | string | n/a | yes |

modules/mysql/main.tf

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ resource "google_sql_database_instance" "default" {
9696
update = var.update_timeout
9797
delete = var.delete_timeout
9898
}
99+
100+
depends_on = [null_resource.module_depends_on]
99101
}
100102

101103
resource "google_sql_database" "default" {
@@ -104,7 +106,7 @@ resource "google_sql_database" "default" {
104106
instance = google_sql_database_instance.default.name
105107
charset = var.db_charset
106108
collation = var.db_collation
107-
depends_on = [google_sql_database_instance.default]
109+
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
108110
}
109111

110112
resource "google_sql_database" "additional_databases" {
@@ -114,7 +116,7 @@ resource "google_sql_database" "additional_databases" {
114116
charset = lookup(var.additional_databases[count.index], "charset", null)
115117
collation = lookup(var.additional_databases[count.index], "collation", null)
116118
instance = google_sql_database_instance.default.name
117-
depends_on = [google_sql_database_instance.default]
119+
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
118120
}
119121

120122
resource "random_id" "user-password" {
@@ -123,7 +125,7 @@ resource "random_id" "user-password" {
123125
}
124126

125127
byte_length = 8
126-
depends_on = [google_sql_database_instance.default]
128+
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
127129
}
128130

129131
resource "google_sql_user" "default" {
@@ -132,7 +134,7 @@ resource "google_sql_user" "default" {
132134
instance = google_sql_database_instance.default.name
133135
host = var.user_host
134136
password = var.user_password == "" ? random_id.user-password.hex : var.user_password
135-
depends_on = [google_sql_database_instance.default]
137+
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
136138
}
137139

138140
resource "google_sql_user" "additional_users" {
@@ -146,6 +148,11 @@ resource "google_sql_user" "additional_users" {
146148
)
147149
host = lookup(var.additional_users[count.index], "host", var.user_host)
148150
instance = google_sql_database_instance.default.name
149-
depends_on = [google_sql_database_instance.default]
151+
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
150152
}
151153

154+
resource "null_resource" "module_depends_on" {
155+
triggers = {
156+
value = length(var.module_depends_on)
157+
}
158+
}

modules/mysql/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,3 +522,8 @@ variable "delete_timeout" {
522522
default = "10m"
523523
}
524524

525+
variable "module_depends_on" {
526+
description = "List of modules or resources this module depends on."
527+
type = list(any)
528+
default = []
529+
}

modules/postgresql/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
| maintenance\_window\_day | The day of week (1-7) for the master instance maintenance. | number | `"1"` | no |
2626
| maintenance\_window\_hour | The hour of day (0-23) maintenance window for the master instance maintenance. | number | `"23"` | no |
2727
| maintenance\_window\_update\_track | The update track of maintenance window for the master instance maintenance.Can be either `canary` or `stable`. | string | `"canary"` | no |
28+
| module\_depends\_on | List of modules or resources this module depends on. | list(any) | `<list>` | no |
2829
| name | The name of the Cloud SQL resources | string | n/a | yes |
29-
| 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 |
3030
| pricing\_plan | The pricing plan for the master instance. | string | `"PER_USE"` | no |
3131
| project\_id | The project ID to manage the Cloud SQL resources | string | n/a | yes |
3232
| read\_replica\_activation\_policy | The activation policy for the read replica instances.Can be either `ALWAYS`, `NEVER` or `ON_DEMAND`. | string | `"ALWAYS"` | no |

modules/postgresql/main.tf

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ locals {
2121
enabled = var.ip_configuration
2222
disabled = {}
2323
}
24-
25-
peering_completed_enabled = var.peering_completed != "" ? true : false
26-
27-
user_labels_including_tf_dependency = {
28-
enabled = merge(map("tf_dependency", var.peering_completed), var.user_labels)
29-
disabled = var.user_labels
30-
}
3124
}
3225

3326
resource "google_sql_database_instance" "default" {
@@ -79,10 +72,7 @@ resource "google_sql_database_instance" "default" {
7972
}
8073
}
8174

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

8777
location_preference {
8878
zone = "${var.region}-${var.zone}"
@@ -106,6 +96,8 @@ resource "google_sql_database_instance" "default" {
10696
update = var.update_timeout
10797
delete = var.delete_timeout
10898
}
99+
100+
depends_on = [null_resource.module_depends_on]
109101
}
110102

111103
resource "google_sql_database" "default" {
@@ -114,7 +106,7 @@ resource "google_sql_database" "default" {
114106
instance = google_sql_database_instance.default.name
115107
charset = var.db_charset
116108
collation = var.db_collation
117-
depends_on = [google_sql_database_instance.default]
109+
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
118110
}
119111

120112
resource "google_sql_database" "additional_databases" {
@@ -124,7 +116,7 @@ resource "google_sql_database" "additional_databases" {
124116
charset = lookup(var.additional_databases[count.index], "charset", "")
125117
collation = lookup(var.additional_databases[count.index], "collation", "")
126118
instance = google_sql_database_instance.default.name
127-
depends_on = [google_sql_database_instance.default]
119+
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
128120
}
129121

130122
resource "random_id" "user-password" {
@@ -133,15 +125,15 @@ resource "random_id" "user-password" {
133125
}
134126

135127
byte_length = 8
136-
depends_on = [google_sql_database_instance.default]
128+
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
137129
}
138130

139131
resource "google_sql_user" "default" {
140132
name = var.user_name
141133
project = var.project_id
142134
instance = google_sql_database_instance.default.name
143135
password = var.user_password == "" ? random_id.user-password.hex : var.user_password
144-
depends_on = [google_sql_database_instance.default]
136+
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
145137
}
146138

147139
resource "google_sql_user" "additional_users" {
@@ -154,5 +146,11 @@ resource "google_sql_user" "additional_users" {
154146
random_id.user-password.hex,
155147
)
156148
instance = google_sql_database_instance.default.name
157-
depends_on = [google_sql_database_instance.default]
149+
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
150+
}
151+
152+
resource "null_resource" "module_depends_on" {
153+
triggers = {
154+
value = length(var.module_depends_on)
155+
}
158156
}

modules/postgresql/variables.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ variable "zone" {
4848
description = "The zone for the master instance, it should be something like: `a`, `c`."
4949
}
5050

51-
variable "peering_completed" {
52-
description = "Optional. This is used to ensure that resources are created in the proper order when using private IPs and service network peering."
53-
type = string
54-
default = ""
55-
}
56-
5751
variable "activation_policy" {
5852
description = "The activation policy for the master instance.Can be either `ALWAYS`, `NEVER` or `ON_DEMAND`."
5953
type = string
@@ -363,3 +357,9 @@ variable "delete_timeout" {
363357
type = string
364358
default = "10m"
365359
}
360+
361+
variable "module_depends_on" {
362+
description = "List of modules or resources this module depends on."
363+
type = list(any)
364+
default = []
365+
}

modules/safer_mysql/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ mysql -S $HOME/mysql_sockets/myproject:region:instance -u user -p
200200
| maintenance\_window\_day | The day of week (1-7) for the master instance maintenance. | number | `"1"` | no |
201201
| maintenance\_window\_hour | The hour of day (0-23) maintenance window for the master instance maintenance. | number | `"23"` | no |
202202
| maintenance\_window\_update\_track | The update track of maintenance window for the master instance maintenance. Can be either `canary` or `stable`. | string | `"stable"` | no |
203+
| module\_depends\_on | List of modules or resources this module depends on. | list(any) | `<list>` | no |
203204
| name | The name of the Cloud SQL resources | string | n/a | yes |
204-
| 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 |
205205
| pricing\_plan | The pricing plan for the master instance. | string | `"PER_USE"` | no |
206206
| project\_id | The project ID to manage the Cloud SQL resources | string | n/a | yes |
207207
| read\_replica\_activation\_policy | The activation policy for the read replica instances. Can be either `ALWAYS`, `NEVER` or `ON_DEMAND`. | string | `"ALWAYS"` | no |

modules/safer_mysql/main.tf

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,7 @@ module "safer_mysql" {
3333
maintenance_window_update_track = var.maintenance_window_update_track
3434
database_flags = var.database_flags
3535

36-
// Define a label to force a dependency to the creation of the network peering.
37-
// Substitute this with a module dependency once the module is migrated to
38-
// Terraform 0.12
39-
user_labels = merge(
40-
{
41-
"tf_dependency" = var.peering_completed
42-
},
43-
var.user_labels,
44-
)
36+
user_labels = var.user_labels
4537

4638
backup_configuration = var.backup_configuration
4739

@@ -119,7 +111,8 @@ module "safer_mysql" {
119111
private_network = var.vpc_network
120112
require_ssl = true
121113
}
122-
create_timeout = var.create_timeout
123-
update_timeout = var.update_timeout
124-
delete_timeout = var.delete_timeout
114+
create_timeout = var.create_timeout
115+
update_timeout = var.update_timeout
116+
delete_timeout = var.delete_timeout
117+
module_depends_on = var.module_depends_on
125118
}

0 commit comments

Comments
 (0)