Skip to content

Commit

Permalink
Merge pull request #20806 from voanhduy1512/fix_elb_wait_with_weighte…
Browse files Browse the repository at this point in the history
…d_capacity

Fix wait_for_elb_capacity not working correctly with weighted_capacity
  • Loading branch information
ewbankkit authored May 18, 2022
2 parents 9bf7fb2 + 99e5d51 commit 5f1dea2
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 78 deletions.
3 changes: 3 additions & 0 deletions .changelog/20806.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_autoscaling_group: Wait for correct number of ELBs when `wait_for_elb_capacity` is configured
```
27 changes: 14 additions & 13 deletions internal/service/appflow/connector_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
tfappflow "github.com/hashicorp/terraform-provider-aws/internal/service/appflow"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
)

func TestAccAppFlowConnectorProfile_basic(t *testing.T) {
Expand All @@ -27,10 +28,10 @@ func TestAccAppFlowConnectorProfile_basic(t *testing.T) {
resourceName := "aws_appflow_connector_profile.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, appflow.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckConnectorProfileDestroy,
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, appflow.EndpointsID),
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: testAccCheckConnectorProfileDestroy,
Steps: []resource.TestStep{
{
Config: testAccConfigConnectorProfile_basic(rName),
Expand Down Expand Up @@ -66,10 +67,10 @@ func TestAccAppFlowConnectorProfile_update(t *testing.T) {
testPrefix := "test-prefix"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, appflow.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckConnectorProfileDestroy,
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, appflow.EndpointsID),
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: testAccCheckConnectorProfileDestroy,
Steps: []resource.TestStep{
{
Config: testAccConfigConnectorProfile_basic(rName),
Expand Down Expand Up @@ -99,10 +100,10 @@ func TestAccAppFlowConnectorProfile_disappears(t *testing.T) {
resourceName := "aws_appflow_connector_profile.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, appflow.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckConnectorProfileDestroy,
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, appflow.EndpointsID),
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: testAccCheckConnectorProfileDestroy,
Steps: []resource.TestStep{
{
Config: testAccConfigConnectorProfile_basic(rName),
Expand All @@ -126,7 +127,7 @@ func testAccCheckConnectorProfileDestroy(s *terraform.State) error {

_, err := tfappflow.FindConnectorProfileByArn(context.Background(), conn, rs.Primary.ID)

if _, ok := err.(*resource.NotFoundError); ok {
if tfresource.NotFound(err) {
continue
}

Expand Down
36 changes: 19 additions & 17 deletions internal/service/appflow/flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
tfappflow "github.com/hashicorp/terraform-provider-aws/internal/service/appflow"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
)

func TestAccAppFlowFlow_basic(t *testing.T) {
Expand All @@ -23,10 +24,10 @@ func TestAccAppFlowFlow_basic(t *testing.T) {
resourceName := "aws_appflow_flow.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, appflow.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckFlowDestroy,
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, appflow.EndpointsID),
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: testAccCheckFlowDestroy,
Steps: []resource.TestStep{
{
Config: testAccConfigFlow_basic(rSourceName, rDestinationName, rFlowName),
Expand Down Expand Up @@ -67,10 +68,10 @@ func TestAccAppFlowFlow_update(t *testing.T) {
description := "test description"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, appflow.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckFlowDestroy,
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, appflow.EndpointsID),
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: testAccCheckFlowDestroy,
Steps: []resource.TestStep{
{
Config: testAccConfigFlow_basic(rSourceName, rDestinationName, rFlowName),
Expand All @@ -97,10 +98,10 @@ func TestAccAppFlowFlow_tags(t *testing.T) {
resourceName := "aws_appflow_flow.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, appflow.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckFlowDestroy,
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, appflow.EndpointsID),
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: testAccCheckFlowDestroy,
Steps: []resource.TestStep{
{
Config: testAccConfigFlow_tags1(rSourceName, rDestinationName, rFlowName, "key1", "value1"),
Expand Down Expand Up @@ -144,10 +145,10 @@ func TestAccAppFlowFlow_disappears(t *testing.T) {
resourceName := "aws_appflow_flow.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, appflow.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckFlowDestroy,
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, appflow.EndpointsID),
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: testAccCheckFlowDestroy,
Steps: []resource.TestStep{
{
Config: testAccConfigFlow_basic(rSourceName, rDestinationName, rFlowName),
Expand Down Expand Up @@ -482,9 +483,10 @@ func testAccCheckFlowDestroy(s *terraform.State) error {

_, err := tfappflow.FindFlowByArn(context.Background(), conn, rs.Primary.ID)

if _, ok := err.(*resource.NotFoundError); ok {
if tfresource.NotFound(err) {
continue
}

if err != nil {
return err
}
Expand Down
20 changes: 11 additions & 9 deletions internal/service/appintegrations/event_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ func TestAccEventIntegration_basic(t *testing.T) {
acctest.PreCheck(t)
acctest.PreCheckPartitionHasService(appintegrationsservice.EndpointsID, t)
},
ErrorCheck: acctest.ErrorCheck(t, appintegrationsservice.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckEventIntegrationDestroy,
ErrorCheck: acctest.ErrorCheck(t, appintegrationsservice.EndpointsID),
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: testAccCheckEventIntegrationDestroy,
Steps: []resource.TestStep{
{
Config: testAccEventIntegrationConfig_basic(rName, originalDescription, sourceName),
Expand Down Expand Up @@ -92,9 +92,10 @@ func TestAccEventIntegration_updateTags(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(t)
acctest.PreCheckPartitionHasService(appintegrationsservice.EndpointsID, t)
}, ErrorCheck: acctest.ErrorCheck(t, appintegrationsservice.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckEventIntegrationDestroy,
},
ErrorCheck: acctest.ErrorCheck(t, appintegrationsservice.EndpointsID),
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: testAccCheckEventIntegrationDestroy,
Steps: []resource.TestStep{
{
Config: testAccEventIntegrationConfig_basic(rName, description, sourceName),
Expand Down Expand Up @@ -170,9 +171,10 @@ func TestAccEventIntegration_disappears(t *testing.T) {
PreCheck: func() {
acctest.PreCheck(t)
acctest.PreCheckPartitionHasService(appintegrationsservice.EndpointsID, t)
}, ErrorCheck: acctest.ErrorCheck(t, appintegrationsservice.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckEventIntegrationDestroy,
},
ErrorCheck: acctest.ErrorCheck(t, appintegrationsservice.EndpointsID),
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: testAccCheckEventIntegrationDestroy,
Steps: []resource.TestStep{
{
Config: testAccEventIntegrationConfig_basic(rName, description, sourceName),
Expand Down
163 changes: 163 additions & 0 deletions internal/service/autoscaling/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2269,6 +2269,47 @@ func TestAccAutoScalingGroup_MixedInstancesPolicyLaunchTemplateOverride_weighted
})
}

func TestAccAutoScalingGroup_MixedInstancesPolicyLaunchTemplateOverride_weightedCapacity_withELB(t *testing.T) {
var group autoscaling.Group
resourceName := "aws_autoscaling_group.test"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, autoscaling.EndpointsID),
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: testAccCheckGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSAutoScalingGroupConfig_MixedInstancesPolicy_LaunchTemplate_Override_WeightedCapacity_WithELB(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckGroupExists(resourceName, &group),
resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.#", "1"),
resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.0.launch_template.#", "1"),
resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.0.launch_template.0.override.#", "2"),
resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.0.launch_template.0.override.0.instance_type", "t3.micro"),
resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.0.launch_template.0.override.0.weighted_capacity", "2"),
resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.0.launch_template.0.override.1.instance_type", "t3.small"),
resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.0.launch_template.0.override.1.weighted_capacity", "2"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"force_delete",
"initial_lifecycle_hook",
"tag",
"tags",
"wait_for_capacity_timeout",
"wait_for_elb_capacity",
},
},
},
})
}

func TestAccAutoScalingGroup_launchTempPartitionNum(t *testing.T) {
var group autoscaling.Group

Expand Down Expand Up @@ -4431,6 +4472,128 @@ resource "aws_autoscaling_group" "test" {
`, rName)
}

