-
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
New Resources: azurerm_postgresql_*
#210
Conversation
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.
picked up a few things after a fresh pair of 👀
|
||
resp, err := client.Get(resGroup, serverName, name) | ||
if err != nil { | ||
if resp.StatusCode == http.StatusNotFound { |
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.
this can be converted too:
if responseWasNotFound(resp) {
|
||
resp, err := client.Get(resourceGroup, serverName, name) | ||
if err != nil { | ||
return fmt.Errorf("Bad: Get on postgresqlConfigurationsClient: %s", err) |
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.
this should become %+v
|
||
resp, err := client.Get(resGroup, serverName, name) | ||
if err != nil { | ||
if resp.StatusCode == http.StatusNotFound { |
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.
this can be updated too:
if responseWasNotFound(resp) {
|
||
resp, err := client.Get(resourceGroup, serverName, name) | ||
if err != nil { | ||
return fmt.Errorf("Bad: Get on postgresqlDatabasesClient: %s", err) |
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.
this can be updated to %+v
|
||
resp, err := client.Get(resourceGroup, serverName, name) | ||
|
||
if err != nil { |
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.
this can be cleaned up, ala the other resources done
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) Specifies the name of the PostgreSQL Configration, which needs [to be a valid PostgreSQL configuration name](TODO). Changing this forces a new resource to be created. |
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.
Configration
-> Configuration
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.
this link should be https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
|
||
* `charset` - (Required) Specifies the Charset for the PostgreSQL Database. Changing this forces a new resource to be created. | ||
|
||
* `collation` - (Required) Specifies the Collation for the PostgreSQL Database. Changing this forces a new resource to be created. |
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.
this wants a link to the valid PostgreSQL collations
|
||
* `resource_group_name` - (Required) The name of the resource group in which the PostgreSQL Server exists. Changing this forces a new resource to be created. | ||
|
||
* `charset` - (Required) Specifies the Charset for the PostgreSQL Database. Changing this forces a new resource to be created. |
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.
this wants a link to the valid PostgreSQL charsets
version = "9.5" | ||
storage_mb = "51200" | ||
ssl_enforcement = "Enabled" | ||
} |
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.
thinking about it we could probably truncate these down
version = "9.5" | ||
storage_mb = "51200" | ||
ssl_enforcement = "Enabled" | ||
} |
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.
thinking about it we could probably truncate these down
a469dbb
to
2519988
Compare
"value": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, |
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.
0362e93
to
34203e3
Compare
34203e3
to
cb0806e
Compare
return fmt.Sprintf(` | ||
resource "azurerm_resource_group" "test" { | ||
name = "acctestRG-%d" | ||
location = "West US" |
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.
need to update this to pass in the location
azurerm_postgresql_*
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.
I left you comments there - many are more generic and apply to most resources - e.g. state checks in tests, detailed log messages and "name as ID" in Create
functions.
Let me know what you think.
func resourceArmPostgreSQLConfigurationCreateUpdate(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).postgresqlConfigurationsClient | ||
|
||
log.Printf("[INFO] preparing arguments for AzureRM PostgreSQL Configuration creation.") |
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.
Nit: This would've been more useful on line 65 with contents of properties
.
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.
if you've got TF_LOG
set to a value - you'll be seeing the http request/response anyway - so I don't think this'll add any value?
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.
Good point, they should be the same, as long as you trust the SDK does the job. 🤷♂️
I just think the value of such log message is equal to "Update function of resource X reached", which is something I almost never had to debug. I remember debugging wrong/missing/additional parameters sent to the API many times though.
Admittedly I don't remember ever debugging discrepancy between SDK and actual API call (at least in AWS), so up to you - as I said it's a nitpick - so feel free to ignore. 😉
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.
Admittedly I don't remember ever debugging discrepancy between SDK and actual API call (at least in AWS), so up to you - as I said it's a nitpick - so feel free to ignore. 😉
This should either be caught when integrating the SDK (which should now be being picked up by the SDK team) - or whilst doing new development; so I don't think that's a common scenario. As such I'm going to leave this for the moment, that said - totally happy to add this in the future if we see this is causing problems :)
func resourceArmPostgreSQLDatabaseCreate(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).postgresqlDatabasesClient | ||
|
||
log.Printf("[INFO] preparing arguments for AzureRM PostgreSQL Database creation.") |
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.
Nit: Similar to my other comment above.
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureRMPostgreSQLDatabaseExists(resourceName), |
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.
Could we add more checks here? At least state checks via resource.TestCheckResourceAttr*
would be nice.
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.
Done.
Config: serverOnlyConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
// "delete" resets back to the default value | ||
testCheckAzureRMPostgreSQLConfigurationValueReset(ri, "deadlock_timeout"), |
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.
Is there any particular reason you decided to implement your own check function instead of using the helper library?
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.
Because we're not checking the local state here, but the remote API (given there's no delete available and we're resetting this back to the original value)
if err != nil { | ||
return err | ||
} | ||
if read.ID == nil { |
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.
😱 Is this really checking for API (mis)behaviour?
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureRMPostgreSQLServerExists(resourceName), |
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.
As mentioned elsewhere - can we add some state checks here?
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.
Done
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureRMPostgreSQLServerExists(resourceName), |
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.
As mentioned elsewhere - can we add some state checks here?
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.
Done
{ | ||
Config: updatedConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureRMPostgreSQLServerExists(resourceName), |
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.
As mentioned elsewhere - can we add some state checks here?
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.
Done
return func(i interface{}, k string) (s []string, es []error) { | ||
v, ok := i.(int) | ||
if !ok { | ||
es = append(es, fmt.Errorf("expected type of %s to be int", k)) |
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.
Nitpick: It might be better to use %q
as quotes can make it clearer it's a field name, not just another word. e.g. as a user if I saw expected type of key to be int
I'd be tempted to think "which key?".
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.
Good point. Updated.
} | ||
|
||
resource "azurerm_postgresql_server" "test" { | ||
... |
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.
Totally minor, but I suggest using an indented # ...
for "etc" placeholders, since it co-operates better with the syntax highlighting.
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.
Updated
I understand the situation, but having a separate PR for each and another one for That's just for future reference. |
59f3d67
to
e9b1264
Compare
02ef31a
to
f66404e
Compare
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.
https://github.com/terraform-providers/terraform-provider-azurerm/pull/210/files#diff-f7626e2a1dbd5eb89c5d808ed1e82770R257
^ that’s my only minor concern left, but not really a blocker
a25d57b
to
d9ba935
Compare
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! |
Adds the following resources:
azurerm_postgresql_configuration
azurerm_postgresql_database
azurerm_postgresql_firewall_rule
azurerm_postgresql_server
Each of these resources builds on one another - so unfortunately due to the way I started writing this it's ended up as one big PR - but I can split it out if needed.
Fixes #158