Skip to content

Commit e1a6fc7

Browse files
eahrendmorgante
andauthored
feat: MySQL - Allow setting type for additional_users (#237)
* pushing changes to use iam type * fixing tests and changing to list map(any) * fixing lint/docs Co-authored-by: Morgante Pell <[email protected]>
1 parent f6bdeee commit e1a6fc7

File tree

10 files changed

+13
-11
lines changed

10 files changed

+13
-11
lines changed

examples/mysql-ha/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,13 @@ module "mysql" {
134134
name = "tftest2"
135135
password = "abcdefg"
136136
host = "localhost"
137+
type = "BUILT_IN"
137138
},
138139
{
139140
name = "tftest3"
140141
password = "abcdefg"
141142
host = "localhost"
143+
type = "BUILT_IN"
142144
},
143145
]
144146
}

examples/mysql-private/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ terraform destroy
8585
| Name | Description | Type | Default | Required |
8686
|------|-------------|------|---------|:--------:|
8787
| db\_name | The name of the SQL Database instance | `string` | `"example-mysql-private"` | no |
88-
| network\_name | n/a | `string` | `"mysql-privat"` | no |
88+
| network\_name | n/a | `string` | `"mysql-private"` | no |
8989
| project\_id | The project to run tests against | `string` | n/a | yes |
9090

9191
## Outputs

examples/mysql-private/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@ module "safer-mysql-db" {
6363
name = "app"
6464
password = "PaSsWoRd"
6565
host = "localhost"
66+
type = "BUILT_IN"
6667
},
6768
{
6869
name = "readonly"
6970
password = "PaSsWoRd"
7071
host = "localhost"
72+
type = "BUILT_IN"
7173
},
7274
]
7375

examples/mysql-private/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ variable "project_id" {
2020
}
2121

2222
variable "network_name" {
23-
default = "mysql-privat"
23+
default = "mysql-private"
2424
type = string
2525
}
2626

modules/mysql/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
99
|------|-------------|------|---------|:--------:|
1010
| activation\_policy | The activation policy for the master instance. Can be either `ALWAYS`, `NEVER` or `ON_DEMAND`. | `string` | `"ALWAYS"` | no |
1111
| additional\_databases | A list of databases to be created in your cluster | <pre>list(object({<br> name = string<br> charset = string<br> collation = string<br> }))</pre> | `[]` | no |
12-
| additional\_users | A list of users to be created in your cluster | <pre>list(object({<br> name = string<br> password = string<br> host = string<br> }))</pre> | `[]` | no |
12+
| additional\_users | A list of users to be created in your cluster | `list(map(any))` | `[]` | no |
1313
| availability\_type | The availability type for the master instance. Can be either `REGIONAL` or `null`. | `string` | `"REGIONAL"` | no |
1414
| backup\_configuration | The backup\_configuration settings subblock for the database setings | <pre>object({<br> binary_log_enabled = bool<br> enabled = bool<br> start_time = string<br> location = string<br> transaction_log_retention_days = string<br> retained_backups = number<br> retention_unit = string<br> })</pre> | <pre>{<br> "binary_log_enabled": false,<br> "enabled": false,<br> "location": null,<br> "retained_backups": null,<br> "retention_unit": null,<br> "start_time": null,<br> "transaction_log_retention_days": null<br>}</pre> | no |
1515
| create\_timeout | The optional timout that is applied to limit long database creates. | `string` | `"10m"` | no |

modules/mysql/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ resource "google_sql_user" "additional_users" {
187187
password = lookup(each.value, "password", random_id.user-password.hex)
188188
host = lookup(each.value, "host", var.user_host)
189189
instance = google_sql_database_instance.default.name
190+
type = lookup(each.value, "type", "BUILT_IN")
190191
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
191192
}
192193

modules/mysql/variables.tf

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,8 @@ variable "user_password" {
242242

243243
variable "additional_users" {
244244
description = "A list of users to be created in your cluster"
245-
type = list(object({
246-
name = string
247-
password = string
248-
host = string
249-
}))
250-
default = []
245+
type = list(map(any))
246+
default = []
251247
}
252248

253249
variable "create_timeout" {

modules/safer_mysql/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ mysql -S $HOME/mysql_sockets/myproject:region:instance -u user -p
166166
|------|-------------|------|---------|:--------:|
167167
| activation\_policy | The activation policy for the master instance. Can be either `ALWAYS`, `NEVER` or `ON_DEMAND`. | `string` | `"ALWAYS"` | no |
168168
| additional\_databases | A list of databases to be created in your cluster | <pre>list(object({<br> name = string<br> charset = string<br> collation = string<br> }))</pre> | `[]` | no |
169-
| additional\_users | A list of users to be created in your cluster | <pre>list(object({<br> name = string<br> password = string<br> host = string<br> }))</pre> | `[]` | no |
169+
| additional\_users | A list of users to be created in your cluster | <pre>list(object({<br> name = string<br> password = string<br> host = string<br> type = string<br> }))</pre> | `[]` | no |
170170
| assign\_public\_ip | Set to true if the master instance should also have a public IP (less secure). | `string` | `false` | no |
171171
| availability\_type | The availability type for the master instance. Can be either `REGIONAL` or `null`. | `string` | `"REGIONAL"` | no |
172172
| backup\_configuration | The backup\_configuration settings subblock for the database setings | <pre>object({<br> binary_log_enabled = bool<br> enabled = bool<br> start_time = string<br> location = string<br> transaction_log_retention_days = string<br> retained_backups = number<br> retention_unit = string<br> })</pre> | <pre>{<br> "binary_log_enabled": false,<br> "enabled": false,<br> "location": null,<br> "retained_backups": null,<br> "retention_unit": null,<br> "start_time": null,<br> "transaction_log_retention_days": null<br>}</pre> | no |

modules/safer_mysql/variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ variable "additional_users" {
234234
name = string
235235
password = string
236236
host = string
237+
type = string
237238
}))
238239
default = []
239240
}

test/fixtures/mysql-private/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ variable "project_id" {
2020
}
2121

2222
variable "network_name" {
23-
default = "mysql-privat"
23+
default = "mysql-private"
2424
type = string
2525
}

0 commit comments

Comments
 (0)