diff --git a/pkg/lookable/asg.go b/pkg/lookable/asg.go index 70bac94..f12947f 100644 --- a/pkg/lookable/asg.go +++ b/pkg/lookable/asg.go @@ -49,7 +49,7 @@ func (asg AutoScalingGroup) doLookupIPs(as ASGAPI, ec EC2API, ctx context.Contex // Make a list of healthy instance ID in the ASG instances := make([]string, 0, numInstances) for _, inst := range resp2.AutoScalingGroups[0].Instances { - if (*inst.HealthStatus == "Healthy" && inst.LifecycleState == "InService") { + if (*inst.HealthStatus == "Healthy" && inst.LifecycleState == asgtypes.LifecycleStateInService) { instances = append(instances, *inst.InstanceId) } } @@ -57,7 +57,8 @@ func (asg AutoScalingGroup) doLookupIPs(as ASGAPI, ec EC2API, ctx context.Contex // No healthy instances if len(instances) == 0 { return nil, nil - + } + // Find running instances IP params3 := &ec2.DescribeInstancesInput{ InstanceIds: instances, diff --git a/pkg/lookable/asg_test.go b/pkg/lookable/asg_test.go index 7856ca1..7e8bfbb 100644 --- a/pkg/lookable/asg_test.go +++ b/pkg/lookable/asg_test.go @@ -25,9 +25,6 @@ func TestLookupASG(t *testing.T) { /* Single instance result */ { client: func(t *testing.T) (ASGAPI,EC2API) { - instanceId1 := "inst-2016584701" - instanceId2 := "inst-2016584702" - instanceId2 := "inst-2016584703" return &MockASGAPI{ DescribeAutoScalingGroupsMethod: func(ctx context.Context, params *autoscaling.DescribeAutoScalingGroupsInput, optFns...func(*autoscaling.Options)) (*autoscaling.DescribeAutoScalingGroupsOutput, error) { @@ -40,19 +37,19 @@ func TestLookupASG(t *testing.T) { { Instances: []asgtypes.Instance{ { - InstanceId: &instanceId1, - HealthStatus: "Healthy", - LifeCycleState: "InService", + InstanceId: aws.String("inst-2016584701"), + HealthStatus: aws.String("Healthy"), + LifecycleState: asgtypes.LifecycleStateInService, }, { - InstanceId: &instanceId2, - HealthStatus: "Degraded", - LifeCycleState: "Pending", + InstanceId: aws.String("inst-2016584702"), + HealthStatus: aws.String("Degraded"), + LifecycleState: asgtypes.LifecycleStateTerminating, }, { - InstanceId: &instanceId3, - HealthStatus: "Healthy", - LifeCycleState: "Terminating", + InstanceId: aws.String("inst-2016584703"), + HealthStatus: aws.String("Healthy"), + LifecycleState: asgtypes.LifecycleStatePending, }, }, }, @@ -73,14 +70,22 @@ func TestLookupASG(t *testing.T) { t.Fatal("expect InstancesIds to not be nil") } + instances := make([]ec2types.Instance, len(params.InstanceIds)) + for _, id := range params.InstanceIds { + ipv4Address := "10.0.0." + id[len(id)-1:] + ipv6Address := "f00:ba5:10:0:0:" + id[len(id)-1:] + t.Log("Instance Id:"+id+" got ipv4:"+ipv4Address+" ipv6:"+ipv6Address) + instances = append(instances, + ec2types.Instance{ + PrivateIpAddress: aws.String(ipv4Address), + Ipv6Address: aws.String(ipv6Address), + }) + } + return &ec2.DescribeInstancesOutput{ Reservations: []ec2types.Reservation{ { - Instances: []ec2types.Instance{ - { - PrivateIpAddress: aws.String("10.0.0.1"), - }, - }, + Instances: instances, }, },