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

r/postgresql_server: support storage auto-grow #4220

Merged
merged 3 commits into from
Sep 3, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions azurerm/resource_arm_postgresql_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ 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),
}, false),
},
},
},
},
Expand Down Expand Up @@ -424,11 +433,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 +470,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