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

New Resources: azurerm_postgresql_* #210

Merged
merged 25 commits into from
Sep 5, 2017
Merged

New Resources: azurerm_postgresql_* #210

merged 25 commits into from
Sep 5, 2017

Conversation

tombuildsstuff
Copy link
Contributor

@tombuildsstuff tombuildsstuff commented Aug 3, 2017

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

Copy link
Contributor Author

@tombuildsstuff tombuildsstuff left a 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 {
Copy link
Contributor Author

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)
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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)
Copy link
Contributor Author

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 {
Copy link
Contributor Author

@tombuildsstuff tombuildsstuff Aug 3, 2017

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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configration -> Configuration

Copy link
Contributor Author

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.
Copy link
Contributor Author

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.
Copy link
Contributor Author

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"
}
Copy link
Contributor Author

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"
}
Copy link
Contributor Author

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

@tombuildsstuff tombuildsstuff changed the title [WIP] PostgreSQL Resources PostgreSQL Resources Aug 4, 2017
"value": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

judging by the API Schema - I think we should be able to get away with a string for all of these values:
screen shot 2017-08-04 at 11 54 08

@tombuildsstuff tombuildsstuff changed the title PostgreSQL Resources [WIP] PostgreSQL Resources Aug 4, 2017
@tombuildsstuff tombuildsstuff changed the title PostgreSQL Resources [WIP] PostgreSQL Resources Aug 4, 2017
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "West US"
Copy link
Contributor Author

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

@tombuildsstuff tombuildsstuff changed the title [WIP] PostgreSQL Resources New Resources: azurerm_postgresql_* Aug 20, 2017
@tombuildsstuff
Copy link
Contributor Author

Tests pass:

screen shot 2017-08-21 at 09 51 48

Copy link
Member

@radeksimko radeksimko left a 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.")
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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. 😉

Copy link
Contributor Author

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.")
Copy link
Member

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),
Copy link
Member

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.

Copy link
Contributor Author

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"),
Copy link
Member

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?

Copy link
Contributor Author

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 {
Copy link
Member

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),
Copy link
Member

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?

Copy link
Contributor Author

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),
Copy link
Member

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?

Copy link
Contributor Author

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),
Copy link
Member

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?

Copy link
Contributor Author

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))
Copy link
Member

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?".

Copy link
Contributor Author

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" {
...
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@radeksimko
Copy link
Member

radeksimko commented Aug 21, 2017

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.

I understand the situation, but having a separate PR for each and another one for vendor changes would make the review a much more enjoyable process 😅

That's just for future reference.

Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tombuildsstuff
Copy link
Contributor Author

Tests pass:
screen shot 2017-09-05 at 16 06 06

@tombuildsstuff tombuildsstuff merged commit 075b671 into master Sep 5, 2017
@tombuildsstuff tombuildsstuff deleted the postgresql branch September 5, 2017 15:08
tombuildsstuff added a commit that referenced this pull request Sep 5, 2017
@ghost
Copy link

ghost commented Apr 1, 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 Apr 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Azure Database for PostgreSQL
2 participants