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

azurerm_postgresql_server - force new if sku_name changes tier #7456

Merged
merged 4 commits into from Jun 24, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions azurerm/internal/services/postgres/postgresql_server_resource.go
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/postgresql/mgmt/2017-12-01/postgresql"
"github.com/Azure/go-autorest/autorest/date"
"github.com/hashicorp/go-azure-helpers/response"
"github.com/hashicorp/terraform-plugin-sdk/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down Expand Up @@ -348,6 +349,22 @@ func resourceArmPostgreSQLServer() *schema.Resource {

"tags": tags.Schema(),
},

CustomizeDiff: customdiff.All(
customdiff.ForceNewIfChange("sku_name", func(old, new, meta interface{}) bool {
oldTier := strings.Split(old.(string), "_")
newTier := strings.Split(new.(string), "_")
// If the sku tier was not changed, we don't need fornew
if oldTier[0] == newTier[0] {
return false
}
// Basic tier could not be changed to other tiers
if oldTier[0] == "B" || newTier[0] == "B" {
return true
}
return false
}),
),
}
}

Expand Down
Expand Up @@ -311,6 +311,13 @@ func TestAccAzureRMPostgreSQLServer_updateSKU(t *testing.T) {
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMPostgreSQLServerDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMPostgreSQLServer_sku(data, "10.0", "B_Gen5_2"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMPostgreSQLServerExists(data.ResourceName),
),
},
data.ImportStep("administrator_login_password"),
{
Config: testAccAzureRMPostgreSQLServer_sku(data, "10.0", "GP_Gen5_2"),
Check: resource.ComposeTestCheckFunc(
Expand Down