Class: Stacco::Template::Base

Inherits:
Stacco::Template show all
Defined in:
lib/stacco/template/base.rb

Constant Summary

Constants inherited from Stacco::Template

AttachmentTypes

Instance Method Summary collapse

Methods inherited from Stacco::Template

#attach, #export_for_json, #mapping, #parameter, #render, #resource, #to_json, #udscript

Constructor Details

#initializeBase

Returns a new instance of Base.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/stacco/template/base.rb', line 26

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

Instance Method Details

#cloudfront_hosted_zone_mapObject



4
5
6
# File 'lib/stacco/template/base.rb', line 4

def cloudfront_hosted_zone_map
  {"us-west-2" => {"HostedZoneId" => "Z2FDTNDATAQYW2"}}
end

#ubuntu_daily_ami_map(want_release, *args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/stacco/template/base.rb', line 8

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