Skip to content

Commit

Permalink
azurerm_postgresql_server - force new if sku_name changes tier (h…
Browse files Browse the repository at this point in the history
…ashicorp#7456)

Fix :hashicorp#7131

=== RUN TestAccAzureRMPostgreSQLServer_updateSKU
=== PAUSE TestAccAzureRMPostgreSQLServer_updateSKU
=== CONT TestAccAzureRMPostgreSQLServer_updateSKU
--- PASS: TestAccAzureRMPostgreSQLServer_updateSKU (632.60s)
PASS
  • Loading branch information
yupwei68 authored and jrauschenbusch committed Jun 29, 2020
1 parent 938a573 commit 54c8eb0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
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

0 comments on commit 54c8eb0

Please sign in to comment.