hashicorp / terraform-provider-mysql

Terraform MySQL provider – This Terraform provider is archived per our provider archiving process: https://terraform.io/docs/internals/archiving.html
https://www.terraform.io/docs/providers/mysql/
Mozilla Public License 2.0
61 stars 190 forks source link

Fix `ReadDatabase` when default collation set #36

Closed mostly-magic closed 6 years ago

mostly-magic commented 6 years ago

I discovered an issue with the ReadDatabase function when the collation is the default for the charset. While it makes the query to retrieve the default collation, it does not set the "default_character_set" and "default_collation" values on the ResourceData object.

Steps to Reproduce

  1. Load the following resource
    resource "mysql_database" "test" {
        name = "test"
        default_character_set = "utf8"
        default_collation = "utf8_bin"
    }
  2. Modify the database default collation
    ALTER DATABASE test COLLATE utf8_general_ci
  3. Attempt to apply the first resource again
    resource "mysql_database" "test" {
        name = "test"
        default_character_set = "utf8"
        default_collation = "utf8_bin"
    }

Expected Behavior

Terraform should detect the modified collation and attempt to update the database

Actual Behavior

Terraform does not recognize the modification to collation and acts as though the database is still "utf8_bin"

joestump commented 6 years ago

Bug fix with a regression test. You get a FOSS 🍪today! Thanks so much!