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

Upgrade postgresql server API version from 2022-03-08-preview to 2022-12-01 #20073

Merged
merged 4 commits into from
Jan 20, 2023
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
2 changes: 1 addition & 1 deletion internal/services/postgres/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
flexibleserverfirewallrules "github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2021-06-01/firewallrules"
"github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2021-06-01/serverrestart"
flexibleserveradministrators "github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2022-03-08-preview/administrators"
flexibleservers "github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2022-03-08-preview/servers"
flexibleservers "github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2022-12-01/servers"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2022-03-08-preview/servers"
"github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2022-12-01/servers"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
Expand Down
31 changes: 21 additions & 10 deletions internal/services/postgres/postgresql_flexible_server_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2021-06-01/serverrestart"
"github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2022-03-08-preview/servers"
"github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2022-12-01/servers"
"github.com/hashicorp/go-azure-sdk/resource-manager/privatedns/2018-09-01/privatezones"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down Expand Up @@ -353,7 +353,8 @@ func resourcePostgresqlFlexibleServerCreate(d *pluginsdk.ResourceData, meta inte
// so we create it with `password_auth_enabled` set to `true`, then set it to `false` in an additional update.
if authRaw, ok := d.GetOk("authentication"); ok {
authConfig := expandFlexibleServerAuthConfig(authRaw.([]interface{}))
authConfig.PasswordAuthEnabled = utils.Bool(true)
passwordAuthEnabled := servers.PasswordAuthEnumEnabled
authConfig.PasswordAuth = &passwordAuthEnabled
parameters.Properties.AuthConfig = authConfig
}

Expand All @@ -365,7 +366,7 @@ func resourcePostgresqlFlexibleServerCreate(d *pluginsdk.ResourceData, meta inte
updateProperties := servers.ServerPropertiesForUpdate{}
if authRaw, ok := d.GetOk("authentication"); ok {
authConfig := expandFlexibleServerAuthConfig(authRaw.([]interface{}))
if !*authConfig.PasswordAuthEnabled {
if authConfig != nil && authConfig.PasswordAuth != nil && *authConfig.PasswordAuth == servers.PasswordAuthEnumDisabled {
requireAdditionalUpdate = true
updateProperties.AuthConfig = authConfig
}
Expand Down Expand Up @@ -780,10 +781,20 @@ func expandFlexibleServerAuthConfig(authRaw []interface{}) *servers.AuthConfig {
}

authConfigs := authRaw[0].(map[string]interface{})
out := servers.AuthConfig{
ActiveDirectoryAuthEnabled: utils.Bool(authConfigs["active_directory_auth_enabled"].(bool)),
PasswordAuthEnabled: utils.Bool(authConfigs["password_auth_enabled"].(bool)),
out := servers.AuthConfig{}

activeDirectoryAuthEnabled := servers.ActiveDirectoryAuthEnumDisabled
if authConfigs["active_directory_auth_enabled"].(bool) {
activeDirectoryAuthEnabled = servers.ActiveDirectoryAuthEnumEnabled
}
out.ActiveDirectoryAuth = &activeDirectoryAuthEnabled

passwordAuthEnabled := servers.PasswordAuthEnumDisabled
if authConfigs["password_auth_enabled"].(bool) {
passwordAuthEnabled = servers.PasswordAuthEnumEnabled
}
out.PasswordAuth = &passwordAuthEnabled

if tenantId, ok := authConfigs["tenant_id"].(string); ok {
out.TenantId = &tenantId
}
Expand All @@ -799,15 +810,15 @@ func flattenFlexibleServerAuthConfig(ac *servers.AuthConfig) interface{} {
}

aadEnabled := false
if ac.ActiveDirectoryAuthEnabled != nil {
aadEnabled = *ac.ActiveDirectoryAuthEnabled
if ac.ActiveDirectoryAuth != nil {
aadEnabled = *ac.ActiveDirectoryAuth == servers.ActiveDirectoryAuthEnumEnabled
}
out["active_directory_auth_enabled"] = aadEnabled

// It is by design if PasswordAuthEnabled is not returned or undefined, we consider it as true.
pwdEnabled := true
if ac.PasswordAuthEnabled != nil {
pwdEnabled = *ac.PasswordAuthEnabled
if ac.PasswordAuth != nil {
pwdEnabled = *ac.PasswordAuth == servers.PasswordAuthEnumEnabled
}
out["password_auth_enabled"] = pwdEnabled

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

"github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2022-03-08-preview/servers"
"github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2022-12-01/servers"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2021-06-01/databas
github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2021-06-01/firewallrules
github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2021-06-01/serverrestart
github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2022-03-08-preview/administrators
github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2022-03-08-preview/servers
github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2022-12-01/servers
github.com/hashicorp/go-azure-sdk/resource-manager/powerbidedicated/2021-01-01/capacities
github.com/hashicorp/go-azure-sdk/resource-manager/privatedns/2018-09-01/privatezones
github.com/hashicorp/go-azure-sdk/resource-manager/privatedns/2018-09-01/recordsets
Expand Down