Class: Serverspec::Type::AWS::EC2::Subnet

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

Overview

The Subnet class exposes the EC2::Subnet resources

Instance Method Summary collapse

Constructor Details

#initialize(subnet_id, instance = nil) ⇒ Subnet

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

Parameters:

  • subnet_id (String)

    The ID of the Subnet

  • instance (Class) (defaults to: nil)

    Aws::EC2::Client instance

Raises:

  • (RuntimeError)

    if subnets.nil?

  • (RuntimeError)

    if subnets.length == 0

  • (RuntimeError)

    if subnets.length > 1



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

def initialize(subnet_id, instance = nil)
  check_init_arg 'subnet_id', 'EC2::Subnet', subnet_id
  @subnet_id = subnet_id
  @aws = instance.nil? ? Aws::EC2::Client.new : instance
  get_subnet subnet_id
end

Instance Method Details

#availability_zoneString

The Availability Zone of the subnet

Returns:

  • (String)


66
67
68
# File 'lib/resources/ec2/subnet.rb', line 66

def availability_zone
  @subnet.availability_zone
end

#available?Boolean

Indicates whether the state is available

Returns:

  • (Boolean)


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

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

#available_ip_address_countInteger

The number of unused IP addresses in the subnet. Note that the IP addresses for any stopped instances are considered unavailable

Returns:

  • (Integer)


60
61
62
# File 'lib/resources/ec2/subnet.rb', line 60

def available_ip_address_count
  @subnet.available_ip_address_count
end

#az_default?Boolean

Indicates whether this is the default subnet for the Availability Zone

Returns:

  • (Boolean)


35
36
37
# File 'lib/resources/ec2/subnet.rb', line 35

def az_default?
  @subnet.default_for_az
end

#cidr_blockString

The CIDR block assigned to the subnet

Returns:

  • (String)


53
54
55
# File 'lib/resources/ec2/subnet.rb', line 53

def cidr_block
  @subnet.cidr_block
end

#tagsArray(Hash)

Any tags assigned to the subnet

Returns:

  • (Array(Hash))


72
73
74
# File 'lib/resources/ec2/subnet.rb', line 72

def tags
  @subnet.tags
end

#to_sString

Returns the string representation of EC2::Subnet

Returns:

  • (String)


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

def to_s
  "EC2 Subnet: #{@subnet_id}"
end

#vpc_idString

The ID of the VPC the subnet is in

Returns:

  • (String)


47
48
49
# File 'lib/resources/ec2/subnet.rb', line 47

def vpc_id
  @subnet.vpc_id
end

#with_public_ip_on_launch?Boolean

Indicates whether instances launched in this subnet receive a public IP address

Returns:

  • (Boolean)


41
42
43
# File 'lib/resources/ec2/subnet.rb', line 41

def with_public_ip_on_launch?
  @subnet.map_public_ip_on_launch
end