func testAccAWSAutoScalingGroupConfig_MixedInstancesPolicy_LaunchTemplate_Override_WeightedCapacity_WithELB(rName string) string {
return acctest.ConfigAvailableAZsNoOptInDefaultExclude() +
fmt.Sprintf(`
resource "aws_vpc" "foo" {
cidr_block = "10.1.0.0/16"
tags = {
Name = %[1]q
}
}
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.foo.id
tags = {
Name = %[1]q
}
}
resource "aws_subnet" "foo" {
availability_zone = data.aws_availability_zones.available.names[0]
cidr_block = "10.1.1.0/24"
vpc_id = aws_vpc.foo.id
tags = {
Name = %[1]q
}
}
resource "aws_security_group" "foo" {
vpc_id = aws_vpc.foo.id
ingress {
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
egress {
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_lb_target_group" "foo" {
port = 80
protocol = "HTTP"
vpc_id = aws_vpc.foo.id
}
resource "aws_elb" "bar" {
subnets = [aws_subnet.foo.id]
security_groups = [aws_security_group.foo.id]
listener {
instance_port = 80
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
health_check {
healthy_threshold = 2
unhealthy_threshold = 2
target = "HTTP:80/"
interval = 5
timeout = 2
}
depends_on = [aws_internet_gateway.gw]
}
locals {
user_data = <<EOF
#!/bin/bash
echo "Terraform aws_autoscaling_group Testing" > index.html
nohup python -m SimpleHTTPServer 80 &
EOF
}
data "aws_ami" "test" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amzn-ami-hvm-*-x86_64-gp2"]
}
}
resource "aws_launch_template" "test" {
image_id = data.aws_ami.test.id
instance_type = "t3.micro"
name = %[1]q
user_data = base64encode(local.user_data)
vpc_security_group_ids = [aws_security_group.foo.id]
}
resource "aws_autoscaling_group" "test" {
desired_capacity = 2
wait_for_elb_capacity = 2
max_size = 2
min_size = 2
name = %[1]q
load_balancers = [aws_elb.bar.name]
vpc_zone_identifier = aws_subnet.foo[*].id
mixed_instances_policy {
launch_template {
launch_template_specification {
launch_template_id = aws_launch_template.test.id
}
override {
instance_type = "t3.micro"
weighted_capacity = "2"
}
override {
instance_type = "t3.small"
weighted_capacity = "2"
}
}
}
}
`, rName)
}

