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

provider: support for the postgresql_flexible_server.restart_server_on_configuration_value_change property #23811

Merged
merged 6 commits into from
Feb 14, 2024
3 changes: 3 additions & 0 deletions internal/features/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,8 @@ func Default() UserFeatures {
Subscription: SubscriptionFeatures{
PreventCancellationOnDestroy: false,
},
PostgresqlFlexibleServer: PostgresqlFlexibleServerFeatures{
RestartServerOnConfigurationValueChange: true,
},
}
}
29 changes: 17 additions & 12 deletions internal/features/user_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
package features

type UserFeatures struct {
ApiManagement ApiManagementFeatures
AppConfiguration AppConfigurationFeatures
ApplicationInsights ApplicationInsightFeatures
CognitiveAccount CognitiveAccountFeatures
VirtualMachine VirtualMachineFeatures
VirtualMachineScaleSet VirtualMachineScaleSetFeatures
KeyVault KeyVaultFeatures
TemplateDeployment TemplateDeploymentFeatures
LogAnalyticsWorkspace LogAnalyticsWorkspaceFeatures
ResourceGroup ResourceGroupFeatures
ManagedDisk ManagedDiskFeatures
Subscription SubscriptionFeatures
ApiManagement ApiManagementFeatures
AppConfiguration AppConfigurationFeatures
ApplicationInsights ApplicationInsightFeatures
CognitiveAccount CognitiveAccountFeatures
VirtualMachine VirtualMachineFeatures
VirtualMachineScaleSet VirtualMachineScaleSetFeatures
KeyVault KeyVaultFeatures
TemplateDeployment TemplateDeploymentFeatures
LogAnalyticsWorkspace LogAnalyticsWorkspaceFeatures
ResourceGroup ResourceGroupFeatures
ManagedDisk ManagedDiskFeatures
Subscription SubscriptionFeatures
PostgresqlFlexibleServer PostgresqlFlexibleServerFeatures
}

type CognitiveAccountFeatures struct {
Expand Down Expand Up @@ -79,3 +80,7 @@ type AppConfigurationFeatures struct {
type SubscriptionFeatures struct {
PreventCancellationOnDestroy bool
}

type PostgresqlFlexibleServerFeatures struct {
RestartServerOnConfigurationValueChange bool
}
25 changes: 25 additions & 0 deletions internal/provider/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,21 @@ func schemaFeatures(supportLegacyTestSuite bool) *pluginsdk.Schema {
},
},
},

"postgresql_flexible_server": {
Type: pluginsdk.TypeList,
Optional: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"restart_server_on_configuration_value_change": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: true,
},
},
},
},
}

// this is a temporary hack to enable us to gradually add provider blocks to test configurations
Expand Down Expand Up @@ -481,5 +496,15 @@ func expandFeatures(input []interface{}) features.UserFeatures {
}
}

if raw, ok := val["postgresql_flexible_server"]; ok {
items := raw.([]interface{})
if len(items) > 0 {
subscriptionRaw := items[0].(map[string]interface{})
if v, ok := subscriptionRaw["restart_server_on_configuration_value_change"]; ok {
featuresMap.PostgresqlFlexibleServer.RestartServerOnConfigurationValueChange = v.(bool)
}
}
}

return featuresMap
}
86 changes: 85 additions & 1 deletion internal/provider/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func TestExpandFeatures(t *testing.T) {
Subscription: features.SubscriptionFeatures{
PreventCancellationOnDestroy: false,
},
PostgresqlFlexibleServer: features.PostgresqlFlexibleServerFeatures{
RestartServerOnConfigurationValueChange: true,
},
},
},
{
Expand Down Expand Up @@ -122,6 +125,11 @@ func TestExpandFeatures(t *testing.T) {
"expand_without_downtime": true,
},
},
"postgresql_flexible_server": []interface{}{
map[string]interface{}{
"restart_server_on_configuration_value_change": true,
},
},
"resource_group": []interface{}{
map[string]interface{}{
"prevent_deletion_if_contains_resources": true,
Expand Down Expand Up @@ -204,6 +212,9 @@ func TestExpandFeatures(t *testing.T) {
ForceDelete: true,
ScaleToZeroOnDelete: true,
},
PostgresqlFlexibleServer: features.PostgresqlFlexibleServerFeatures{
RestartServerOnConfigurationValueChange: true,
},
},
},
{
Expand Down Expand Up @@ -255,6 +266,11 @@ func TestExpandFeatures(t *testing.T) {
"expand_without_downtime": false,
},
},
"postgresql_flexible_server": []interface{}{
map[string]interface{}{
"restart_server_on_configuration_value_change": false,
},
},
"resource_group": []interface{}{
map[string]interface{}{
"prevent_deletion_if_contains_resources": false,
Expand Down Expand Up @@ -337,6 +353,9 @@ func TestExpandFeatures(t *testing.T) {
RollInstancesWhenRequired: false,
ScaleToZeroOnDelete: false,
},
PostgresqlFlexibleServer: features.PostgresqlFlexibleServerFeatures{
RestartServerOnConfigurationValueChange: false,
},
},
},
}
Expand Down Expand Up @@ -1237,7 +1256,7 @@ func TestExpandFeaturesSubscription(t *testing.T) {
},
},
{
Name: "No Downtime Resize Enabled",
Name: "Subscription cancellation on destroy is Disabled",
igorkliushnikov marked this conversation as resolved.
Show resolved Hide resolved
Input: []interface{}{
map[string]interface{}{
"subscription": []interface{}{
Expand All @@ -1263,3 +1282,68 @@ func TestExpandFeaturesSubscription(t *testing.T) {
}
}
}

func TestExpandFeaturesPosgresqlFlexibleServer(t *testing.T) {
testData := []struct {
Name string
Input []interface{}
EnvVars map[string]interface{}
Expected features.UserFeatures
}{
{
Name: "Empty Block",
Input: []interface{}{
map[string]interface{}{
"postgresql_flexible_server": []interface{}{},
},
},
Expected: features.UserFeatures{
PostgresqlFlexibleServer: features.PostgresqlFlexibleServerFeatures{
RestartServerOnConfigurationValueChange: true,
},
},
},
{
Name: "Postgresql Flexible Server restarts on configuration change is Enabled",
Input: []interface{}{
map[string]interface{}{
"postgresql_flexible_server": []interface{}{
map[string]interface{}{
"restart_server_on_configuration_value_change": true,
},
},
},
},
Expected: features.UserFeatures{
PostgresqlFlexibleServer: features.PostgresqlFlexibleServerFeatures{
RestartServerOnConfigurationValueChange: true,
},
},
},
{
Name: "Postgresql Flexible Server restarts on configuration change is Disabled",
Input: []interface{}{
map[string]interface{}{
"postgresql_flexible_server": []interface{}{
map[string]interface{}{
"restart_server_on_configuration_value_change": false,
},
},
},
},
Expected: features.UserFeatures{
PostgresqlFlexibleServer: features.PostgresqlFlexibleServerFeatures{
RestartServerOnConfigurationValueChange: false,
},
},
},
}

for _, testCase := range testData {
t.Logf("[DEBUG] Test Case: %q", testCase.Name)
result := expandFeatures(testCase.Input)
if !reflect.DeepEqual(result.Subscription, testCase.Expected.Subscription) {
t.Fatalf("Expected %+v but got %+v", result.Subscription, testCase.Expected.Subscription)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ func resourceFlexibleServerConfigurationUpdate(d *pluginsdk.ResourceData, meta i

if isDynamicConfig := props.IsDynamicConfig; isDynamicConfig != nil && !*isDynamicConfig {
if isReadOnly := props.IsReadOnly; isReadOnly != nil && !*isReadOnly {
restartClient := meta.(*clients.Client).Postgres.ServerRestartClient
restartServerId := serverrestart.NewFlexibleServerID(id.SubscriptionId, id.ResourceGroupName, id.FlexibleServerName)
if meta.(*clients.Client).Features.PostgresqlFlexibleServer.RestartServerOnConfigurationValueChange {
restartClient := meta.(*clients.Client).Postgres.ServerRestartClient
restartServerId := serverrestart.NewFlexibleServerID(id.SubscriptionId, id.ResourceGroupName, id.FlexibleServerName)

if err = restartClient.ServersRestartThenPoll(ctx, restartServerId, serverrestart.RestartParameter{}); err != nil {
return fmt.Errorf("restarting server %s: %+v", id, err)
if err = restartClient.ServersRestartThenPoll(ctx, restartServerId, serverrestart.RestartParameter{}); err != nil {
return fmt.Errorf("restarting server %s: %+v", id, err)
}
}
}
}
Expand Down Expand Up @@ -186,11 +188,13 @@ func resourceFlexibleServerConfigurationDelete(d *pluginsdk.ResourceData, meta i

if isDynamicConfig := props.IsDynamicConfig; isDynamicConfig != nil && !*isDynamicConfig {
if isReadOnly := props.IsReadOnly; isReadOnly != nil && !*isReadOnly {
restartClient := meta.(*clients.Client).Postgres.ServerRestartClient
restartServerId := serverrestart.NewFlexibleServerID(id.SubscriptionId, id.ResourceGroupName, id.FlexibleServerName)
if meta.(*clients.Client).Features.PostgresqlFlexibleServer.RestartServerOnConfigurationValueChange {
restartClient := meta.(*clients.Client).Postgres.ServerRestartClient
restartServerId := serverrestart.NewFlexibleServerID(id.SubscriptionId, id.ResourceGroupName, id.FlexibleServerName)

if err = restartClient.ServersRestartThenPoll(ctx, restartServerId, serverrestart.RestartParameter{}); err != nil {
return fmt.Errorf("restarting server %s: %+v", id, err)
if err = restartClient.ServersRestartThenPoll(ctx, restartServerId, serverrestart.RestartParameter{}); err != nil {
return fmt.Errorf("restarting server %s: %+v", id, err)
}
}
}
}
Expand Down
Loading
Loading