From 2ca48ab8d593d2ea340fc36c01d48e39a0239b9c Mon Sep 17 00:00:00 2001 From: Even Holthe Date: Tue, 3 Sep 2019 09:54:37 +0200 Subject: [PATCH 1/3] r/postgresql_server: support storage auto-grow Add support for Azure PostgreSQL storage auto-grow. It went into GA on June 26th 2019. It is enabled by default, to conform with the behaviour described in the Azure CLI docs . This resolves #3885 --- azurerm/resource_arm_postgresql_server.go | 14 ++++++++++++++ azurerm/resource_arm_postgresql_server_test.go | 4 ++++ website/docs/r/postgresql_server.html.markdown | 3 +++ 3 files changed, 21 insertions(+) diff --git a/azurerm/resource_arm_postgresql_server.go b/azurerm/resource_arm_postgresql_server.go index f3ac12bed6a6..bd70a5a72966 100644 --- a/azurerm/resource_arm_postgresql_server.go +++ b/azurerm/resource_arm_postgresql_server.go @@ -166,6 +166,16 @@ func resourceArmPostgreSQLServer() *schema.Resource { }, true), DiffSuppressFunc: suppress.CaseDifference, }, + "auto_grow": { + Type: schema.TypeString, + Optional: true, + Default: string(postgresql.StorageAutogrowEnabled), + ValidateFunc: validation.StringInSlice([]string{ + string(postgresql.StorageAutogrowEnabled), + string(postgresql.StorageAutogrowDisabled), + }, true), + DiffSuppressFunc: suppress.CaseDifference, + }, }, }, }, @@ -424,11 +434,13 @@ func expandAzureRmPostgreSQLStorageProfile(d *schema.ResourceData) *postgresql.S backupRetentionDays := storageprofile["backup_retention_days"].(int) geoRedundantBackup := storageprofile["geo_redundant_backup"].(string) storageMB := storageprofile["storage_mb"].(int) + autoGrow := storageprofile["auto_grow"].(string) return &postgresql.StorageProfile{ BackupRetentionDays: utils.Int32(int32(backupRetentionDays)), GeoRedundantBackup: postgresql.GeoRedundantBackup(geoRedundantBackup), StorageMB: utils.Int32(int32(storageMB)), + StorageAutogrow: postgresql.StorageAutogrow(autoGrow), } } @@ -459,6 +471,8 @@ func flattenPostgreSQLStorageProfile(resp *postgresql.StorageProfile) []interfac values["storage_mb"] = *storageMB } + values["auto_grow"] = string(resp.StorageAutogrow) + if backupRetentionDays := resp.BackupRetentionDays; backupRetentionDays != nil { values["backup_retention_days"] = *backupRetentionDays } diff --git a/azurerm/resource_arm_postgresql_server_test.go b/azurerm/resource_arm_postgresql_server_test.go index f6d3c385efc4..975390457b44 100644 --- a/azurerm/resource_arm_postgresql_server_test.go +++ b/azurerm/resource_arm_postgresql_server_test.go @@ -298,6 +298,7 @@ func TestAccAzureRMPostgreSQLServer_updated(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "sku.0.name", "GP_Gen5_2"), resource.TestCheckResourceAttr(resourceName, "version", "9.6"), resource.TestCheckResourceAttr(resourceName, "storage_profile.0.storage_mb", "51200"), + resource.TestCheckResourceAttr(resourceName, "storage_profile.0.auto_grow", "Disabled"), resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), ), }, @@ -308,6 +309,7 @@ func TestAccAzureRMPostgreSQLServer_updated(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "sku.0.name", "GP_Gen5_4"), resource.TestCheckResourceAttr(resourceName, "version", "9.6"), resource.TestCheckResourceAttr(resourceName, "storage_profile.0.storage_mb", "640000"), + resource.TestCheckResourceAttr(resourceName, "storage_profile.0.auto_grow", "Enabled"), resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), ), }, @@ -438,6 +440,7 @@ resource "azurerm_postgresql_server" "test" { storage_mb = 51200 backup_retention_days = 7 geo_redundant_backup = "Disabled" + auto_grow = "Disabled" } administrator_login = "acctestun" @@ -583,6 +586,7 @@ resource "azurerm_postgresql_server" "test" { storage_mb = 947200 backup_retention_days = 7 geo_redundant_backup = "Disabled" + auto_grow = "Enabled" } administrator_login = "acctestun" diff --git a/website/docs/r/postgresql_server.html.markdown b/website/docs/r/postgresql_server.html.markdown index 34318962e5f6..5a3e6460724b 100644 --- a/website/docs/r/postgresql_server.html.markdown +++ b/website/docs/r/postgresql_server.html.markdown @@ -34,6 +34,7 @@ resource "azurerm_postgresql_server" "test" { storage_mb = 5120 backup_retention_days = 7 geo_redundant_backup = "Disabled" + auto_grow = "Enabled" } administrator_login = "psqladminun" @@ -89,6 +90,8 @@ The following arguments are supported: * `geo_redundant_backup` - (Optional) Enable/Disable Geo-redundant for server backup. Valid values for this property are `Enabled` or `Disabled`, not supported for the `basic` tier. This allows you to choose between locally redundant or geo-redundant backup storage in the General Purpose and Memory Optimized tiers. When the backups are stored in geo-redundant backup storage, they are not only stored within the region in which your server is hosted, but are also replicated to a paired data center. This provides better protection and ability to restore your server in a different region in the event of a disaster. The Basic tier only offers locally redundant backup storage. +* `auto_grow` - (Optional) Enable/Disable auto-growing of the storage. Valid values for this property are `Enabled` or `Disabled`. Storage auto-grow prevents your server from running out of storage and becoming read-only. If storage auto grow is enabled, the storage automatically grows without impacting the workload. The default value if not explicitly specified is `Enabled`. + ## Attributes Reference The following attributes are exported: From e84e923becb4456eec3f1db0b2aad6b1e556f46e Mon Sep 17 00:00:00 2001 From: Even Holthe Date: Tue, 3 Sep 2019 10:07:35 +0200 Subject: [PATCH 2/3] r/postgresql_server: fix formatting --- azurerm/resource_arm_postgresql_server.go | 24 +++++++++---------- .../resource_arm_postgresql_server_test.go | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/azurerm/resource_arm_postgresql_server.go b/azurerm/resource_arm_postgresql_server.go index bd70a5a72966..9744c3bb1ddb 100644 --- a/azurerm/resource_arm_postgresql_server.go +++ b/azurerm/resource_arm_postgresql_server.go @@ -166,16 +166,16 @@ func resourceArmPostgreSQLServer() *schema.Resource { }, true), DiffSuppressFunc: suppress.CaseDifference, }, - "auto_grow": { - Type: schema.TypeString, - Optional: true, - Default: string(postgresql.StorageAutogrowEnabled), - ValidateFunc: validation.StringInSlice([]string{ - string(postgresql.StorageAutogrowEnabled), - string(postgresql.StorageAutogrowDisabled), - }, true), - DiffSuppressFunc: suppress.CaseDifference, - }, + "auto_grow": { + Type: schema.TypeString, + Optional: true, + Default: string(postgresql.StorageAutogrowEnabled), + ValidateFunc: validation.StringInSlice([]string{ + string(postgresql.StorageAutogrowEnabled), + string(postgresql.StorageAutogrowDisabled), + }, true), + DiffSuppressFunc: suppress.CaseDifference, + }, }, }, }, @@ -434,7 +434,7 @@ func expandAzureRmPostgreSQLStorageProfile(d *schema.ResourceData) *postgresql.S backupRetentionDays := storageprofile["backup_retention_days"].(int) geoRedundantBackup := storageprofile["geo_redundant_backup"].(string) storageMB := storageprofile["storage_mb"].(int) - autoGrow := storageprofile["auto_grow"].(string) + autoGrow := storageprofile["auto_grow"].(string) return &postgresql.StorageProfile{ BackupRetentionDays: utils.Int32(int32(backupRetentionDays)), @@ -471,7 +471,7 @@ func flattenPostgreSQLStorageProfile(resp *postgresql.StorageProfile) []interfac values["storage_mb"] = *storageMB } - values["auto_grow"] = string(resp.StorageAutogrow) + values["auto_grow"] = string(resp.StorageAutogrow) if backupRetentionDays := resp.BackupRetentionDays; backupRetentionDays != nil { values["backup_retention_days"] = *backupRetentionDays diff --git a/azurerm/resource_arm_postgresql_server_test.go b/azurerm/resource_arm_postgresql_server_test.go index 975390457b44..89e9407e6932 100644 --- a/azurerm/resource_arm_postgresql_server_test.go +++ b/azurerm/resource_arm_postgresql_server_test.go @@ -298,7 +298,7 @@ func TestAccAzureRMPostgreSQLServer_updated(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "sku.0.name", "GP_Gen5_2"), resource.TestCheckResourceAttr(resourceName, "version", "9.6"), resource.TestCheckResourceAttr(resourceName, "storage_profile.0.storage_mb", "51200"), - resource.TestCheckResourceAttr(resourceName, "storage_profile.0.auto_grow", "Disabled"), + resource.TestCheckResourceAttr(resourceName, "storage_profile.0.auto_grow", "Disabled"), resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), ), }, @@ -309,7 +309,7 @@ func TestAccAzureRMPostgreSQLServer_updated(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "sku.0.name", "GP_Gen5_4"), resource.TestCheckResourceAttr(resourceName, "version", "9.6"), resource.TestCheckResourceAttr(resourceName, "storage_profile.0.storage_mb", "640000"), - resource.TestCheckResourceAttr(resourceName, "storage_profile.0.auto_grow", "Enabled"), + resource.TestCheckResourceAttr(resourceName, "storage_profile.0.auto_grow", "Enabled"), resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), ), }, From 7db7c4a4f2b0d47b34b3156cd635b988953ec76b Mon Sep 17 00:00:00 2001 From: Even Holthe Date: Tue, 3 Sep 2019 13:53:46 +0200 Subject: [PATCH 3/3] r/postgresql_server: make 'auto_grow' case-sensitive --- azurerm/resource_arm_postgresql_server.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/azurerm/resource_arm_postgresql_server.go b/azurerm/resource_arm_postgresql_server.go index 9744c3bb1ddb..03dacfa46ad4 100644 --- a/azurerm/resource_arm_postgresql_server.go +++ b/azurerm/resource_arm_postgresql_server.go @@ -173,8 +173,7 @@ func resourceArmPostgreSQLServer() *schema.Resource { ValidateFunc: validation.StringInSlice([]string{ string(postgresql.StorageAutogrowEnabled), string(postgresql.StorageAutogrowDisabled), - }, true), - DiffSuppressFunc: suppress.CaseDifference, + }, false), }, }, },