lib/cfgen.rb
#this method prepares the subnets from template
this method prepares the subnets from template
this method prepares the subnets from template
def prepare_subnet(subnet, vpc_name, subnet_ip, cidr, az_list)
      cidr_bits = 32-cidr.to_i
      subnet_new = deep_copy(subnet)
      subnet_old = deep_copy(subnet['Resources']['mySubnet'])
      az_count = 0;
      for x in 0..2
        subnet_name = "Subnet#{x+1}"
        subnet_new['Resources'][subnet_name] = deep_copy(subnet_old)
        subnet_new['Resources'].delete("mySubnet")
        subnet_new['Resources'][subnet_name]['Properties']['VpcId']['Ref'] = vpc_name
        subnet_new['Resources'][subnet_name]['Properties']['CidrBlock']['Fn::Select'][0] = x
        subnet_new['Resources'][subnet_name]['Properties']['CidrBlock']['Fn::Select'][1]["Fn::Cidr"][0] = subnet_ip
        subnet_new['Resources'][subnet_name]['Properties']['CidrBlock']['Fn::Select'][1]["Fn::Cidr"][2] = cidr_bits
        subnet_new['Resources'][subnet_name]['Properties']['AvailabilityZone'] = az_list[az_count]
        subnet_new['Resources'][subnet_name]['Properties']['Tags'][0]["Value"] = subnet_name
        az_count = az_count < (az_list.length-1) ? (az_count = az_count + 1) : (az_count = 0)
      end
      subnet_new
    end
def prepare_subnet ( subnet , vpc_name , subnet_ip , cidr , az_list ) cidr_bits = 32 - cidr . to_i subnet_new = deep_copy ( subnet ) subnet_old = deep_copy ( subnet [ 'Resources' ] [ 'mySubnet' ] ) az_count = 0 ; for x in 0 .. 2 subnet_name = "Subnet#{x+1}" subnet_new [ 'Resources' ] [ subnet_name ] = deep_copy ( subnet_old ) subnet_new [ 'Resources' ] . delete ( "mySubnet" ) subnet_new [ 'Resources' ] [ subnet_name ] [ 'Properties' ] [ 'VpcId' ] [ 'Ref' ] = vpc_name subnet_new [ 'Resources' ] [ subnet_name ] [ 'Properties' ] [ 'CidrBlock' ] [ 'Fn::Select' ] [ 0 ] = x subnet_new [ 'Resources' ] [ subnet_name ] [ 'Properties' ] [ 'CidrBlock' ] [ 'Fn::Select' ] [ 1 ] [ "Fn::Cidr" ] [ 0 ] = subnet_ip subnet_new [ 'Resources' ] [ subnet_name ] [ 'Properties' ] [ 'CidrBlock' ] [ 'Fn::Select' ] [ 1 ] [ "Fn::Cidr" ] [ 2 ] = cidr_bits subnet_new [ 'Resources' ] [ subnet_name ] [ 'Properties' ] [ 'AvailabilityZone' ] = az_list [ az_count ] subnet_new [ 'Resources' ] [ subnet_name ] [ 'Properties' ] [ 'Tags' ] [ 0 ] [ "Value" ] = subnet_name az_count = az_count < ( az_list . length - 1 ) ? ( az_count = az_count + 1 ) : ( az_count = 0 ) end subnet_new end
this method prepares the subnets from template
this method prepares the subnets from template
#calculate cidr bits, #TODO calculate number of subnets available #clone #assign the values accordingly #count according to number of az's in region
subnet
vpc_name
subnet_ip
cidr
az_list