Skip to content

Commit

Permalink
feat: MySQL - Allow setting type for additional_users (#237)
Browse files Browse the repository at this point in the history
* pushing changes to use iam type

* fixing tests and changing to list map(any)

* fixing lint/docs

Co-authored-by: Morgante Pell <morgantep@google.com>
  • Loading branch information
eahrend and morgante committed Oct 5, 2021
1 parent f6bdeee commit e1a6fc7
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 11 deletions.
2 changes: 2 additions & 0 deletions examples/mysql-ha/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,13 @@ module "mysql" {
name = "tftest2"
password = "abcdefg"
host = "localhost"
type = "BUILT_IN"
},
{
name = "tftest3"
password = "abcdefg"
host = "localhost"
type = "BUILT_IN"
},
]
}
2 changes: 1 addition & 1 deletion examples/mysql-private/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ terraform destroy
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| db\_name | The name of the SQL Database instance | `string` | `"example-mysql-private"` | no |
| network\_name | n/a | `string` | `"mysql-privat"` | no |
| network\_name | n/a | `string` | `"mysql-private"` | no |
| project\_id | The project to run tests against | `string` | n/a | yes |

## Outputs
Expand Down
2 changes: 2 additions & 0 deletions examples/mysql-private/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ module "safer-mysql-db" {
name = "app"
password = "PaSsWoRd"
host = "localhost"
type = "BUILT_IN"
},
{
name = "readonly"
password = "PaSsWoRd"
host = "localhost"
type = "BUILT_IN"
},
]

Expand Down
2 changes: 1 addition & 1 deletion examples/mysql-private/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ variable "project_id" {
}

variable "network_name" {
default = "mysql-privat"
default = "mysql-private"
type = string
}

Expand Down
2 changes: 1 addition & 1 deletion modules/mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
|------|-------------|------|---------|:--------:|
| activation\_policy | The activation policy for the master instance. Can be either `ALWAYS`, `NEVER` or `ON_DEMAND`. | `string` | `"ALWAYS"` | no |
| 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 |
| 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 |
| additional\_users | A list of users to be created in your cluster | `list(map(any))` | `[]` | no |
| availability\_type | The availability type for the master instance. Can be either `REGIONAL` or `null`. | `string` | `"REGIONAL"` | no |
| 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 |
| create\_timeout | The optional timout that is applied to limit long database creates. | `string` | `"10m"` | no |
Expand Down
1 change: 1 addition & 0 deletions modules/mysql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ resource "google_sql_user" "additional_users" {
password = lookup(each.value, "password", random_id.user-password.hex)
host = lookup(each.value, "host", var.user_host)
instance = google_sql_database_instance.default.name
type = lookup(each.value, "type", "BUILT_IN")
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
}

Expand Down
8 changes: 2 additions & 6 deletions modules/mysql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,8 @@ variable "user_password" {

variable "additional_users" {
description = "A list of users to be created in your cluster"
type = list(object({
name = string
password = string
host = string
}))
default = []
type = list(map(any))
default = []
}

variable "create_timeout" {
Expand Down
2 changes: 1 addition & 1 deletion modules/safer_mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ mysql -S $HOME/mysql_sockets/myproject:region:instance -u user -p
|------|-------------|------|---------|:--------:|
| activation\_policy | The activation policy for the master instance. Can be either `ALWAYS`, `NEVER` or `ON_DEMAND`. | `string` | `"ALWAYS"` | no |
| 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 |
| 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 |
| 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 |
| assign\_public\_ip | Set to true if the master instance should also have a public IP (less secure). | `string` | `false` | no |
| availability\_type | The availability type for the master instance. Can be either `REGIONAL` or `null`. | `string` | `"REGIONAL"` | no |
| 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 |
Expand Down
1 change: 1 addition & 0 deletions modules/safer_mysql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ variable "additional_users" {
name = string
password = string
host = string
type = string
}))
default = []
}
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/mysql-private/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ variable "project_id" {
}

variable "network_name" {
default = "mysql-privat"
default = "mysql-private"
type = string
}

0 comments on commit e1a6fc7

Please sign in to comment.