Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Commit

Permalink
r/postgresql_server: support storage auto-grow
Browse files Browse the repository at this point in the history
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 hashicorp#3885
  • Loading branch information
evenh committed Sep 3, 2019
1 parent 74d519f commit f9ea5b6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
14 changes: 14 additions & 0 deletions azurerm/resource_arm_postgresql_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
},
Expand Down Expand Up @@ -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),
}
}

Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions azurerm/resource_arm_postgresql_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
Expand All @@ -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"),
),
},
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/postgresql_server.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit f9ea5b6

Please sign in to comment.