Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure DB for PostgreSQL collation changes automatically. #396

Closed
piotrgo opened this issue Oct 4, 2017 · 6 comments
Closed

Azure DB for PostgreSQL collation changes automatically. #396

piotrgo opened this issue Oct 4, 2017 · 6 comments
Milestone

Comments

@piotrgo
Copy link
Contributor

piotrgo commented Oct 4, 2017

Hi,

We've run into an issue with newly added Azure DB for Postgres. I am not sure whether it's just a misinformation in documentation, or an actual problem with Terraform implementing Azure DB.
DB's collation changes from en_US to en-US and Terraform want's to change it.

Terraform Version

0.10.5

Affected Resource(s)

azurerm_postgresql_database

Terraform Configuration Files

resource "azurerm_postgresql_database" "pgsql_db" {
  name                             = "${replace(var.pgsql_srv_name, "-", "_")}_db"
  resource_group_name = "${var.resource_group_name}"
  server_name                 = "${azurerm_postgresql_server.pgsql_srv.name}"
  charset                          = "${var.charset}"
  collation                        = "en_US"
}

Initial Plan Output

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  + module.pgsql-artifactory.azurerm_postgresql_database.pgsql_db
      id:                             <computed>
      charset:                        "UTF8"
      collation:                      "en_US"
      name:                           "dbname"
      resource_group_name:            "rgname"
      server_name:                    "srvname"

Plan: 1 to add, 0 to change, 0 to destroy.

------------------------------------------------------------------------

Apply runs without any problems, immediately after, another plan results with:

Terraform will perform the following actions:

-/+ module.pgsql-artifactory.azurerm_postgresql_database.pgsql_db (new resource required)
      id:                             "/subscriptions/ID" => <computed> (forces new resource)
      charset:                        "UTF8" => "UTF8"
      collation:                      "en-US" => "en_US" (forces new resource)
      name:                           "dbname" => "dbname"
      resource_group_name:"rgname" => "rgname"
      server_name:                "srvname" => "srvname"

Plan: 1 to add, 0 to change, 1 to destroy.

------------------------------------------------------------------------


Expected Behavior

DB should be created with specified collation as per PGSQL documentation (underscore in collation type) and no further changes should be planned by Terraform

Actual Behavior

DB is being created fine, but on subsequent plan it is being marked for a change from en_US to en-US

Steps to Reproduce

Follow an example from the documentation for setting up Azure DB for PostgreSQL and Azure PostgreSQL DB with collation type set as per PGSQL documentation.

@tombuildsstuff
Copy link
Member

Hey @piotrgo

Thanks for opening this issue :)

In the example you've provided above, we're submitting the value en_US through to Azure and then getting en-US back - out of interest do you see the same issue when using the value en-US for Collation? Taking a look at our test suite - we're making use of the collation English_United States.1252 - as such I'd suggest this is a documentation issue

Thanks

@piotrgo
Copy link
Contributor Author

piotrgo commented Oct 11, 2017

I've run a test, and it behaves as expected when I specify en-US from the start. I did some searching, and Microsoft uses different notation that uses a hyphen instead of underscore.

Do you think it's worth updating the docs in #418?

Cheers

@tombuildsstuff
Copy link
Member

@piotrgo that's good to hear, thanks for looking into this further - it's definitely worth updating the docs via #418 and I'll close this issue now that's merged. Thanks!

@ghost
Copy link

ghost commented Jan 26, 2018

When en-US is used now, Azure fails the deployment due to an invalid collation. Using en_US works, but it means that Terraform sees a change and deploys the PGSQL infrastructure on every run, destroying any existing data :(

WodansSon added a commit that referenced this issue May 18, 2018
tombuildsstuff pushed a commit that referenced this issue May 24, 2018
* Update PostgreSQL to GA 2017-12-01 API

* Added TestCheckResourceAttr for create_mode to tests

* Upgraded Go SDK to v16.2.1 to match Master Branch

* Replaced 2017-04-30-preview postgreSQL API  with 2017-12-01 GA API

* Removed CreateMode from schema, updated tests and documentation to match

* Removed createmode validation from tests

* Removed createmode from two hcl sections

* [Bug Fix] Fixes issues #396 and #760

* Updated validators to match master branch

* Fixing a merge conflict

* Removed debug fmt statement

* Removed AzureRMNormalizeCollation util function

* Updated replace methiod

* Updated validator to use regex instead of string contains

* Made charset case insensitive and added two test cases

* Switching to use the fields within `.Properties` to match the API

Also working around a potential crash. Tests pass:

```
$ acctests azurerm TestAccAzureRMPostgreSQLDatabase_
=== RUN   TestAccAzureRMPostgreSQLDatabase_importBasic
--- PASS: TestAccAzureRMPostgreSQLDatabase_importBasic (402.40s)
=== RUN   TestAccAzureRMPostgreSQLDatabase_basic
--- PASS: TestAccAzureRMPostgreSQLDatabase_basic (486.39s)
=== RUN   TestAccAzureRMPostgreSQLDatabase_charsetLowercase
--- PASS: TestAccAzureRMPostgreSQLDatabase_charsetLowercase (424.71s)
=== RUN   TestAccAzureRMPostgreSQLDatabase_charsetMixedcase
--- PASS: TestAccAzureRMPostgreSQLDatabase_charsetMixedcase (424.97s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	1738.507s
```
@katbyte katbyte added this to the 1.6.0 milestone May 25, 2018
@katbyte
Copy link
Collaborator

katbyte commented May 25, 2018

Hey @piotrgo,

Just wanted to let you know we have released v1.6.0 of the provider hopefully fixing this issue 🙂

@ghost
Copy link

ghost commented Mar 31, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants