Skip to content

Commit de16a90

Browse files
committed
drop changes in google_sql_database and google_sql_user
1 parent 903e617 commit de16a90

File tree

16 files changed

+118
-162
lines changed

16 files changed

+118
-162
lines changed

modules/mysql/README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
| backup_configuration | The backup configuration block of the Cloud SQL resources This argument will be passed through the master instance directrly.<br><br>See [more details](https://www.terraform.io/docs/providers/google/r/sql_database_instance.html). | map | `<map>` | no |
1212
| database_flags | The database flags for the master instance. See [more details](https://cloud.google.com/sql/docs/mysql/flags) | list | `<list>` | no |
1313
| database_version | The database version to use | string | - | yes |
14-
| databases | The list of databases for the instacne | list | `<list>` | no |
14+
| db_charset | The charset for the default database | string | `` | no |
15+
| db_collation | The collation for the default database. Example: 'utf8_general_ci' | string | `` | no |
16+
| db_name | The name of the default database to create | string | `default` | no |
1517
| disk_autoresize | Configuration to increase storage size | string | `true` | no |
1618
| disk_size | The disk size for the master instance | string | `10` | no |
1719
| disk_type | The disk type for the master instance. | string | `PD_SSD` | no |
@@ -58,18 +60,16 @@
5860
| read_replica_zones | The zones for the read replica instancess, it should be something like: `a,b,c`. Given zones are used rotationally for creating read replicas. | string | `` | no |
5961
| region | The region of the Cloud SQL resources | string | `us-central1` | no |
6062
| tier | The tier for the master instance. | string | `db-n1-standard-1` | no |
63+
| user_host | The host for the default user | string | `%` | no |
6164
| user_labels | The key/value labels for the master instances. | map | `<map>` | no |
62-
| users | The list of users on the database | list | `<list>` | no |
65+
| user_name | The name of the default user | string | `default` | no |
66+
| user_password | The password for the default user. If not set, a random one will be generated and available in the generated_user_password output variable. | string | `` | no |
6367
| zone | The zone for the master instance, it should be something like: `a`, `c`. | string | - | yes |
6468

6569
## Outputs
6670

6771
| Name | Description |
6872
|------|-------------|
69-
| database_charsets | The list of database charsets |
70-
| database_collation | The list of database collations |
71-
| database_names | The list of database names |
72-
| database_self_links | The URIs of the databases |
7373
| failover-replica_instance_connection_name | The connection name of the failover-replica instance to be used in connection strings |
7474
| failover-replica_instance_first_ip_address | The first IPv4 address of the addesses assigned for the failover-replica instance |
7575
| failover-replica_instance_name | The instance name for the failover replica instance |
@@ -90,8 +90,5 @@
9090
| replicas_instance_self_links | The URIs of the replica instances |
9191
| replicas_instance_server_ca_certs | The CA certificates information used to connect to the replica instances via SSL |
9292
| replicas_instance_service_account_email_addresses | The service account email addresses assigned to the replica instances |
93-
| user_hosts | The list of user hosts for the database |
94-
| user_names | The list of user names for the database |
95-
| user_passwords | The list of user passwords for the database |
9693

9794
[^]: (autogen_docs_end)

modules/mysql/main.tf

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
*/
1616

1717
locals {
18-
default_user_host = "%"
18+
default_user_host = "%"
19+
ip_configuration_enabled = "${length(keys(var.ip_configuration)) > 0 ? true : false}"
20+
21+
ip_configurations = {
22+
enabled = "${list(var.ip_configuration)}"
23+
disabled = "${list()}"
24+
}
1925
}
2026

2127
resource "google_sql_database_instance" "default" {
@@ -29,7 +35,7 @@ resource "google_sql_database_instance" "default" {
2935
activation_policy = "${var.activation_policy}"
3036
authorized_gae_applications = ["${var.authorized_gae_applications}"]
3137
backup_configuration = ["${var.backup_configuration}"]
32-
ip_configuration = ["${var.ip_configuration}"]
38+
ip_configuration = "${local.ip_configurations["${local.ip_configuration_enabled ? "enabled" : "disabled"}"]}"
3339

3440
disk_autoresize = "${var.disk_autoresize}"
3541

@@ -55,13 +61,12 @@ resource "google_sql_database_instance" "default" {
5561
}
5662
}
5763

58-
resource "google_sql_database" "databases" {
59-
count = "${length(var.databases)}"
64+
resource "google_sql_database" "default" {
65+
name = "${var.db_name}"
6066
project = "${var.project_id}"
61-
name = "${lookup(var.databases[count.index], "name")}"
62-
charset = "${lookup(var.databases[count.index], "charset", "utf8mb4")}"
63-
collation = "${lookup(var.databases[count.index], "collation", "utf8mb4_general_ci")}"
6467
instance = "${google_sql_database_instance.default.name}"
68+
charset = "${var.db_charset}"
69+
collation = "${var.db_collation}"
6570
depends_on = ["google_sql_database_instance.default"]
6671
}
6772

@@ -74,12 +79,11 @@ resource "random_id" "user-password" {
7479
depends_on = ["google_sql_database_instance.default"]
7580
}
7681

77-
resource "google_sql_user" "users" {
78-
count = "${length(var.users)}"
82+
resource "google_sql_user" "default" {
83+
name = "${var.user_name}"
7984
project = "${var.project_id}"
8085
instance = "${google_sql_database_instance.default.name}"
81-
name = "${lookup(var.users[count.index], "name")}"
82-
password = "${lookup(var.users[count.index], "password", random_id.user-password.hex)}"
83-
host = "${lookup(var.users[count.index], "host", local.default_user_host)}"
86+
host = "${var.user_host}"
87+
password = "${var.user_password == "" ? random_id.user-password.hex : var.user_password}"
8488
depends_on = ["google_sql_database_instance.default"]
8589
}

modules/mysql/outputs.tf

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -112,41 +112,6 @@ output "failover-replica_instance_name" {
112112
description = "The instance name for the failover replica instance"
113113
}
114114

115-
output "user_names" {
116-
value = ["${google_sql_user.users.*.name}"]
117-
description = "The list of user names for the database"
118-
}
119-
120-
output "user_passwords" {
121-
value = ["${google_sql_user.users.*.password}"]
122-
description = "The list of user passwords for the database"
123-
}
124-
125-
output "user_hosts" {
126-
value = ["${google_sql_user.users.*.host}"]
127-
description = "The list of user hosts for the database"
128-
}
129-
130-
output "database_names" {
131-
value = ["${google_sql_database.databases.*.name}"]
132-
description = "The list of database names"
133-
}
134-
135-
output "database_charsets" {
136-
value = ["${google_sql_database.databases.*.charset}"]
137-
description = "The list of database charsets"
138-
}
139-
140-
output "database_collation" {
141-
value = ["${google_sql_database.databases.*.collation}"]
142-
description = "The list of database collations"
143-
}
144-
145-
output "database_self_links" {
146-
value = ["${google_sql_database.databases.*.self_link}"]
147-
description = "The URIs of the databases"
148-
}
149-
150115
output "generated_user_password" {
151116
description = "The auto generated default user password if not input password was provided"
152117
value = "${random_id.user-password.hex}"

modules/mysql/read_replica.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ resource "google_sql_database_instance" "replicas" {
4141
settings {
4242
tier = "${var.read_replica_tier}"
4343
activation_policy = "${var.read_replica_activation_policy}"
44-
ip_configuration = ["${var.read_replica_ip_configuration}"]
44+
ip_configuration = "${local.ip_configurations["${local.ip_configuration_enabled ? "enabled" : "disabled"}"]}"
4545
authorized_gae_applications = ["${var.authorized_gae_applications}"]
4646

4747
crash_safe_replication = "${var.read_replica_crash_safe_replication}"

modules/mysql/variables.tf

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,32 @@ variable "failover_replica_ip_configuration" {
288288
default = {}
289289
}
290290

291-
// for google_sql_database
292-
variable "databases" {
293-
default = []
294-
description = "The list of databases for the instacne"
291+
variable "db_name" {
292+
description = "The name of the default database to create"
293+
default = "default"
295294
}
296295

297-
// for google_sql_user
298-
variable "users" {
299-
default = []
300-
description = "The list of users on the database"
296+
variable "db_charset" {
297+
description = "The charset for the default database"
298+
default = ""
299+
}
300+
301+
variable "db_collation" {
302+
description = "The collation for the default database. Example: 'utf8_general_ci'"
303+
default = ""
304+
}
305+
306+
variable "user_name" {
307+
description = "The name of the default user"
308+
default = "default"
309+
}
310+
311+
variable "user_host" {
312+
description = "The host for the default user"
313+
default = "%"
314+
}
315+
316+
variable "user_password" {
317+
description = "The password for the default user. If not set, a random one will be generated and available in the generated_user_password output variable."
318+
default = ""
301319
}

modules/postgresql/README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
| backup_configuration | The backup configuration block of the Cloud SQL resources This argument will be passed through the master instance directrly.<br><br>See [more details](https://www.terraform.io/docs/providers/google/r/sql_database_instance.html). | map | `<map>` | no |
1313
| database_flags | The database flags for the master instance. See [more details](https://cloud.google.com/sql/docs/mysql/flags) | list | `<list>` | no |
1414
| database_version | The database version to use | string | - | yes |
15-
| databases | The list of databases for the instacne | list | `<list>` | no |
15+
| db_charset | The charset for the default database | string | `` | no |
16+
| db_collation | The collation for the default database. Example: 'en_US.UTF8' | string | `` | no |
17+
| db_name | The name of the default database to create | string | `default` | no |
1618
| disk_autoresize | Configuration to increase storage size. | string | `true` | no |
1719
| disk_size | The disk size for the master instance. | string | `10` | no |
1820
| disk_type | The disk type for the master instance. | string | `PD_SSD` | no |
@@ -43,18 +45,16 @@
4345
| read_replica_zones | The zones for the read replica instancess, it should be something like: `a,b,c`. Given zones are used rotationally for creating read replicas. | string | `` | no |
4446
| region | The region of the Cloud SQL resources | string | `us-central1` | no |
4547
| tier | The tier for the master instance. | string | `db-f1-micro` | no |
48+
| user_host | The host for the default user | string | `%` | no |
4649
| user_labels | The key/value labels for the master instances. | map | `<map>` | no |
47-
| users | The list of users on the database | list | `<list>` | no |
50+
| user_name | The name of the default user | string | `default` | no |
51+
| user_password | The password for the default user. If not set, a random one will be generated and available in the generated_user_password output variable. | string | `` | no |
4852
| zone | The zone for the master instance, it should be something like: `a`, `c`. | string | - | yes |
4953

5054
## Outputs
5155

5256
| Name | Description |
5357
|------|-------------|
54-
| database_charsets | The list of database charsets |
55-
| database_collation | The list of database collations |
56-
| database_names | The list of database names |
57-
| database_self_links | The URIs of the databases |
5858
| generated_user_password | The auto generated default user password if not input password was provided |
5959
| instance_address | The IPv4 addesses assigned for the master instance |
6060
| instance_connection_name | The connection name of the master instance to be used in connection strings |
@@ -69,8 +69,5 @@
6969
| replicas_instance_self_links | The URIs of the replica instances |
7070
| replicas_instance_server_ca_certs | The CA certificates information used to connect to the replica instances via SSL |
7171
| replicas_instance_service_account_email_addresses | The service account email addresses assigned to the replica instances |
72-
| user_hosts | The list of user hosts for the database |
73-
| user_names | The list of user names for the database |
74-
| user_passwords | The list of user passwords for the database |
7572

7673
[^]: (autogen_docs_end)

modules/postgresql/main.tf

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
*/
1616

1717
locals {
18-
default_user_host = ""
18+
default_user_host = ""
19+
ip_configuration_enabled = "${length(keys(var.ip_configuration)) > 0 ? true : false}"
20+
21+
ip_configurations = {
22+
enabled = "${list(var.ip_configuration)}"
23+
disabled = "${list()}"
24+
}
1925
}
2026

2127
resource "google_sql_database_instance" "default" {
@@ -30,7 +36,7 @@ resource "google_sql_database_instance" "default" {
3036
availability_type = "${var.availability_type}"
3137
authorized_gae_applications = ["${var.authorized_gae_applications}"]
3238
backup_configuration = ["${var.backup_configuration}"]
33-
ip_configuration = ["${var.ip_configuration}"]
39+
ip_configuration = "${local.ip_configurations["${local.ip_configuration_enabled ? "enabled" : "disabled"}"]}"
3440

3541
disk_autoresize = "${var.disk_autoresize}"
3642
disk_size = "${var.disk_size}"
@@ -55,13 +61,12 @@ resource "google_sql_database_instance" "default" {
5561
}
5662
}
5763

58-
resource "google_sql_database" "databases" {
59-
count = "${length(var.databases)}"
64+
resource "google_sql_database" "default" {
65+
name = "${var.db_name}"
6066
project = "${var.project_id}"
61-
name = "${lookup(var.databases[count.index], "name")}"
62-
charset = "${lookup(var.databases[count.index], "charset", "UTF8")}"
63-
collation = "${lookup(var.databases[count.index], "collation", "en_US.UTF8")}"
6467
instance = "${google_sql_database_instance.default.name}"
68+
charset = "${var.db_charset}"
69+
collation = "${var.db_collation}"
6570
depends_on = ["google_sql_database_instance.default"]
6671
}
6772

@@ -74,12 +79,11 @@ resource "random_id" "user-password" {
7479
depends_on = ["google_sql_database_instance.default"]
7580
}
7681

77-
resource "google_sql_user" "users" {
78-
count = "${length(var.users)}"
82+
resource "google_sql_user" "default" {
83+
name = "${var.user_name}"
7984
project = "${var.project_id}"
8085
instance = "${google_sql_database_instance.default.name}"
81-
name = "${lookup(var.users[count.index], "name")}"
82-
password = "${lookup(var.users[count.index], "password", random_id.user-password.hex)}"
83-
host = "${lookup(var.users[count.index], "host", local.default_user_host)}"
86+
host = "${var.user_host}"
87+
password = "${var.user_password == "" ? random_id.user-password.hex : var.user_password}"
8488
depends_on = ["google_sql_database_instance.default"]
8589
}

modules/postgresql/outputs.tf

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -81,41 +81,6 @@ output "read_replica_instance_names" {
8181
description = "The instance names for the read replica instances"
8282
}
8383

84-
output "user_names" {
85-
value = ["${google_sql_user.users.*.name}"]
86-
description = "The list of user names for the database"
87-
}
88-
89-
output "user_passwords" {
90-
value = ["${google_sql_user.users.*.password}"]
91-
description = "The list of user passwords for the database"
92-
}
93-
94-
output "user_hosts" {
95-
value = ["${google_sql_user.users.*.host}"]
96-
description = "The list of user hosts for the database"
97-
}
98-
99-
output "database_names" {
100-
value = ["${google_sql_database.databases.*.name}"]
101-
description = "The list of database names"
102-
}
103-
104-
output "database_charsets" {
105-
value = ["${google_sql_database.databases.*.charset}"]
106-
description = "The list of database charsets"
107-
}
108-
109-
output "database_collation" {
110-
value = ["${google_sql_database.databases.*.collation}"]
111-
description = "The list of database collations"
112-
}
113-
114-
output "database_self_links" {
115-
value = ["${google_sql_database.databases.*.self_link}"]
116-
description = "The URIs of the databases"
117-
}
118-
11984
output "generated_user_password" {
12085
description = "The auto generated default user password if not input password was provided"
12186
value = "${random_id.user-password.hex}"

modules/postgresql/read_replica.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ resource "google_sql_database_instance" "replicas" {
4343
activation_policy = "${var.read_replica_activation_policy}"
4444
authorized_gae_applications = ["${var.authorized_gae_applications}"]
4545
availability_type = "${var.read_replica_availability_type}"
46-
ip_configuration = ["${var.read_replica_ip_configuration}"]
46+
ip_configuration = "${local.ip_configurations["${local.ip_configuration_enabled ? "enabled" : "disabled"}"]}"
4747

4848
crash_safe_replication = "${var.read_replica_crash_safe_replication}"
4949
disk_autoresize = "${var.read_replica_disk_autoresize}"

modules/postgresql/variables.tf

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,32 @@ variable "read_replica_ip_configuration" {
208208
default = {}
209209
}
210210

211-
// for google_sql_database
212-
variable "databases" {
213-
default = []
214-
description = "The list of databases for the instacne"
211+
variable "db_name" {
212+
description = "The name of the default database to create"
213+
default = "default"
215214
}
216215

217-
// for google_sql_user
218-
variable "users" {
219-
default = []
220-
description = "The list of users on the database"
216+
variable "db_charset" {
217+
description = "The charset for the default database"
218+
default = ""
219+
}
220+
221+
variable "db_collation" {
222+
description = "The collation for the default database. Example: 'en_US.UTF8'"
223+
default = ""
224+
}
225+
226+
variable "user_name" {
227+
description = "The name of the default user"
228+
default = "default"
229+
}
230+
231+
variable "user_host" {
232+
description = "The host for the default user"
233+
default = "%"
234+
}
235+
236+
variable "user_password" {
237+
description = "The password for the default user. If not set, a random one will be generated and available in the generated_user_password output variable."
238+
default = ""
221239
}

0 commit comments

Comments
 (0)