require 'stacco/template' class Stacco::Template::Base < Stacco::Template def cloudfront_hosted_zone_map {"us-west-2" => {"HostedZoneId" => "Z2FDTNDATAQYW2"}} end def ubuntu_daily_ami_map(want_release, *args) wants = [args.include?(:amd64), args.include?(:hvm), args.include?(:instance_store)] ami_map = {} doc = Nokogiri::XML.parse(open("https://cloud-images.ubuntu.com/rss/#{want_release}-Daily.xml")) Nokogiri::HTML.parse(doc.xpath("//item").sort_by{ |it| Time.strptime(it.css("pubDate").text, "%a, %b %d %H:%M:%S %Z %Y") }.last.css('description').children[0].text).xpath('//p')[1].children.find_all{ |el| el.text? }[1..-1].each do |ln| region, ami, arch, storage = ln.text.strip.split("\t") is_hvm = storage.include?("hvm") is_instance_store = storage.include?("instance") is_sixtyfourbit = (arch == 'amd64') next unless [is_sixtyfourbit, is_hvm, is_instance_store] == wants ami_map[region] = {"AMI" => ami} end ami_map end def initialize super mapping [:ec2, :AMIsByRegion], ubuntu_daily_ami_map('trusty', :amd64) mapping [:cloud_front, :hosted_zones_by_region], cloudfront_hosted_zone_map parameter StackVar[:domain], :string, min_length: 5, max_length: 256 parameter StackVar[:environment], :string, allowed_values: [:production, :staging, :development] parameter StackVar[:hosted_zone], :string, min_length: 13, max_length: 16, allowed_pattern: /[A-Z0-9]+/ parameter StackVar[:keypair], :string, min_length: 1, max_length: 256, allowed_pattern: /[-a-z0-9]+/ parameter Var[:ec2, :common_user_data], :string vpc = resource Type[:ec2, :vpc], cidr_block: '10.100.0.0/16', instance_tenancy: 'default', enable_dns_support: true, enable_dns_hostnames: true internet_gateway = resource Type[:ec2, :internet_gateway] dhcp_options = resource Type[:ec2, :dhcp_options], domain_name: StackVar[:domain], domain_name_servers: [:amazon_provided_dns] attach vpc, internet_gateway attach vpc, dhcp_options end end