diff --git a/plugin/plugin.go b/plugin/plugin.go index 486cddc..2f276e6 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -414,12 +414,6 @@ func (p *AwsPlugin) ListHosts(ctx context.Context, req *pb.ListHostsRequest) (*p return nil, fmt.Errorf("error processing host results for host set id %q: %w", query.Id, err) } - if host == nil { - // Nil result means we don't include the host (instance not - // running, or some other issue). - continue - } - queries[i].OutputHosts = append(queries[i].OutputHosts, host) maxLen++ // Increment maximum counter for allocation later } @@ -612,9 +606,6 @@ func buildDescribeInstancesInput(attrs *structpb.Struct, dryRun bool) (*ec2.Desc // awsInstanceToHost processes data from an ec2.Instance and returns // a ListHostsResponseHost with the ID and network addresses // populated. -// -// Returns nil if the instance is not ready (ie: powered down, -// hibernated, or terminated). func awsInstanceToHost(instance *ec2.Instance) (*pb.ListHostsResponseHost, error) { // Integrity check: some fields should always be non-nil. Check // those. @@ -622,23 +613,10 @@ func awsInstanceToHost(instance *ec2.Instance) (*pb.ListHostsResponseHost, error return nil, errors.New("response integrity error: missing instance entry") } - if instance.State == nil { - return nil, errors.New("response integrity error: missing instance state") - } - - if aws.StringValue(instance.State.Name) == "" { - return nil, errors.New("response integrity error: missing instance state name") - } - if aws.StringValue(instance.InstanceId) == "" { return nil, errors.New("response integrity error: missing instance id") } - // Abort this if the instance is not ready - if aws.StringValue(instance.State.Name) != ec2.InstanceStateNameRunning { - return nil, nil - } - result := new(pb.ListHostsResponseHost) // External ID is the instance ID. diff --git a/plugin/plugin_test.go b/plugin/plugin_test.go index 8b3d3fa..3f9fd9d 100644 --- a/plugin/plugin_test.go +++ b/plugin/plugin_test.go @@ -1183,7 +1183,7 @@ func TestPluginListHostsErr(t *testing.T) { ), )), }, - expectedErr: "error processing host results for host set id \"foobar\": response integrity error: missing instance state", + expectedErr: "error processing host results for host set id \"foobar\": response integrity error: missing instance id", }, } @@ -1674,42 +1674,13 @@ func TestAwsInstanceToHost(t *testing.T) { expectedErr: "response integrity error: missing instance entry", }, { - name: "nil instance state", + name: "missing instance id", instance: &ec2.Instance{}, - expectedErr: "response integrity error: missing instance state", - }, - { - name: "missing instance state name", - instance: &ec2.Instance{ - State: &ec2.InstanceState{}, - }, - expectedErr: "response integrity error: missing instance state name", - }, - { - name: "missing instance id", - instance: &ec2.Instance{ - State: &ec2.InstanceState{ - Name: aws.String(ec2.InstanceStateNameRunning), - }, - }, expectedErr: "response integrity error: missing instance id", }, - { - name: "instance not running", - instance: &ec2.Instance{ - State: &ec2.InstanceState{ - Name: aws.String(ec2.InstanceStateNameTerminated), - }, - InstanceId: aws.String("foobar"), - }, - expected: nil, - }, { name: "nil interface entry", instance: &ec2.Instance{ - State: &ec2.InstanceState{ - Name: aws.String(ec2.InstanceStateNameRunning), - }, InstanceId: aws.String("foobar"), NetworkInterfaces: []*ec2.InstanceNetworkInterface{nil}, }, @@ -1718,9 +1689,6 @@ func TestAwsInstanceToHost(t *testing.T) { { name: "nil interface address entry", instance: &ec2.Instance{ - State: &ec2.InstanceState{ - Name: aws.String(ec2.InstanceStateNameRunning), - }, InstanceId: aws.String("foobar"), NetworkInterfaces: []*ec2.InstanceNetworkInterface{ &ec2.InstanceNetworkInterface{ @@ -1733,9 +1701,6 @@ func TestAwsInstanceToHost(t *testing.T) { { name: "good, single IP w/public addr", instance: &ec2.Instance{ - State: &ec2.InstanceState{ - Name: aws.String(ec2.InstanceStateNameRunning), - }, InstanceId: aws.String("foobar"), PrivateIpAddress: aws.String("10.0.0.1"), PublicIpAddress: aws.String("1.1.1.1"), @@ -1760,9 +1725,6 @@ func TestAwsInstanceToHost(t *testing.T) { { name: "good, private", instance: &ec2.Instance{ - State: &ec2.InstanceState{ - Name: aws.String(ec2.InstanceStateNameRunning), - }, InstanceId: aws.String("foobar"), PrivateIpAddress: aws.String("10.0.0.1"), NetworkInterfaces: []*ec2.InstanceNetworkInterface{ @@ -1783,9 +1745,6 @@ func TestAwsInstanceToHost(t *testing.T) { { name: "good, multiple interfaces", instance: &ec2.Instance{ - State: &ec2.InstanceState{ - Name: aws.String(ec2.InstanceStateNameRunning), - }, InstanceId: aws.String("foobar"), PrivateIpAddress: aws.String("10.0.0.1"), PublicIpAddress: aws.String("1.1.1.1"), @@ -1817,9 +1776,6 @@ func TestAwsInstanceToHost(t *testing.T) { { name: "good, multiple public interfaces", instance: &ec2.Instance{ - State: &ec2.InstanceState{ - Name: aws.String(ec2.InstanceStateNameRunning), - }, InstanceId: aws.String("foobar"), PrivateIpAddress: aws.String("10.0.0.1"), PublicIpAddress: aws.String("1.1.1.1"), @@ -1854,9 +1810,6 @@ func TestAwsInstanceToHost(t *testing.T) { { name: "good, multiple addresses on single interface", instance: &ec2.Instance{ - State: &ec2.InstanceState{ - Name: aws.String(ec2.InstanceStateNameRunning), - }, InstanceId: aws.String("foobar"), PrivateIpAddress: aws.String("10.0.0.1"), PublicIpAddress: aws.String("1.1.1.1"), @@ -1884,9 +1837,6 @@ func TestAwsInstanceToHost(t *testing.T) { { name: "good, single IP w/public addr and IPv6", instance: &ec2.Instance{ - State: &ec2.InstanceState{ - Name: aws.String(ec2.InstanceStateNameRunning), - }, InstanceId: aws.String("foobar"), PrivateIpAddress: aws.String("10.0.0.1"), PublicIpAddress: aws.String("1.1.1.1"),