Module: Convection::DSL::Template::Resource::EC2VPC

Includes:
Convection::DSL::Template::Resource
Included in:
Model::Template::Resource::EC2VPC
Defined in:
lib/convection/model/template/resource/aws_ec2_vpc.rb

Overview

DSL For VPC sub-entities

Instance Method Summary collapse

Methods included from Convection::DSL::Template::Resource

attach_resource

Instance Method Details

#add_internet_gateway(&block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/convection/model/template/resource/aws_ec2_vpc.rb', line 14

def add_internet_gateway(&block)
  g = Model::Template::Resource::EC2InternetGateway.new("#{ name }IG", @template)
  g.attach_to_vpc(self)
  g.tag('Name', "#{ name }InternetGateway")

  g.instance_exec(&block) if block
  @template.resources[g.name] = g

  ## Store the gateway for later reference
  @internet_gateway = g
end

#add_network_acl(name, &block) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/convection/model/template/resource/aws_ec2_vpc.rb', line 26

def add_network_acl(name, &block)
  network_acl = Model::Template::Resource::EC2NetworkACL.new("#{ self.name }ACL#{ name }", @template)
  network_acl.vpc(self)
  network_acl.tag('Name', network_acl.name)

  network_acl.instance_exec(&block) if block
  @template.resources[network_acl.name] = network_acl
end

#add_route_table(name, options = {}, &block) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/convection/model/template/resource/aws_ec2_vpc.rb', line 35

def add_route_table(name, options = {}, &block)
  route_table = Model::Template::Resource::EC2RouteTable.new("#{ self.name }Table#{ name }", @template)
  route_table.vpc(self)
  route_table.tag('Name', route_table.name)

  route_table.instance_exec(&block) if block

  @template.resources[route_table.name] = route_table
  return route_table unless options[:gateway_route]

  ## Create and associate an InterntGateway
  add_internet_gateway if @internet_gateway.nil?

  ## Create a route to the VPC's InternetGateway
  vpc_default_route = route_table.route('Default')
  vpc_default_route.destination('0.0.0.0/0')
  vpc_default_route.gateway(@internet_gateway)

  route_table
end

#add_subnet(name, &block) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/convection/model/template/resource/aws_ec2_vpc.rb', line 56

def add_subnet(name, &block)
  s = Model::Template::Resource::EC2Subnet.new("#{ self.name }Subnet#{ name }", @template)
  s.tag('Name', s.name)
  s.vpc(self)

  ## Allocate the next available subnet
  @subnet_allocated += 1
  subnets = network.subnet(:Bits => @subnet_length,
                           :NumSubnets => @subnet_allocated)
  s.network(subnets[@subnet_allocated - 1])

  s.instance_exec(&block) if block
  @template.resources[s.name] = s
end