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 resource azurerm_postgresql_server_key - Add CMK support #8126

Merged
merged 18 commits into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions azurerm/internal/services/postgres/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Client struct {
DatabasesClient *postgresql.DatabasesClient
FirewallRulesClient *postgresql.FirewallRulesClient
ServersClient *postgresql.ServersClient
ServerKeysClient *postgresql.ServerKeysClient
ServerSecurityAlertPoliciesClient *postgresql.ServerSecurityAlertPoliciesClient
VirtualNetworkRulesClient *postgresql.VirtualNetworkRulesClient
ServerAdministratorsClient *postgresql.ServerAdministratorsClient
Expand All @@ -28,6 +29,9 @@ func NewClient(o *common.ClientOptions) *Client {
serversClient := postgresql.NewServersClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&serversClient.Client, o.ResourceManagerAuthorizer)

serverKeysClient := postgresql.NewServerKeysClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&serverKeysClient.Client, o.ResourceManagerAuthorizer)

serverSecurityAlertPoliciesClient := postgresql.NewServerSecurityAlertPoliciesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&serverSecurityAlertPoliciesClient.Client, o.ResourceManagerAuthorizer)

Expand All @@ -42,6 +46,7 @@ func NewClient(o *common.ClientOptions) *Client {
DatabasesClient: &databasesClient,
FirewallRulesClient: &firewallRulesClient,
ServersClient: &serversClient,
ServerKeysClient: &serverKeysClient,
ServerSecurityAlertPoliciesClient: &serverSecurityAlertPoliciesClient,
VirtualNetworkRulesClient: &virtualNetworkRulesClient,
ServerAdministratorsClient: &serverAdministratorsClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
)

type PostgresServerServerId struct {
type PostgreSQLServerId struct {
ResourceGroup string
Name string
}

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

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

Expand Down
38 changes: 38 additions & 0 deletions azurerm/internal/services/postgres/parse/postgresql_server_key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package parse

import (
"fmt"

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

type PostgreSQLServerKeyId struct {
Name string
ServerName string
ResourceGroup string
}

func PostgreSQLServerKeyID(input string) (*PostgreSQLServerKeyId, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, fmt.Errorf("unable to parse Postgres Server Key ID %q: %+v", input, err)
}

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

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

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

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

return &server, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package parse

import "testing"

func TestPostgreSQLServerKeyID(t *testing.T) {
testData := []struct {
Name string
Input string
Expected *PostgreSQLServerKeyId
}{
{
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.DBforPostgreSQL/servers/",
Expected: nil,
},
{
Name: "Postgres Server ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.DBforPostgreSQL/servers/Server1/",
Expected: nil,
},
{
Name: "Missing Key Name",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.DBforPostgreSQL/servers/Server1/keys/",
Expected: nil,
},
{
Name: "PostgreSQL Server Key ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.DBforPostgreSQL/servers/Server1/keys/key1",
Expected: &PostgreSQLServerKeyId{
Name: "key1",
ServerName: "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 := PostgreSQLServerKeyID(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.ServerName != v.Expected.ServerName {
t.Fatalf("Expected %q but got %q for Name", v.Expected.ServerName, actual.ServerName)
}

if actual.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ func TestAnalysisServicesServerId(t *testing.T) {
testData := []struct {
Name string
Input string
Expected *PostgresServerServerId
Expected *PostgreSQLServerId
}{
{
Name: "Empty",
Expand Down Expand Up @@ -38,7 +38,7 @@ func TestAnalysisServicesServerId(t *testing.T) {
{
Name: "Postgres Server ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.DBforPostgreSQL/servers/Server1",
Expected: &PostgresServerServerId{
Expected: &PostgreSQLServerId{
Name: "Server1",
ResourceGroup: "resGroup1",
},
Expand All @@ -53,7 +53,7 @@ func TestAnalysisServicesServerId(t *testing.T) {
for _, v := range testData {
t.Logf("[DEBUG] Testing %q", v.Name)

actual, err := PostgresServerServerID(v.Input)
actual, err := PostgreSQLServerID(v.Input)
if err != nil {
if v.Expected == nil {
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func resourceArmPostgreSQLConfiguration() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.PostgresServerServerName,
ValidateFunc: validate.PostgreSQLServerName,
},

"value": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func resourceArmPostgreSQLDatabase() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.PostgresServerServerName,
ValidateFunc: validate.PostgreSQLServerName,
},

"charset": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func resourceArmPostgreSQLFirewallRule() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.PostgresServerServerName,
ValidateFunc: validate.PostgreSQLServerName,
},

"start_ip_address": {
Expand Down
Loading