-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
resource/aws_autoscaling_group: Batch ELB attachments and detachments by 10 to prevent API and rate limiting errors #10445
Merged
bflad
merged 1 commit into
master
from
b-aws_autoscaling_group-load_balancers-update-batching
Oct 31, 2019
+240
−12
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1358,6 +1358,56 @@ func TestAccAWSAutoScalingGroup_LaunchTemplate_IAMInstanceProfile(t *testing.T) | |
}) | ||
} | ||
|
||
// Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/256 | ||
func TestAccAWSAutoScalingGroup_LoadBalancers(t *testing.T) { | ||
var group autoscaling.Group | ||
resourceName := "aws_autoscaling_group.test" | ||
rName := acctest.RandomWithPrefix("tf-acc-test") | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSAutoScalingGroupConfig_LoadBalancers(rName, 11), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSAutoScalingGroupExists(resourceName, &group), | ||
resource.TestCheckResourceAttr(resourceName, "load_balancers.#", "11"), | ||
), | ||
}, | ||
{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎊 |
||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{ | ||
"force_delete", | ||
"initial_lifecycle_hook", | ||
"name_prefix", | ||
"tag", | ||
"tags", | ||
"wait_for_capacity_timeout", | ||
"wait_for_elb_capacity", | ||
}, | ||
}, | ||
{ | ||
Config: testAccAWSAutoScalingGroupConfig_LoadBalancers(rName, 0), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSAutoScalingGroupExists(resourceName, &group), | ||
resource.TestCheckResourceAttr(resourceName, "load_balancers.#", "0"), | ||
), | ||
}, | ||
{ | ||
Config: testAccAWSAutoScalingGroupConfig_LoadBalancers(rName, 11), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSAutoScalingGroupExists(resourceName, &group), | ||
resource.TestCheckResourceAttr(resourceName, "load_balancers.#", "11"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAWSAutoScalingGroup_MixedInstancesPolicy(t *testing.T) { | ||
var group autoscaling.Group | ||
resourceName := "aws_autoscaling_group.test" | ||
|
@@ -3285,6 +3335,78 @@ resource "aws_autoscaling_group" "test" { | |
`, rName, rName, rName, rName) | ||
} | ||
|
||
func testAccAWSAutoScalingGroupConfig_LoadBalancers(rName string, elbCount int) string { | ||
return fmt.Sprintf(` | ||
data "aws_ami" "test" { | ||
most_recent = true | ||
owners = ["amazon"] | ||
|
||
filter { | ||
name = "name" | ||
values = ["amzn-ami-hvm-*-x86_64-gp2"] | ||
} | ||
} | ||
|
||
data "aws_availability_zones" "available" { | ||
state = "available" | ||
} | ||
|
||
resource "aws_launch_template" "test" { | ||
image_id = data.aws_ami.test.id | ||
instance_type = "t3.micro" | ||
name = %[1]q | ||
} | ||
|
||
resource "aws_vpc" "test" { | ||
cidr_block = "10.0.0.0/16" | ||
|
||
tags = { | ||
Name = %[1]q | ||
} | ||
} | ||
|
||
resource "aws_subnet" "test" { | ||
availability_zone = data.aws_availability_zones.available.names[0] | ||
cidr_block = "10.0.0.0/24" | ||
vpc_id = aws_vpc.test.id | ||
|
||
tags = { | ||
Name = %[1]q | ||
} | ||
} | ||
|
||
resource "aws_internet_gateway" "test" { | ||
vpc_id = aws_vpc.test.id | ||
} | ||
|
||
resource "aws_elb" "test" { | ||
count = %[2]d | ||
depends_on = ["aws_internet_gateway.test"] | ||
|
||
subnets = [aws_subnet.test.id] | ||
|
||
listener { | ||
instance_port = 80 | ||
instance_protocol = "http" | ||
lb_port = 80 | ||
lb_protocol = "http" | ||
} | ||
} | ||
|
||
resource "aws_autoscaling_group" "test" { | ||
force_delete = true | ||
max_size = 0 | ||
min_size = 0 | ||
load_balancers = length(aws_elb.test) > 0 ? aws_elb.test[*].name : [] | ||
vpc_zone_identifier = [aws_subnet.test.id] | ||
|
||
launch_template { | ||
id = aws_launch_template.test.id | ||
} | ||
} | ||
`, rName, elbCount) | ||
} | ||
|
||
func testAccAWSAutoScalingGroupConfig_MixedInstancesPolicy_Base(rName string) string { | ||
return fmt.Sprintf(` | ||
data "aws_ami" "test" { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there ever a case when we'd want to set a timeout on these functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great question and yes, there might be! Quickly scanning the recent issues, I don't see any complaints about the similar change to the target group handling (that also does not have timeouts), but for now this is dependent on the AWS side entering some sort of failure state rather than staying in the adding/deleting state forever in those cases. 🤞