class AWS::EC2::SubnetCollection


subnet = subnets.filter(‘state’, ‘available’).first
(docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeSubnets.html) for a complete list of accepted filters.
You can filter subnets as well. See the EC2 API documentation
subnet = subnets[‘subnet-id-here’]

If you know the subnet id, you can get a subnet using {#[]}.
## Getting a Subnet
created in.
You can optionally pass the availability zone you want the subnet
subnet = subnets.create(‘10.0.0.0/20’)
a suitable CIDR block.
To create a subnet, call {#create} on a subnet collection, passing in
## Creating a Subnet
subnets = ec2.vpcs.subnets
# represents subnets within the named vpc
subnets = ec2.subnets
# represents all subnets
subnets within a single vpc.
all your VPCs). You can also get a subnet collection that represents
two ways. You can get a collection that represents ALL subnets (across
Represents a collection of VPC subnets. You can get a subnet collection

def [] subnet_id

Returns:
  • (Subnet) - Returns a subnet with the given id.

Parameters:
  • subnet_id (String) --
def [] subnet_id
  Subnet.new(subnet_id, :config => config)
end

def _each_item options = {}, &block

def _each_item options = {}, &block
  response = filtered_request(:describe_subnets, options, &block)
  response.subnet_set.each do |s|
    subnet = Subnet.new_from(:describe_subnets,
      s, s.subnet_id, :config => config)
    yield(subnet)
  end
end

def az_option options

def az_option options
  options[:availability_zone].is_a?(AvailabilityZone) ?
    options[:availability_zone].name :
    options[:availability_zone]
end

def create cidr_block, options = {}

Returns:
  • (Subnet) -

Options Hash: (**options)
  • :availability_zone (String, AvailabilityZone) --
  • :vpc (VPC, String) -- The VPC (or VPC id string) to

Parameters:
  • options (Hash) --
  • cidr_block (String) -- The CIDR block you want the subnet to
def create cidr_block, options = {}
  client_opts = {}
  client_opts[:vpc_id] = vpc_id_option(options)
  client_opts[:cidr_block] = cidr_block
  client_opts[:availability_zone] = az_option(options) if
    options[:availability_zone]
  resp = client.create_subnet(client_opts)
  Subnet.new_from(:create_subnet, resp.subnet,
    resp.subnet.subnet_id, :config => config)
end