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/aws_fsx_openzfs_file_system: add validation for disk_iops_configuration #30299

Merged
merged 3 commits into from
Mar 29, 2023
Merged
Changes from 2 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
32 changes: 28 additions & 4 deletions internal/service/fsx/openzfs_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ func ResourceOpenzfsFileSystem() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"iops": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validation.IntBetween(0, 160000),
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"mode": {
Type: schema.TypeString,
Expand Down Expand Up @@ -271,6 +270,7 @@ func ResourceOpenzfsFileSystem() *schema.Resource {

CustomizeDiff: customdiff.All(
verify.SetTagsDiff,
validateDiskConfigurationIOPS,
func(_ context.Context, d *schema.ResourceDiff, meta interface{}) error {
var (
singleAZ1ThroughputCapacityValues = []int{64, 128, 256, 512, 1024, 2048, 3072, 4096}
Expand All @@ -296,6 +296,30 @@ func ResourceOpenzfsFileSystem() *schema.Resource {
}
}

func validateDiskConfigurationIOPS(_ context.Context, d *schema.ResourceDiff, meta interface{}) error {
deploymentType := d.Get("deployment_type").(string)

if diskConfiguration, ok := d.GetOk("disk_iops_configuration"); ok {
if len(diskConfiguration.([]interface{})) > 0 {
m := diskConfiguration.([]interface{})[0].(map[string]interface{})

if v, ok := m["iops"].(int); ok {
if deploymentType == fsx.OpenZFSDeploymentTypeSingleAz1 {
if v < 0 || v > 160000 {
return fmt.Errorf("expected disk_iops_configuration.0.iops to be in the range (0 - 160000) when deployment_type (%s), got %d", fsx.OpenZFSDeploymentTypeSingleAz1, v)
}
} else if deploymentType == fsx.OpenZFSDeploymentTypeSingleAz2 {
if v < 0 || v > 350000 {
return fmt.Errorf("expected disk_iops_configuration.0.iops to be in the range (0 - 350000) when deployment_type (%s), got %d", fsx.OpenZFSDeploymentTypeSingleAz2, v)
}
}
}
}
}

return nil
}

func resourceOpenzfsFileSystemCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).FSxConn()
Expand Down