-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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_flexible_server: fix storage_tier calculation #25947
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -400,6 +400,13 @@ func resourcePostgresqlFlexibleServer() *pluginsdk.Resource { | |||||||||||||||||||||||||||||||||||||
// storage_mb size... | ||||||||||||||||||||||||||||||||||||||
storageTiers := storageTierMappings[newMb] | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
// set default tier for storage when there is now configuration available | ||||||||||||||||||||||||||||||||||||||
if v := diff.GetRawConfig().AsValueMap()["storage_tier"]; v.IsNull() { | ||||||||||||||||||||||||||||||||||||||
newTier = string(storageTiers.DefaultTier) | ||||||||||||||||||||||||||||||||||||||
// set the new value that the update function will pickup and deploy new new storage tier. | ||||||||||||||||||||||||||||||||||||||
diff.SetNew("storage_tier", newTier) | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think if we just replace the current
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will change the logic a bit. |
||||||||||||||||||||||||||||||||||||||
if newTier == "" { | ||||||||||||||||||||||||||||||||||||||
newTier = string(storageTiers.DefaultTier) | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -524,6 +524,48 @@ func TestAccPostgresqlFlexibleServer_invalidStorageTierScalingStorageMbStorageTi | |
}) | ||
} | ||
|
||
func TestAccPostgresqlFlexibleServer_updateOnlyWithStorageMb(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is a great start to the test coverage, yet I think there are many more scenarios around this especially if we are now setting defaults when storage mb changes. I would like to see tests for storage tier set above storage tier default value, then remove the storage tier from the configuration (e.g., storage mb set to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For sure will add one more test |
||
data := acceptance.BuildTestData(t, "azurerm_postgresql_flexible_server", "test") | ||
r := PostgresqlFlexibleServerResource{} | ||
|
||
data.ResourceTest(t, r, []acceptance.TestStep{ | ||
{ | ||
Config: r.invalidStorageTierScaling(data, "P4", "32768"), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).ExistsInAzure(r), | ||
), | ||
}, | ||
data.ImportStep("administrator_password", "create_mode"), | ||
{ | ||
Config: r.updateOnlyWithStorageMb(data, "65536"), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).ExistsInAzure(r), | ||
), | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccPostgresqlFlexibleServer_updateOnlyWithStorageTier(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "azurerm_postgresql_flexible_server", "test") | ||
r := PostgresqlFlexibleServerResource{} | ||
|
||
data.ResourceTest(t, r, []acceptance.TestStep{ | ||
{ | ||
Config: r.invalidStorageTierScaling(data, "P4", "32768"), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).ExistsInAzure(r), | ||
), | ||
}, | ||
data.ImportStep("administrator_password", "create_mode"), | ||
{ | ||
Config: r.updateOnlyWithStorageTier(data, "P10"), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).ExistsInAzure(r), | ||
), | ||
}, | ||
}) | ||
} | ||
|
||
func (PostgresqlFlexibleServerResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { | ||
id, err := servers.ParseFlexibleServerID(state.ID) | ||
if err != nil { | ||
|
@@ -551,6 +593,41 @@ resource "azurerm_resource_group" "test" { | |
`, data.RandomInteger, data.Locations.Primary) | ||
} | ||
|
||
func (r PostgresqlFlexibleServerResource) updateOnlyWithStorageTier(data acceptance.TestData, storageTier string) string { | ||
return fmt.Sprintf(` | ||
%s | ||
resource "azurerm_postgresql_flexible_server" "test" { | ||
name = "acctest-fs-%d" | ||
resource_group_name = azurerm_resource_group.test.name | ||
location = azurerm_resource_group.test.location | ||
administrator_login = "adminTerraform" | ||
administrator_password = "QAZwsx123" | ||
storage_mb = 65536 | ||
storage_tier = "%s" | ||
version = "12" | ||
sku_name = "GP_Standard_D2s_v3" | ||
zone = "2" | ||
} | ||
`, r.template(data), data.RandomInteger, storageTier) | ||
} | ||
|
||
func (r PostgresqlFlexibleServerResource) updateOnlyWithStorageMb(data acceptance.TestData, storageMb string) string { | ||
return fmt.Sprintf(` | ||
%s | ||
resource "azurerm_postgresql_flexible_server" "test" { | ||
name = "acctest-fs-%d" | ||
resource_group_name = azurerm_resource_group.test.name | ||
location = azurerm_resource_group.test.location | ||
administrator_login = "adminTerraform" | ||
administrator_password = "QAZwsx123" | ||
storage_mb = %s | ||
version = "12" | ||
sku_name = "GP_Standard_D2s_v3" | ||
zone = "2" | ||
} | ||
`, r.template(data), data.RandomInteger, storageMb) | ||
} | ||
|
||
func (r PostgresqlFlexibleServerResource) basic(data acceptance.TestData) string { | ||
return fmt.Sprintf(` | ||
%s | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove all of this code and handle everything in the
!isValid
check below: