Skip to content

Commit

Permalink
fix(ocean/ecs): Fixed max_vcpu and max_memory_gib fields to accep…
Browse files Browse the repository at this point in the history
…t null. (#600)
  • Loading branch information
chandra1-n authored Nov 26, 2024
1 parent affffe6 commit 7d777b5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Unreleased

## 1.200.0 (November, 26 2024)
BUG FIXES:
* resource/spotinst_ocean_aws: Fixed `max_vcpu` and `max_memory_gib` fields to accept null.
* resource/spotinst_ocean_ecs: Fixed `max_vcpu` and `max_memory_gib` fields to accept null.

## 1.199.0 (November, 21 2024)
ENHANCEMENTS:
* resource/spotinst_ocean_aws: Added `reserved_enis` field to support max pods configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,21 @@ func expandOceanAWSAutoScalerResourceLimits(data interface{}) (*aws.AutoScalerRe
if list != nil && list[0] != nil {
m := list[0].(map[string]interface{})

if v, ok := m[string(MaxMemoryGIB)].(int); ok && v > 0 {
resLimits.SetMaxMemoryGiB(spotinst.Int(v))
if v, ok := m[string(MaxMemoryGIB)].(int); ok {
if v == 0 {
resLimits.SetMaxMemoryGiB(nil)
} else {
resLimits.SetMaxMemoryGiB(spotinst.Int(v))
}
}

if v, ok := m[string(MaxVCPU)].(int); ok && v > 0 {
resLimits.SetMaxVCPU(spotinst.Int(v))
if v, ok := m[string(MaxVCPU)].(int); ok {
if v == 0 {
resLimits.SetMaxVCPU(nil)
} else {
resLimits.SetMaxVCPU(spotinst.Int(v))
}
}

}
return resLimits, nil
}
Expand Down Expand Up @@ -429,7 +436,15 @@ func flattenAutoScaleDown(autoScaleDown *aws.AutoScalerDown) []interface{} {

func flattenAutoScaleResourceLimits(autoScalerResourceLimits *aws.AutoScalerResourceLimits) []interface{} {
down := make(map[string]interface{})
down[string(MaxVCPU)] = spotinst.IntValue(autoScalerResourceLimits.MaxVCPU)
down[string(MaxMemoryGIB)] = spotinst.IntValue(autoScalerResourceLimits.MaxMemoryGiB)
value := spotinst.Int(0)
down[string(MaxVCPU)] = value
down[string(MaxMemoryGIB)] = value

if autoScalerResourceLimits.MaxVCPU != nil {
down[string(MaxVCPU)] = spotinst.IntValue(autoScalerResourceLimits.MaxVCPU)
}
if autoScalerResourceLimits.MaxMemoryGiB != nil {
down[string(MaxMemoryGIB)] = spotinst.IntValue(autoScalerResourceLimits.MaxMemoryGiB)
}
return []interface{}{down}
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,20 @@ func expandOceanAWSAutoScalerResourceLimits(data interface{}) (*aws.ECSAutoScale
if list != nil && list[0] != nil {
m := list[0].(map[string]interface{})

if v, ok := m[string(MaxMemoryGib)].(int); ok && v > 0 {
resLimits.SetMaxMemoryGiB(spotinst.Int(v))
if v, ok := m[string(MaxMemoryGib)].(int); ok {
if v == 0 {
resLimits.SetMaxMemoryGiB(nil)
} else {
resLimits.SetMaxMemoryGiB(spotinst.Int(v))
}
}

if v, ok := m[string(MaxVCpu)].(int); ok && v > 0 {
resLimits.SetMaxVCPU(spotinst.Int(v))
if v, ok := m[string(MaxVCpu)].(int); ok {
if v == 0 {
resLimits.SetMaxVCPU(nil)
} else {
resLimits.SetMaxVCPU(spotinst.Int(v))
}
}

}
Expand Down Expand Up @@ -338,7 +346,15 @@ func flattenAutoScaleHeadroom(autoScaleHeadroom *aws.ECSAutoScalerHeadroom) []in

func flattenAutoScaleResourceLimits(autoScalerResourceLimits *aws.ECSAutoScalerResourceLimits) []interface{} {
down := make(map[string]interface{})
down[string(MaxVCpu)] = spotinst.IntValue(autoScalerResourceLimits.MaxVCPU)
down[string(MaxMemoryGib)] = spotinst.IntValue(autoScalerResourceLimits.MaxMemoryGiB)
value := spotinst.Int(0)
down[string(MaxVCpu)] = value
down[string(MaxMemoryGib)] = value

if autoScalerResourceLimits.MaxVCPU != nil {
down[string(MaxVCpu)] = spotinst.IntValue(autoScalerResourceLimits.MaxVCPU)
}
if autoScalerResourceLimits.MaxMemoryGiB != nil {
down[string(MaxMemoryGib)] = spotinst.IntValue(autoScalerResourceLimits.MaxMemoryGiB)
}
return []interface{}{down}
}

0 comments on commit 7d777b5

Please sign in to comment.