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

[ASG] fix: Fixed max_group_prepared_capacity to allow setting 0 #37174

Merged
Show file tree
Hide file tree
Changes from 6 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
7 changes: 7 additions & 0 deletions .changelog/37174.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:bug
resource/aws_autoscaling_group: Fix bug updating `warm_pool.max_group_prepared_capacity` to `0`
```

```release-note:enhancement
resource/aws_autoscaling_group: Add plan-time validation of `warm_pool.max_group_prepared_capacity` and `warm_pool.min_size`
```
File renamed without changes.
16 changes: 9 additions & 7 deletions internal/service/autoscaling/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,14 +923,16 @@ func resourceGroup() *schema.Resource {
},
},
"max_group_prepared_capacity": {
Type: schema.TypeInt,
Optional: true,
Default: defaultWarmPoolMaxGroupPreparedCapacity,
Type: schema.TypeInt,
Optional: true,
Default: defaultWarmPoolMaxGroupPreparedCapacity,
ValidateFunc: validation.IntAtLeast(defaultWarmPoolMaxGroupPreparedCapacity),
},
"min_size": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Type: schema.TypeInt,
Optional: true,
Default: 0,
ValidateFunc: validation.IntAtLeast(0),
},
"pool_state": {
Type: schema.TypeString,
Expand Down Expand Up @@ -3264,7 +3266,7 @@ func expandPutWarmPoolInput(name string, tfMap map[string]interface{}) *autoscal
apiObject.InstanceReusePolicy = expandInstanceReusePolicy(v[0].(map[string]interface{}))
}

if v, ok := tfMap["max_group_prepared_capacity"].(int); ok && v != 0 {
if v, ok := tfMap["max_group_prepared_capacity"].(int); ok {
apiObject.MaxGroupPreparedCapacity = aws.Int32(int32(v))
}

Expand Down
40 changes: 40 additions & 0 deletions internal/service/autoscaling/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,18 @@ func TestAccAutoScalingGroup_warmPool(t *testing.T) {
resource.TestCheckNoResourceAttr(resourceName, "warm_pool.#"),
),
},
{
Config: testAccGroupConfig_warmPoolZero(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckGroupExists(ctx, resourceName, &group),
resource.TestCheckResourceAttr(resourceName, "warm_pool.#", "1"),
resource.TestCheckResourceAttr(resourceName, "warm_pool.0.instance_reuse_policy.#", "1"),
resource.TestCheckResourceAttr(resourceName, "warm_pool.0.instance_reuse_policy.0.reuse_on_scale_in", "true"),
resource.TestCheckResourceAttr(resourceName, "warm_pool.0.max_group_prepared_capacity", "0"),
resource.TestCheckResourceAttr(resourceName, "warm_pool.0.min_size", "0"),
resource.TestCheckResourceAttr(resourceName, "warm_pool.0.pool_state", "Stopped"),
),
},
},
})
}
Expand Down Expand Up @@ -5778,6 +5790,34 @@ resource "aws_autoscaling_group" "test" {
`, rName))
}

func testAccGroupConfig_warmPoolZero(rName string) string {
return acctest.ConfigCompose(testAccGroupConfig_launchConfigurationBase(rName, "t3.nano"), fmt.Sprintf(`
resource "aws_autoscaling_group" "test" {
availability_zones = [data.aws_availability_zones.available.names[0]]
max_size = 5
min_size = 1
desired_capacity = 1
name = %[1]q
launch_configuration = aws_launch_configuration.test.name

warm_pool {
pool_state = "Stopped"
min_size = 0
max_group_prepared_capacity = 0
instance_reuse_policy {
reuse_on_scale_in = true
}
}

tag {
key = "Name"
value = %[1]q
propagate_at_launch = true
}
}
`, rName))
}

func testAccGroupConfig_warmPoolNone(rName string) string {
return acctest.ConfigCompose(testAccGroupConfig_launchConfigurationBase(rName, "t3.nano"), fmt.Sprintf(`
resource "aws_autoscaling_group" "test" {
Expand Down
Loading