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

update azurerm_postgresql_server/azurerm_mysql_server storage_mb validation bounds #1449

Merged
merged 10 commits into from
Jun 28, 2018
15 changes: 14 additions & 1 deletion azurerm/resource_arm_mysql_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package azurerm
import (
"fmt"
"log"
"strings"

"github.com/Azure/azure-sdk-for-go/services/mysql/mgmt/2017-12-01/mysql"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -135,7 +136,7 @@ func resourceArmMySqlServer() *schema.Resource {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validateIntBetweenDivisibleBy(5120, 1048576, 1024),
ValidateFunc: validateIntBetweenDivisibleBy(5120, 4194304, 1024),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this also validate the SKU since only general purpose and memory optimized support this larger upper limit?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, i agree

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeffreyCline I'm not super familiar with your conventions / golang style best practices. would you use a case/switch or an if here? Or is there a better option? Is there an example of another resource in the provider that does this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gabinante,

Here is an example of using the a CustomizeDiff to ensure 1 of 2 properties is set.

In your case you can use this to get the storage_mb property is within the bounds of what the current sku allows.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gabinante I went ahead and added the validation code directly to your branch, hope that was ok. 😃

},
"backup_retention_days": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -172,6 +173,18 @@ func resourceArmMySqlServer() *schema.Resource {

"tags": tagsSchema(),
},

CustomizeDiff: func(diff *schema.ResourceDiff, v interface{}) error {

tier, _ := diff.GetOk("sku.0.tier")
storageMB, _ := diff.GetOk("storage_profile.0.storage_mb")

if strings.ToLower(tier.(string)) == "basic" && storageMB.(int) > 1048576 {
return fmt.Errorf("basic pricing tier only supports upto 1,048,576 MB (1TB) of storage")
}

return nil
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_mysql_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ resource "azurerm_mysql_server" "test" {
}

storage_profile {
storage_mb = 1048576,
storage_mb = 4194304,
backup_retention_days = 7
geo_redundant_backup = "Enabled"
}
Expand Down
15 changes: 14 additions & 1 deletion azurerm/resource_arm_postgresql_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package azurerm
import (
"fmt"
"log"
"strings"

"github.com/Azure/azure-sdk-for-go/services/postgresql/mgmt/2017-12-01/postgresql"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -136,7 +137,7 @@ func resourceArmPostgreSQLServer() *schema.Resource {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validateIntBetweenDivisibleBy(5120, 1048576, 1024),
ValidateFunc: validateIntBetweenDivisibleBy(5120, 4194304, 1024),
},

"backup_retention_days": {
Expand Down Expand Up @@ -175,6 +176,18 @@ func resourceArmPostgreSQLServer() *schema.Resource {

"tags": tagsSchema(),
},

CustomizeDiff: func(diff *schema.ResourceDiff, v interface{}) error {

tier, _ := diff.GetOk("sku.0.tier")
storageMB, _ := diff.GetOk("storage_profile.0.storage_mb")

if strings.ToLower(tier.(string)) == "basic" && storageMB.(int) > 1048576 {
return fmt.Errorf("basic pricing tier only supports upto 1,048,576 MB (1TB) of storage")
}

return nil
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_postgresql_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ resource "azurerm_postgresql_server" "test" {
}

storage_profile {
storage_mb = 1048576
storage_mb = 4194304
backup_retention_days = 7
geo_redundant_backup = "Enabled"
}
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/mysql_server.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ The following arguments are supported:

`storage_profile` supports the following:

* `storage_mb` - (Required) Max storage allowed for a server, possible values are between `5120 MB` (5GB) and `1048576 MB` (1TB). The step for this value must be in `1024 MB` (1GB) increments. For more information see the [product documentation](https://docs.microsoft.com/en-us/rest/api/mysql/servers/create#StorageProfile).
* `storage_mb` - (Required) Max storage allowed for a server. Possible values are between `5120` MB(5GB) and `1048576` MB(1TB) for the Basic SKU and between `5120` MB(5GB) and `4194304` MB(4TB) for General Purpose/Memory Optimized SKUs. For more information see the [product documentation](https://docs.microsoft.com/en-us/rest/api/mysql/servers/create#StorageProfile).

* `backup_retention_days` - (Optional) Backup retention days for the server, supported values are between `7` and `35` days.

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/postgresql_server.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ The following arguments are supported:

`storage_profile` supports the following:

* `storage_mb` - (Required) Max storage allowed for a server, possible values are between `5120 MB` (5GB) and `1048576 MB` (1TB). The step for this value must be in `1024 MB` (1GB) increments. For more information see the [product documentation](https://docs.microsoft.com/en-us/rest/api/postgresql/servers/create#StorageProfile).
* `storage_mb` - (Required) Max storage allowed for a server. Possible values are between `5120` MB(5GB) and `1048576` MB(1TB) for the Basic SKU and between `5120` MB(5GB) and `4194304` MB(4TB) for General Purpose/Memory Optimized SKUs. For more information see the [product documentation](https://docs.microsoft.com/en-us/rest/api/postgresql/servers/create#StorageProfile).

* `backup_retention_days` - (Optional) Backup retention days for the server, supported values are between `7` and `35` days.

Expand Down