Skip to content

Commit

Permalink
Merge pull request #30299 from hashicorp/b-aws_fsx_openzfs_file_syste…
Browse files Browse the repository at this point in the history
…m-iops

r/aws_fsx_openzfs_file_system: add validation for `disk_iops_configuration`
  • Loading branch information
johnsonaj authored Mar 29, 2023
2 parents 517da47 + 3ebebcc commit b044bc4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/30299.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_lakeformation_lf_tag: Fix `iops` validation in `disk_iops_configuration` to allow values for `SINGLE_AZ_1` and `SINGLE_AZ_2`
```
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

0 comments on commit b044bc4

Please sign in to comment.