Skip to content

Commit

Permalink
azurerm_postgres_server - fix #2819, #5121, #5865, #6180, #6216 (#6459)
Browse files Browse the repository at this point in the history
refactor code and tests to

support for create_mode, creation_source_server_id, infrastructure_encryption_enabled,public_network_access_enabled, ssl_minimal_tls_version_enforced properties
support replicas
computed storage_mb when auto_grow_enabled is true
use booleans for toggle properties by renaming:
-- ssl_enforcement -> ssl_enforcement_enabled
-- geo_redundant_backup -> backup_geo_redundant_enabled
-- auto_grow -> auto_grow_enabled
move all properties within the storage_profile block to the top level
superseeds #6241
fixes #6216
fixes #6180
fixes #5865
fixes #5121
fixed #2819
  • Loading branch information
katbyte committed Apr 21, 2020
1 parent 50bb45e commit e969b88
Show file tree
Hide file tree
Showing 13 changed files with 796 additions and 381 deletions.
17 changes: 0 additions & 17 deletions azurerm/helpers/validate/database.go
Expand Up @@ -21,20 +21,3 @@ func MariaDatabaseCollation(i interface{}, k string) (warnings []string, errors

return warnings, errors
}

func PostgresDatabaseCollation(i interface{}, k string) (warnings []string, errors []error) {
v, ok := i.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %s to be string", k))
return
}

matched, _ := regexp.MatchString(`^[-A-Za-z0-9_. ]+$`, v)

if !matched {
errors = append(errors, fmt.Errorf("%s contains invalid characters, only alphanumeric, underscore, space or hyphen characters are supported, got %s", k, v))
return
}

return warnings, errors
}
38 changes: 0 additions & 38 deletions azurerm/helpers/validate/database_test.go

This file was deleted.

33 changes: 33 additions & 0 deletions azurerm/internal/services/postgres/parse/postgres.go
@@ -0,0 +1,33 @@
package parse

import (
"fmt"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
)

type PostgresServerServerId struct {
ResourceGroup string
Name string
}

func PostgresServerServerID(input string) (*PostgresServerServerId, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, fmt.Errorf("[ERROR] Unable to parse Postgres Server ID %q: %+v", input, err)
}

server := PostgresServerServerId{
ResourceGroup: id.ResourceGroup,
}

if server.Name, err = id.PopSegment("servers"); err != nil {
return nil, err
}

if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
}

return &server, nil
}
73 changes: 73 additions & 0 deletions azurerm/internal/services/postgres/parse/postgres_test.go
@@ -0,0 +1,73 @@
package parse

import (
"testing"
)

func TestAnalysisServicesServerId(t *testing.T) {
testData := []struct {
Name string
Input string
Expected *PostgresServerServerId
}{
{
Name: "Empty",
Input: "",
Expected: nil,
},
{
Name: "No Resource Groups Segment",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000",
Expected: nil,
},
{
Name: "No Resource Groups Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/",
Expected: nil,
},
{
Name: "Resource Group ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/",
Expected: nil,
},
{
Name: "Missing Servers Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Web/servers/",
Expected: nil,
},
{
Name: "Postgres Server ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.DBforPostgreSQL/servers/Server1",
Expected: &PostgresServerServerId{
Name: "Server1",
ResourceGroup: "resGroup1",
},
},
{
Name: "Wrong Casing",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.DBforPostgreSQL/Servers/",
Expected: nil,
},
}

for _, v := range testData {
t.Logf("[DEBUG] Testing %q", v.Name)

actual, err := PostgresServerServerID(v.Input)
if err != nil {
if v.Expected == nil {
continue
}

t.Fatalf("Expected a value but got an error: %s", err)
}

if actual.Name != v.Expected.Name {
t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name)
}

if actual.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup)
}
}
}
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/postgres/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
Expand Down Expand Up @@ -43,7 +44,7 @@ func resourceArmPostgreSQLConfiguration() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: ValidatePSQLServerName,
ValidateFunc: validate.PostgresServerServerName,
},

"value": {
Expand Down
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/postgres/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
Expand Down Expand Up @@ -47,7 +47,7 @@ func resourceArmPostgreSQLDatabase() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: ValidatePSQLServerName,
ValidateFunc: validate.PostgresServerServerName,
},

"charset": {
Expand Down
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/postgres/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
Expand Down Expand Up @@ -45,7 +46,7 @@ func resourceArmPostgreSQLFirewallRule() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: ValidatePSQLServerName,
ValidateFunc: validate.PostgresServerServerName,
},

"start_ip_address": {
Expand Down

0 comments on commit e969b88

Please sign in to comment.