<commit_before>require 'aws-sdk-core'

zones = ::Array.new
ec2 = ::Aws::EC2::Client.new
zones = ec2.describe_availability_zones.availability_zones.map(&:zone_name)

SparkleFormation.dynamic(:public_subnets) do |options = {}|
  route_table = options.fetch(:public_route_table, :default_ec2_route_table)

  parameters(:cidr_prefix) do
    type 'Number'
    min_value '16'
    max_value '31'
    default '16'
    description 'The prefix of the CIDR block to assign to the VPC (172.X.0.0/16)'
  end

  zones.each do |zone|
    subnet = ((zone[-1].ord - 'a'.ord) * 16).to_s

    dynamic!(:ec2_subnet, "#{zone.gsub('-', '_')}_public").properties do
      vpc_id ref!(:vpc)
      availability_zone zone
      cidr_block join!( join!( '172', ref!(:cidr_prefix), subnet, '0', {:options => {:delimiter => '.'}}), '20', {:options => {:delimiter => '/'}})
      map_public_ip_on_launch options.fetch(:map_public_ips, 'false')
      tags _array(
             -> {
               key 'Name'
               value join!('public', zone, '172', ref!(:cidr_prefix), subnet, '0/20', {:options => { :delimiter => '-' }})
             },
             -> {
               key 'Network'
               value 'Public'
             },
             -> {
               key 'Environment'
               value ENV['environment']
             }
           )
    end

    dynamic!(:ec2_subnet_route_table_association, "#{zone.gsub('-', '_')}_public").properties do
      subnet_id ref!("#{zone.gsub('-', '_')}_public_ec2_subnet".to_sym)
      route_table_id ref!(route_table)
    end
  end
end

SparkleFormation.dynamic(:private_subnets) do |options = {}|
  zones.each do |zone|
    subnet = (240 - ((zone[-1].ord - 'a'.ord) * 16)).to_s

    dynamic!(:ec2_route_table, "#{zone.gsub('-', '_')}_private").properties do
      vpc_id ref!(:vpc)
      tags _array(
        -> {
          key 'Name'
          value "#{zone.gsub('-', '_')}_private_route_table".to_sym
        }
      )
    end

    dynamic!(:ec2_subnet, "#{zone.gsub('-', '_')}_private").properties do
      vpc_id ref!(:vpc)
      availability_zone zone
      cidr_block join!( join!( '172', ref!(:cidr_prefix), subnet, '0', {:options => {:delimiter => '.'}}), '20', {:options => {:delimiter => '/'}})
      tags _array(
             -> {
               key 'Name'
               value join!('private', zone, '172', ref!(:cidr_prefix), subnet, '0/20', {:options => { :delimiter => '-' }})
             },
             -> {
               key 'Network'
               value 'Private'
             },
             -> {
               key 'Environment'
               value ENV['environment']
             }
           )
    end<commit_msg>Start supporting Kubernetes.  I may rip this out.<commit_after>require 'aws-sdk-core'

zones = ::Array.new
ec2 = ::Aws::EC2::Client.new
zones = ec2.describe_availability_zones.availability_zones.map(&:zone_name)

SparkleFormation.dynamic(:public_subnets) do |options = {}|
  route_table = options.fetch(:public_route_table, :default_ec2_route_table)

  parameters(:cidr_prefix) do
    type 'Number'
    min_value '16'
    max_value '31'
    default '16'
    description 'The prefix of the CIDR block to assign to the VPC (172.X.0.0/16)'
  end

  zones.each do |zone|
    subnet = ((zone[-1].ord - 'a'.ord) * 16).to_s

    dynamic!(:ec2_subnet, "#{zone.gsub('-', '_')}_public").properties do
      vpc_id ref!(:vpc)
      availability_zone zone
      cidr_block join!( join!( '172', ref!(:cidr_prefix), subnet, '0', {:options => {:delimiter => '.'}}), '20', {:options => {:delimiter => '/'}})
      map_public_ip_on_launch options.fetch(:map_public_ips, 'false')
      tags _array(
             -> {
               key 'Name'
               value join!('public', zone, '172', ref!(:cidr_prefix), subnet, '0/20', {:options => { :delimiter => '-' }})
             },
             -> {
               key 'Network'
               value 'Public'
             },
             -> {
               key 'Environment'
               value ENV['environment']
             }
           )
    end

    dynamic!(:ec2_subnet_route_table_association, "#{zone.gsub('-', '_')}_public").properties do
      subnet_id ref!("#{zone.gsub('-', '_')}_public_ec2_subnet".to_sym)
      route_table_id ref!(route_table)
    end
  end
end

SparkleFormation.dynamic(:private_subnets) do |options = {}|
  zones.each do |zone|
    subnet = (240 - ((zone[-1].ord - 'a'.ord) * 16)).to_s

    dynamic!(:ec2_route_table, "#{zone.gsub('-', '_')}_private").properties do
      vpc_id ref!(:vpc)
      tags _array(
        -> {
          key 'Name'
          value "#{zone.gsub('-', '_')}_private_route_table".to_sym
        }
      )
    end

    dynamic!(:ec2_subnet, "#{zone.gsub('-', '_')}_private").properties do
      vpc_id ref!(:vpc)
      availability_zone zone
      cidr_block join!( join!( '172', ref!(:cidr_prefix), subnet, '0', {:options => {:delimiter => '.'}}), '20', {:options => {:delimiter => '/'}})
      tags _array(
             -> {
               key 'Name'
               value join!('private', zone, '172', ref!(:cidr_prefix), subnet, '0/20', {:options => { :delimiter => '-' }})
             },
             -> {
               key 'Network'
               value 'Private'
             },
             -> {
               key 'Environment'
               value ENV['environment']
             },
             -> {
               key 'KubernetesCluster'
               value "k8s.#{ENV['public_domain']}"
             }
           )
    end
{'fraction_non_alphanumeric': 0.17485443959243085, 'fraction_numerical': 0.02019650655021834, 'mean_word_length': 2.0986471251409244, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1200999', 'n_tokens_mistral': 1886, 'n_tokens_neox': 1807, 'n_words': 348}