Skip to content

Commit

Permalink
fix(share-iops): Share Iops range fix for dp2
Browse files Browse the repository at this point in the history
  • Loading branch information
deepaksibm authored and hkantare committed Sep 19, 2023
1 parent e644eed commit 54ed6c1
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 131 deletions.
125 changes: 0 additions & 125 deletions ibm/flex/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -2718,131 +2718,6 @@ func ResourceIBMISLBPoolCookieValidate(diff *schema.ResourceDiff) error {
return nil
}

func ResourceSharesValidate(diff *schema.ResourceDiff) error {
err := ResourceSharesValidateHelper(diff, "size", "profile", "iops")
if err != nil {
return err
}
if _, ok := diff.GetOk("replica_share"); ok {
err := ResourceSharesValidateHelper(diff, "replica_share.0.size", "replica_share.0.profile", "replica_share.0.iops")
if err != nil {
return err
}
}
return nil
}
func ResourceSharesValidateHelper(diff *schema.ResourceDiff, sizeStr, profileStr, iopsStr string) error {

profile := ""
var size, iops int

if iopsIntf, ok := diff.GetOk(iopsStr); ok {
iops = iopsIntf.(int)
}
if profileIntf, ok := diff.GetOk(profileStr); ok {
profile = profileIntf.(string)
}
if diff.HasChange(sizeStr) && !diff.HasChange(profileStr) {
oldSize, newSize := diff.GetChange(sizeStr)
if newSize.(int) < oldSize.(int) {
return fmt.Errorf("The new share size '%d' must be greater than the current share size '%d'", newSize.(int), oldSize.(int))
}
}

if sizeIntf, ok := diff.GetOk(sizeStr); ok {
size = sizeIntf.(int)
if profile == "tier-5iops" && size > 9600 {
return fmt.Errorf("'%s' shares cannot have size more than %d.", profile, 9600)
} else if profile == "tier-10iops" && size > 4800 {
return fmt.Errorf("'%s' shares cannot have size more than %d.", profile, 4800)
} else if profile == "custom-iops" && size > 16000 {
return fmt.Errorf("'%s' shares cannot have size more than %d.", profile, 16000)
}
}

if profile != "custom-iops" && profile != "dp2" {
if iops != 0 && diff.NewValueKnown(iopsStr) && diff.HasChange(iopsStr) {
return fmt.Errorf("The Share profile specified in the request cannot accept IOPS values")
}
} else {
if iops == 0 {
return nil
}
if size >= 10 && size <= 39 {
min := 100
max := 1000
if !(iops >= min && iops <= max) {
return fmt.Errorf("Shares Error: Allowed iops range for size %d is [%d-%d] ", size, min, max)
}
}
if size >= 40 && size <= 79 {
min := 100
max := 2000
if !(iops >= min && iops <= max) {
return fmt.Errorf("Shares Error: Allowed iops range for size %d is [%d-%d] ", size, min, max)
}
}
if size >= 80 && size <= 99 {
min := 100
max := 4000
if !(iops >= min && iops <= max) {
return fmt.Errorf("Shares Error: Allowed iops range for size %d is [%d-%d] ", size, min, max)
}
}
if size >= 100 && size <= 499 {
min := 100
max := 6000
if !(iops >= min && iops <= max) {
return fmt.Errorf("Shares Error: Allowed iops range for size %d is [%d-%d] ", size, min, max)
}
}
if size >= 500 && size <= 999 {
min := 100
max := 10000
if !(iops >= min && iops <= max) {
return fmt.Errorf("Shares Error: Allowed iops range for size %d is [%d-%d] ", size, min, max)
}
}
if size >= 1000 && size <= 1999 {
min := 100
max := 20000
if !(iops >= min && iops <= max) {
return fmt.Errorf("Shares Error: Allowed iops range for size %d is [%d-%d] ", size, min, max)
}
}
if size >= 2000 && size <= 3999 {
min := 200
max := 40000
if !(iops >= min && iops <= max) {
return fmt.Errorf("Shares Error: Allowed iops range for size %d is [%d-%d] ", size, min, max)
}
}
if size >= 4000 && size <= 7999 {
min := 300
max := 40000
if !(iops >= min && iops <= max) {
return fmt.Errorf("Shares Error: Allowed iops range for size %d is [%d-%d] ", size, min, max)
}
}
if size >= 8000 && size <= 9999 {
min := 500
max := 48000
if !(iops >= min && iops <= max) {
return fmt.Errorf("Shares Error: Allowed iops range for size %d is [%d-%d] ", size, min, max)
}
}
if size >= 10000 && size <= 16000 {
min := 1000
max := 48000
if !(iops >= min && iops <= max) {
return fmt.Errorf("Shares Error: Allowed iops range for size %d is [%d-%d] ", size, min, max)
}
}
}

return nil
}

func ResourceVolumeAttachmentValidate(diff *schema.ResourceDiff) error {

if volsintf, ok := diff.GetOk("volume_attachments"); ok {
Expand Down
6 changes: 1 addition & 5 deletions ibm/service/vpc/resource_ibm_is_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ func ResourceIbmIsShare() *schema.Resource {
return flex.ResourceValidateAccessTags(diff, v)
},
),
customdiff.Sequence(
func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
return flex.ResourceSharesValidate(diff)
}),
),

Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -675,7 +671,7 @@ func ResourceIbmIsShareValidator() *validate.ResourceValidator {
Type: validate.TypeInt,
Optional: true,
MinValue: "100",
MaxValue: "48000",
MaxValue: "96000",
},
validate.ValidateSchema{
Identifier: "name",
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/is_share.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ The following arguments are supported:
Nested scheme for `initial_owner`:
- `gid` - (Optional, Integer) The initial group identifier for the file share.
- `uid` - (Optional, Integer) The initial user identifier for the file share.
- `iops` - (Optional, Integer) The maximum input/output operation performance bandwidth per second for the file share.
- `iops` - (Optional, Integer) The maximum input/output operation performance bandwidth per second for the file share. For more information about the iops range for the given size, refer [File Storage for VPC profiles](https://cloud.ibm.com/docs/vpc?topic=vpc-file-storage-profiles&interface=ui)
- `mount_targets` - (Optional, List) Share targets for the file share.
- `name` - (Required, string) The user-defined name for this share target. Names must be unique within the share the share target resides in.
- `virtual_network_interface` (Optional, List) The virtual network interface for this share mount target. Required if the share's `access_control_mode` is `security_group`.
Expand Down

0 comments on commit 54ed6c1

Please sign in to comment.