Don't ignore non-running instances, rely on filter instead
We now add the instance-state = ["running"] filter to all queries if instance-state is not explicitly defined beforehand. This should ensure that all queries return running instances beforehand (saving some post-processing later too). As such, I'm removing an artifact of the old code where we were not doing this, which was basically to skip all running instances. Additionally, this will allow an operator to include non-running instances in a filter should this be desired for whatever reason.
This commit is contained in:
2 files changed
+2
-74
No files matched your search
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user