Puppet Function: stdlib_aws::subnet_id_to_cidr
- Defined in:
- lib/puppet/functions/stdlib_aws/subnet_id_to_cidr.rb
- Function type:
- Ruby 4.x API
Overview
Returns a CIDR address for a given AWS Subnet ID, by region. Uses default region when none is given.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/puppet/functions/stdlib_aws/subnet_id_to_cidr.rb', line 5 Puppet::Functions.create_function(:'stdlib_aws::subnet_id_to_cidr') do # Returns the correct IPv4 CIDR value for a given AWS subnet. # @param subnetid The AWS Subnet ID you wish to retrieve CIDR info for. # @param region Optionally, the region to use for subnet discovery. Will use default region for your AWS credentials if not supplied. # @return [String] Returns the CIDR-notation network info for a subnet, as a string. dispatch :cidr_from_subnet_id do param 'String', :subnetid optional_param 'String', :region return_type 'String' end def ec2_client(region) case region when nil Aws::EC2::Resource.new when String Aws::EC2::Resource.new({region: region}) end end def cidr_from_subnet_id(subnetid, region=nil) client = ec2_client(region) client.subnet(subnetid).cidr_block end end |