2018-02-08 04:23:05 +00:00
|
|
|
class AwsSubnets < Inspec.resource(1)
|
|
|
|
name 'aws_subnets'
|
2018-02-08 01:12:02 +00:00
|
|
|
desc 'Verifies settings for VPC Subnets in bulk'
|
|
|
|
example "
|
|
|
|
# you should be able to test the cidr_block of a subnet
|
2018-02-08 04:23:05 +00:00
|
|
|
describe aws_subnets.where(vpc_id: 'vpc-123456789') do
|
2018-02-08 01:12:02 +00:00
|
|
|
its('subnet_ids') { should eq ['subnet-12345678', 'subnet-87654321'] }
|
|
|
|
its('cidr_blocks') { should eq ['172.31.96.0/20'] }
|
|
|
|
its('states') { should_not include 'pending' }
|
|
|
|
end
|
|
|
|
"
|
2018-02-08 04:26:37 +00:00
|
|
|
supports platform: 'aws'
|
|
|
|
|
|
|
|
include AwsPluralResourceMixin
|
|
|
|
|
|
|
|
def validate_params(resource_params)
|
|
|
|
unless resource_params.empty?
|
|
|
|
raise ArgumentError, 'aws_vpc_subnets does not accept resource parameters.'
|
|
|
|
end
|
|
|
|
resource_params
|
|
|
|
end
|
2018-02-08 01:12:02 +00:00
|
|
|
|
2018-02-08 04:26:37 +00:00
|
|
|
def fetch_from_api
|
|
|
|
backend = BackendFactory.create(inspec_runner)
|
2018-02-08 01:12:02 +00:00
|
|
|
@table = backend.describe_subnets.subnets.map(&:to_h)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Underlying FilterTable implementation.
|
|
|
|
filter = FilterTable.create
|
|
|
|
filter.add_accessor(:where)
|
|
|
|
.add_accessor(:entries)
|
|
|
|
.add(:exists?) { |x| !x.entries.empty? }
|
|
|
|
.add(:vpc_ids, field: :vpc_id)
|
|
|
|
.add(:subnet_ids, field: :subnet_id)
|
|
|
|
.add(:cidr_blocks, field: :cidr_block)
|
|
|
|
.add(:states, field: :state)
|
2018-02-08 04:26:37 +00:00
|
|
|
filter.connect(self, :table)
|
2018-02-08 01:12:02 +00:00
|
|
|
|
|
|
|
def to_s
|
|
|
|
'EC2 VPC Subnets'
|
|
|
|
end
|
|
|
|
|
|
|
|
class Backend
|
2018-02-08 04:26:37 +00:00
|
|
|
class AwsClientApi < AwsBackendBase
|
2018-02-09 05:56:28 +00:00
|
|
|
BackendFactory.set_default_backend self
|
2018-02-08 04:26:37 +00:00
|
|
|
self.aws_client_class = Aws::EC2::Client
|
2018-02-08 01:12:02 +00:00
|
|
|
|
|
|
|
def describe_subnets(query = {})
|
2018-02-08 04:26:37 +00:00
|
|
|
aws_service_client.describe_subnets(query)
|
2018-02-08 01:12:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|