func testAccGroupPartitionConfig(rName string) string {
return acctest.ConfigAvailableAZsNoOptInDefaultExclude() +
fmt.Sprintf(`
Expand Down
2 changes: 1 addition & 1 deletion internal/service/autoscaling/group_waiting.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func isELBCapacitySatisfied(d *schema.ResourceData, meta interface{}, g *autosca
}
}
if inAllLbs {
haveELB++
haveELB += capacity
}
}

Expand Down
12 changes: 6 additions & 6 deletions internal/service/connect/routing_profile_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ func TestAccConnectRoutingProfileDataSource_routingProfileID(t *testing.T) {
datasourceName := "data.aws_connect_routing_profile.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, connect.EndpointsID),
Providers: acctest.Providers,
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, connect.EndpointsID),
ProviderFactories: acctest.ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccRoutingProfileDataSourceConfig_RoutingProfileID(rName, rName2, rName3, rName4),
Expand Down Expand Up @@ -71,9 +71,9 @@ func TestAccConnectRoutingProfileDataSource_name(t *testing.T) {
datasourceName := "data.aws_connect_routing_profile.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, connect.EndpointsID),
Providers: acctest.Providers,
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, connect.EndpointsID),
ProviderFactories: acctest.ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccRoutingProfileDataSourceConfig_Name(rName, rName2, rName3, rName4),
Expand Down
Loading

0 comments on commit 5f1dea2

Please sign in to comment.