Class: AwsEc2Instances

Inherits:
Object
  • Object
show all
Includes:
AwsPluralResourceMixin
Defined in:
lib/resources/aws/aws_ec2_instances.rb

Defined Under Namespace

Classes: Backend

Instance Attribute Summary

Attributes included from AwsPluralResourceMixin

#table

Instance Method Summary collapse

Methods included from AwsPluralResourceMixin

included

Methods included from AwsResourceMixin

#catch_aws_errors, #check_resource_param_names, #initialize, #inspec_runner

Instance Method Details

#fetch_from_apiObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/resources/aws/aws_ec2_instances.rb', line 34

def fetch_from_api
  backend = BackendFactory.create(inspec_runner)
  @table = []
  pagination_opts = {}
  loop do
    api_result = backend.describe_instances(pagination_opts)
    @table += unpack_describe_instances_response(api_result.reservations)
    break unless api_result.next_token

    pagination_opts = { next_token: api_result.next_token }
  end
end

#to_sObject



30
31
32
# File 'lib/resources/aws/aws_ec2_instances.rb', line 30

def to_s
  "EC2 Instances"
end

#unpack_describe_instances_response(reservations) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/resources/aws/aws_ec2_instances.rb', line 47

def unpack_describe_instances_response(reservations)
  instance_rows = []
  reservations.each do |res|
    instance_rows += res.instances.map do |instance_struct|
      {
        instance_id: instance_struct.instance_id,
      }
    end
  end
  instance_rows
end

#validate_params(resource_params) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/resources/aws/aws_ec2_instances.rb', line 16

def validate_params(resource_params)
  unless resource_params.empty?
    raise ArgumentError, "aws_ec2_instances does not accept resource parameters."
  end

  resource_params
end