-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[Bug Fix] Fixes PostgreSQL collation issues #396 and #760 #1255
Conversation
Hi @jeffreyCline, Thanks for fixing this 🙂 I am going to wait review this until the other 2 PRs are merged so the diff is only the 4 file to review. |
@jeffreyCline FYI since I've merged the PostgreSQL PR I've rebased (well, merged since this was done previously) this PR so it now only contains the original changes :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @jeffreyCline
Thanks for this PR - I hope you don't mind but I've rebased/merged this since the PostgreSQL PR's been merged. I've taken a look through and left some comments inline, but this is off to a good start. If we can fix the commented issues (and the tests pass) this should be good to merge.
Thanks!
azurerm/validators.go
Outdated
return | ||
} | ||
|
||
if strings.Contains(v, "-") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO we'd be better using a Regex match here, it appears ^[A-Za-z0-9_. ]+$
should suffice for this?
@@ -372,6 +372,8 @@ func expandAzureRmPostgreSQLServerSku(d *schema.ResourceData) *postgresql.Sku { | |||
skus := d.Get("sku").([]interface{}) | |||
sku := skus[0].(map[string]interface{}) | |||
|
|||
fmt.Printf("[SKU]: %s", sku) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor can we remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DOH! Sorry, that was part of my debug code... I forgot to remove it thanks for spotting it! :)
@@ -119,8 +120,7 @@ func resourceArmPostgreSQLDatabaseRead(d *schema.ResourceData, meta interface{}) | |||
d.Set("resource_group_name", resGroup) | |||
d.Set("server_name", serverName) | |||
d.Set("charset", resp.Charset) | |||
d.Set("collation", resp.Collation) | |||
|
|||
d.Set("collation", utils.AzureRMNormalizeCollation(d.Get("collation").(string), "-", "_", -1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
providing we split this out to a separate line (to make it more readable) - we should be able to just use a string replacement directly? e.g.
collation := strings.Replace(d.Get(resp.Collation, "-", "_", -1)
d.Set("collation", collation)
note: in general we shouldn't be retrieving any properties from the schema in the Read function - since they won't exist during Import and can lead to crashes.
azurerm/utils/utils.go
Outdated
func AzureRMNormalizeCollation(input string, find string, replace string, count int) *string { | ||
collation := strings.Replace(input, find, replace, count) | ||
return &collation | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(which means we don't need this method)
I made all the requested changes, I also snuck a fix in for the charset issue... PostgreSQL had the same charset casing issues that MySQL did, except opposite.... PostgreSQL always returns uppercase, while MySQL always returns lowercase… go figure. I also added two test cases to validate the casing behavior, you can see the test results below. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor crash point we should fix (which I'll push a commit for) - but this otherwise LGTM 👍
@@ -119,7 +122,9 @@ func resourceArmPostgreSQLDatabaseRead(d *schema.ResourceData, meta interface{}) | |||
d.Set("resource_group_name", resGroup) | |||
d.Set("server_name", serverName) | |||
d.Set("charset", resp.Charset) | |||
d.Set("collation", resp.Collation) | |||
|
|||
collation := strings.Replace(*resp.Collation, "-", "_", -1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's a potential crash here, if resp.Collation
is returned nil from the API - I'll push a commit to wrap this e.g.
if collation := resp.Collation; collation != nil {
v := strings.Replace(collation, "-", "_", -1)
d.Set("collation", v)
}
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 ```
Tests pass after adding the crash fix / switching to use the
|
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! |
NOTE: This PR is based on the
u-postgreslq
branch, once theu-postgreslq
branch PR #1090 is merged intomaster
this PR will only affect the following 4 files to fix the collation issues per #396 and #760