Sha256: 34435be399ebded108922004f9d6fa48a0f24dd840aae9848ed7b91b64439cbe

Contents?: true

Size: 1.57 KB

Versions: 3

Compression:

Stored size: 1.57 KB

Contents

class AwsRouteTable < Inspec.resource(1)
  name 'aws_route_table'
  desc 'Verifies settings for an AWS Route Table'
  example "
    describe aws_route_table do
      its('route_table_id') { should cmp 'rtb-2c60ec44' }
    end
  "
  supports platform: 'aws'

  include AwsSingularResourceMixin

  def to_s
    "Route Table #{@route_table_id}"
  end

  attr_reader :route_table_id, :vpc_id

  private

  def validate_params(raw_params)
    validated_params = check_resource_param_names(
      raw_params: raw_params,
      allowed_params: [:route_table_id],
      allowed_scalar_name: :route_table_id,
      allowed_scalar_type: String,
    )

    if validated_params.key?(:route_table_id) && validated_params[:route_table_id] !~ /^rtb\-[0-9a-f]{8}/
      raise ArgumentError, 'aws_route_table Route Table ID must be in the' \
       ' format "rtb-" followed by 8 hexadecimal characters.'
    end

    validated_params
  end

  def fetch_from_api
    backend = BackendFactory.create(inspec_runner)

    if @route_table_id.nil?
      args = nil
    else
      args = { filters: [{ name: 'route-table-id', values: [@route_table_id] }] }
    end

    resp = backend.describe_route_tables(args)
    routetable = resp.to_h[:route_tables]
    @exists = !routetable.empty?
  end

  class Backend
    class AwsClientApi < AwsBackendBase
      BackendFactory.set_default_backend(self)
      self.aws_client_class = Aws::EC2::Client

      def describe_route_tables(query)
        aws_service_client.describe_route_tables(query)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
inspec-2.1.10 lib/resources/aws/aws_route_table.rb
inspec-2.0.32 lib/resources/aws/aws_route_table.rb
inspec-2.0.17 lib/resources/aws/aws_route_table.rb