Class: Serverspec::Type::AWS::EC2::VPC

Inherits:
Base
  • Object
show all
Defined in:
lib/resources/ec2/vpc.rb

Overview

The VPC class exposes the EC2::VPC resources

Instance Method Summary collapse

Constructor Details

#initialize(vpc_id, instance = nil) ⇒ VPC

AWS SDK for Ruby v2 Aws::EC2::Client wrapper for initializing a VPC resource

Parameters:

  • vpc_id (String)

    The ID of the VPC

  • instance (Class) (defaults to: nil)

    Aws::EC2::Client instance

Raises:

  • (RuntimeError)

    if vpcs.nil?

  • (RuntimeError)

    if vpcs.length == 0

  • (RuntimeError)

    if vpcs.length > 1



15
16
17
18
19
20
# File 'lib/resources/ec2/vpc.rb', line 15

def initialize(vpc_id, instance = nil)
  check_init_arg 'vpc_id', 'EC2::VPC', vpc_id
  @vpc_id = vpc_id
  @aws = instance.nil? ? Aws::EC2::Client.new : instance
  get_vpc vpc_id
end

Instance Method Details

#available?Boolean

Indicates whether the state is available

Returns:

  • (Boolean)


29
30
31
# File 'lib/resources/ec2/vpc.rb', line 29

def available?
  @vpc.state == 'available'
end

#cidr_blockString

The CIDR block for the VPC

Returns:

  • (String)


45
46
47
# File 'lib/resources/ec2/vpc.rb', line 45

def cidr_block
  @vpc.cidr_block
end

#default?Boolean

Indicates whether the VPC is the default VPC

Returns:

  • (Boolean)


34
35
36
# File 'lib/resources/ec2/vpc.rb', line 34

def default?
  @vpc.is_default
end

#default_tenancy?Boolean

Indicates whether the instance_tenancy is default

Returns:

  • (Boolean)


39
40
41
# File 'lib/resources/ec2/vpc.rb', line 39

def default_tenancy?
  @vpc.instance_tenancy == 'default'
end

#dhcp_options_idString

The ID of the set of DHCP options you've associated with the VPC (or default if the default options are associated with the VPC)

Returns:

  • (String)


52
53
54
# File 'lib/resources/ec2/vpc.rb', line 52

def dhcp_options_id
  @vpc.dhcp_options_id
end

#subnetsObject

Get the subnets associated with the VPC



63
64
65
# File 'lib/resources/ec2/vpc.rb', line 63

def subnets
  Subnets.new Aws::EC2::Vpc.new(@vpc_id, client: @aws).subnets
end

#tagsArray(Hash)

Any tags assigned to the VPC

Returns:

  • (Array(Hash))


58
59
60
# File 'lib/resources/ec2/vpc.rb', line 58

def tags
  @vpc.tags
end

#to_sString

Returns the string representation of EC2::VPC

Returns:

  • (String)


24
25
26
# File 'lib/resources/ec2/vpc.rb', line 24

def to_s
  "EC2 VPC: #{@vpc_id}"
end