diff --git a/.changelog/37174.txt b/.changelog/37174.txt new file mode 100644 index 00000000000..40f846003a6 --- /dev/null +++ b/.changelog/37174.txt @@ -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` +``` diff --git a/37977.txt b/.changelog/37977.txt similarity index 100% rename from 37977.txt rename to .changelog/37977.txt diff --git a/internal/service/autoscaling/group.go b/internal/service/autoscaling/group.go index a20bfaca962..11c76a19cd4 100644 --- a/internal/service/autoscaling/group.go +++ b/internal/service/autoscaling/group.go @@ -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, @@ -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)) } diff --git a/internal/service/autoscaling/group_test.go b/internal/service/autoscaling/group_test.go index a30df4d5db8..5e0bd39be4d 100644 --- a/internal/service/autoscaling/group_test.go +++ b/internal/service/autoscaling/group_test.go @@ -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.#", acctest.Ct1), + resource.TestCheckResourceAttr(resourceName, "warm_pool.0.instance_reuse_policy.#", acctest.Ct1), + resource.TestCheckResourceAttr(resourceName, "warm_pool.0.instance_reuse_policy.0.reuse_on_scale_in", acctest.CtTrue), + resource.TestCheckResourceAttr(resourceName, "warm_pool.0.max_group_prepared_capacity", acctest.Ct0), + resource.TestCheckResourceAttr(resourceName, "warm_pool.0.min_size", acctest.Ct0), + resource.TestCheckResourceAttr(resourceName, "warm_pool.0.pool_state", "Stopped"), + ), + }, }, }) } @@ -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" {