Skip to content

Commit

Permalink
Merge pull request #12018 from lachlancooper/asg-update-min-size
Browse files Browse the repository at this point in the history
Fix wait for ASG capacity when increasing min size
  • Loading branch information
YakDriver authored Nov 24, 2021
2 parents 56ba1c3 + 4e4c955 commit 1e6d287
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/12018.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_autoscaling_group: Prevent infinite wait for capacity when increasing `min_size` and not specifying `desired_capacity`
```
12 changes: 7 additions & 5 deletions internal/service/autoscaling/group_waiting.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,13 @@ func CapacitySatisfiedCreate(d *schema.ResourceData, haveASG, haveELB int) (bool

// CapacitySatisfiedUpdate only cares about specific targets
func CapacitySatisfiedUpdate(d *schema.ResourceData, haveASG, haveELB int) (bool, string) {
if wantASG := d.Get("desired_capacity").(int); wantASG > 0 {
if haveASG != wantASG {
return false, fmt.Sprintf(
"Need exactly %d healthy instances in ASG, have %d", wantASG, haveASG)
}
minASG := d.Get("min_size").(int)
if wantASG := d.Get("desired_capacity").(int); wantASG > minASG {
minASG = wantASG
}
if haveASG != minASG {
return false, fmt.Sprintf(
"Need exactly %d healthy instances in ASG, have %d", minASG, haveASG)
}
if wantELB := d.Get("wait_for_elb_capacity").(int); wantELB > 0 {
if haveELB != wantELB {
Expand Down
25 changes: 25 additions & 0 deletions internal/service/autoscaling/group_waiting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,22 @@ func TestCapacitySatisfiedUpdate(t *testing.T) {
Data: map[string]interface{}{},
ExpectSatisfied: true,
},
"min_size, got it": {
Data: map[string]interface{}{
"min_size": 5,
},
HaveASG: 5,
ExpectSatisfied: true,
},
"min_size overrides desired_capacity": {
Data: map[string]interface{}{
"min_size": 5,
"desired_capacity": 2,
},
HaveASG: 2,
ExpectSatisfied: false,
ExpectReason: "Need exactly 5 healthy instances in ASG, have 2",
},
"desired_capacity, have less": {
Data: map[string]interface{}{
"desired_capacity": 5,
Expand All @@ -165,6 +181,15 @@ func TestCapacitySatisfiedUpdate(t *testing.T) {
ExpectSatisfied: false,
ExpectReason: "Need exactly 5 healthy instances in ASG, have 2",
},
"desired_capacity overrides min_size": {
Data: map[string]interface{}{
"min_size": 2,
"desired_capacity": 5,
},
HaveASG: 2,
ExpectSatisfied: false,
ExpectReason: "Need exactly 5 healthy instances in ASG, have 2",
},
"desired_capacity, got it": {
Data: map[string]interface{}{
"desired_capacity": 5,
Expand Down

0 comments on commit 1e6d287

Please sign in to comment.