Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gruntwork-io/terratest
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 72d9de8cfd7fbdb02cba9d81c3f3ff1e8f3e58ce
Choose a base ref
..
head repository: gruntwork-io/terratest
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 22a3870b391ea393e0454bec6007cc97f5ccccac
Choose a head ref
Showing with 27 additions and 8 deletions.
  1. +27 −8 modules/aws/asg_test.go
35 changes: 27 additions & 8 deletions modules/aws/asg_test.go
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import (

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/autoscaling"
autoscalingTypes "github.com/aws/aws-sdk-go-v2/service/autoscaling/types"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/stretchr/testify/assert"
@@ -49,20 +50,32 @@ func TestGetInstanceIdsForAsg(t *testing.T) {
assert.Equal(t, len(instanceIds), 1)
}

// The following functions were adapted from the tests for cloud-nuke

func createTestAutoScalingGroup(t *testing.T, name string, region string, desiredCount int32) {
instance := createTestEC2Instance(t, region, name)
azs := GetAvailabilityZones(t, region)
ec2Client := NewEc2Client(t, region)
imageID := GetAmazonLinuxAmi(t, region)
template, err := ec2Client.CreateLaunchTemplate(context.Background(), &ec2.CreateLaunchTemplateInput{
LaunchTemplateData: &types.RequestLaunchTemplateData{
ImageId: aws.String(imageID),
InstanceType: types.InstanceType(GetRecommendedInstanceType(t, region, []string{"t2.micro, t3.micro", "t2.small", "t3.small"})),
},
LaunchTemplateName: aws.String(name),
})
require.NoError(t, err)

asgClient := NewAsgClient(t, region)
param := &autoscaling.CreateAutoScalingGroupInput{
AutoScalingGroupName: &name,
InstanceId: instance.InstanceId,
DesiredCapacity: aws.Int32(desiredCount),
MinSize: aws.Int32(1),
MaxSize: aws.Int32(3),
LaunchTemplate: &autoscalingTypes.LaunchTemplateSpecification{
LaunchTemplateId: template.LaunchTemplate.LaunchTemplateId,
Version: aws.String("$Latest"),
},
AvailabilityZones: azs,
DesiredCapacity: aws.Int32(desiredCount),
MinSize: aws.Int32(1),
MaxSize: aws.Int32(3),
}
_, err := asgClient.CreateAutoScalingGroup(context.Background(), param)
_, err = asgClient.CreateAutoScalingGroup(context.Background(), param)
require.NoError(t, err)

waiter := autoscaling.NewGroupExistsWaiter(asgClient)
@@ -151,6 +164,12 @@ func deleteAutoScalingGroup(t *testing.T, name string, region string) {
AutoScalingGroupNames: []string{name},
}, 40*time.Minute)
require.NoError(t, err)

ec2Client := NewEc2Client(t, region)
_, err = ec2Client.DeleteLaunchTemplate(context.Background(), &ec2.DeleteLaunchTemplateInput{
LaunchTemplateName: aws.String(name),
})
require.NoError(t, err)
}

func scaleAsgToZero(t *testing.T, name string, region string) {