convection 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rubocop.yml +16 -0
- data/Gemfile +4 -0
- data/LICENSE +23 -0
- data/README.md +224 -0
- data/Rakefile +2 -0
- data/Thorfile +5 -0
- data/convection.gemspec +27 -0
- data/example/iam_role.rb +63 -0
- data/example/s3.rb +13 -0
- data/example/vpc.rb +85 -0
- data/lib/convection.rb +18 -0
- data/lib/convection/control/stack.rb +165 -0
- data/lib/convection/dsl/helpers.rb +15 -0
- data/lib/convection/dsl/intrinsic_functions.rb +79 -0
- data/lib/convection/model/mixin/cidr_block.rb +17 -0
- data/lib/convection/model/mixin/conditional.rb +21 -0
- data/lib/convection/model/mixin/taggable.rb +48 -0
- data/lib/convection/model/template.rb +127 -0
- data/lib/convection/model/template/mapping.rb +42 -0
- data/lib/convection/model/template/output.rb +37 -0
- data/lib/convection/model/template/parameter.rb +44 -0
- data/lib/convection/model/template/resource.rb +64 -0
- data/lib/convection/model/template/resource/aws_ec2_instance.rb +69 -0
- data/lib/convection/model/template/resource/aws_ec2_internet_gateway.rb +55 -0
- data/lib/convection/model/template/resource/aws_ec2_route.rb +55 -0
- data/lib/convection/model/template/resource/aws_ec2_route_table.rb +60 -0
- data/lib/convection/model/template/resource/aws_ec2_security_group.rb +104 -0
- data/lib/convection/model/template/resource/aws_ec2_subnet.rb +66 -0
- data/lib/convection/model/template/resource/aws_ec2_subnet_route_table_association.rb +39 -0
- data/lib/convection/model/template/resource/aws_ec2_vpc.rb +116 -0
- data/lib/convection/model/template/resource/aws_ec2_vpc_gateway_attachment.rb +43 -0
- data/lib/convection/model/template/resource/aws_iam_policy.rb +45 -0
- data/lib/convection/model/template/resource/aws_iam_role.rb +45 -0
- data/lib/convection/model/template/resource/aws_s3_bucket.rb +67 -0
- data/lib/convection/model/template/resource/aws_s3_bucket_policy.rb +40 -0
- data/lib/convection/version.rb +6 -0
- metadata +375 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
require_relative '../../dsl/intrinsic_functions'
|
2
|
+
|
3
|
+
module Convection
|
4
|
+
module Model
|
5
|
+
##
|
6
|
+
# Hash with auto-generating sparse keys
|
7
|
+
##
|
8
|
+
class Smash < Hash
|
9
|
+
def initialize(*args)
|
10
|
+
super do |hash, key|
|
11
|
+
hash[key] = Smash.new
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Template
|
17
|
+
##
|
18
|
+
# Mapping
|
19
|
+
##
|
20
|
+
class Mapping
|
21
|
+
include DSL::IntrinsicFunctions
|
22
|
+
|
23
|
+
attr_reader :items
|
24
|
+
|
25
|
+
def initialize(name, template)
|
26
|
+
@name = name
|
27
|
+
@template = template
|
28
|
+
|
29
|
+
@items = Smash.new
|
30
|
+
end
|
31
|
+
|
32
|
+
def item(key_1, key_2, value)
|
33
|
+
items[key_1][key_2] = value
|
34
|
+
end
|
35
|
+
|
36
|
+
def render
|
37
|
+
items
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative '../../dsl/intrinsic_functions'
|
2
|
+
require_relative '../mixin/conditional'
|
3
|
+
|
4
|
+
module Convection
|
5
|
+
module Model
|
6
|
+
class Template
|
7
|
+
##
|
8
|
+
# Resource
|
9
|
+
##
|
10
|
+
class Output
|
11
|
+
extend DSL::Helpers
|
12
|
+
include DSL::IntrinsicFunctions
|
13
|
+
include Model::Mixin::Conditional
|
14
|
+
|
15
|
+
attribute :value
|
16
|
+
attribute :description
|
17
|
+
|
18
|
+
def initialize(name, template)
|
19
|
+
@name = name
|
20
|
+
@template = template
|
21
|
+
|
22
|
+
@type = ''
|
23
|
+
@properties = {}
|
24
|
+
end
|
25
|
+
|
26
|
+
def render
|
27
|
+
{
|
28
|
+
'Value' => value,
|
29
|
+
'Description' => description
|
30
|
+
}.tap do |resource|
|
31
|
+
render_condition(resource)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative '../../dsl/intrinsic_functions'
|
2
|
+
|
3
|
+
module Convection
|
4
|
+
module Model
|
5
|
+
class Template
|
6
|
+
##
|
7
|
+
# Template Parameter
|
8
|
+
##
|
9
|
+
class Parameter
|
10
|
+
extend DSL::Helpers
|
11
|
+
include DSL::IntrinsicFunctions
|
12
|
+
|
13
|
+
attribute :type
|
14
|
+
attribute :default
|
15
|
+
attribute :description
|
16
|
+
attr_reader :allowed_values
|
17
|
+
|
18
|
+
def initialize(name, template)
|
19
|
+
@name = name
|
20
|
+
@template = template
|
21
|
+
|
22
|
+
@type = 'String'
|
23
|
+
@default = ''
|
24
|
+
@allowed_values = []
|
25
|
+
@description = ''
|
26
|
+
end
|
27
|
+
|
28
|
+
def allow(value)
|
29
|
+
allowed_values << value
|
30
|
+
end
|
31
|
+
|
32
|
+
def render
|
33
|
+
{
|
34
|
+
'Type' => type,
|
35
|
+
'Default' => default,
|
36
|
+
'Description' => description
|
37
|
+
}.tap do |resource|
|
38
|
+
resource['AllowedValues'] = allowed_values unless allowed_values.empty?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require_relative '../../dsl/intrinsic_functions'
|
2
|
+
require_relative '../mixin/cidr_block'
|
3
|
+
require_relative '../mixin/conditional'
|
4
|
+
require_relative '../mixin/taggable'
|
5
|
+
|
6
|
+
module Convection
|
7
|
+
module Model
|
8
|
+
class Template
|
9
|
+
##
|
10
|
+
# Resource
|
11
|
+
##
|
12
|
+
class Resource
|
13
|
+
extend DSL::Helpers
|
14
|
+
include DSL::IntrinsicFunctions
|
15
|
+
include Model::Mixin::Conditional
|
16
|
+
|
17
|
+
attribute :type
|
18
|
+
attr_reader :name
|
19
|
+
attr_reader :properties
|
20
|
+
|
21
|
+
def initialize(name, template)
|
22
|
+
@name = name
|
23
|
+
@template = template
|
24
|
+
|
25
|
+
@type = ''
|
26
|
+
@properties = {}
|
27
|
+
end
|
28
|
+
|
29
|
+
def property(key, value)
|
30
|
+
properties[key] = value.is_a?(Model::Template::Resource) ? value.reference : value
|
31
|
+
end
|
32
|
+
|
33
|
+
def reference
|
34
|
+
{
|
35
|
+
'Ref' => name
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def render
|
40
|
+
{
|
41
|
+
'Type' => type,
|
42
|
+
'Properties' => properties
|
43
|
+
}.tap do |resource|
|
44
|
+
render_condition(resource)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
require_relative 'resource/aws_ec2_instance'
|
53
|
+
require_relative 'resource/aws_ec2_internet_gateway'
|
54
|
+
require_relative 'resource/aws_ec2_route'
|
55
|
+
require_relative 'resource/aws_ec2_route_table'
|
56
|
+
require_relative 'resource/aws_ec2_security_group'
|
57
|
+
require_relative 'resource/aws_ec2_subnet'
|
58
|
+
require_relative 'resource/aws_ec2_subnet_route_table_association'
|
59
|
+
require_relative 'resource/aws_ec2_vpc'
|
60
|
+
require_relative 'resource/aws_ec2_vpc_gateway_attachment'
|
61
|
+
require_relative 'resource/aws_s3_bucket'
|
62
|
+
require_relative 'resource/aws_s3_bucket_policy'
|
63
|
+
require_relative 'resource/aws_iam_role'
|
64
|
+
require_relative 'resource/aws_iam_policy'
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require_relative '../resource'
|
2
|
+
|
3
|
+
module Convection
|
4
|
+
module Model
|
5
|
+
class Template
|
6
|
+
class Resource
|
7
|
+
##
|
8
|
+
# AWS::EC2::Instance
|
9
|
+
##
|
10
|
+
class EC2Instance < Resource
|
11
|
+
include Model::Mixin::Taggable
|
12
|
+
|
13
|
+
def initialize(*args)
|
14
|
+
super
|
15
|
+
|
16
|
+
type 'AWS::EC2::Instance'
|
17
|
+
@properties['SecurityGroupIds'] = []
|
18
|
+
end
|
19
|
+
|
20
|
+
def availability_zone(value)
|
21
|
+
property('AvailabilityZone', value)
|
22
|
+
end
|
23
|
+
|
24
|
+
def image_id(value)
|
25
|
+
property('ImageId', value)
|
26
|
+
end
|
27
|
+
|
28
|
+
def instance_type(value)
|
29
|
+
property('InstanceType', value)
|
30
|
+
end
|
31
|
+
|
32
|
+
def key_name(value)
|
33
|
+
property('KeyName', value)
|
34
|
+
end
|
35
|
+
|
36
|
+
def security_group(value)
|
37
|
+
@properties['SecurityGroupIds'] << value
|
38
|
+
end
|
39
|
+
|
40
|
+
def subnet(value)
|
41
|
+
property('SubnetId', value)
|
42
|
+
end
|
43
|
+
|
44
|
+
def user_data(value)
|
45
|
+
property('UserData', value)
|
46
|
+
end
|
47
|
+
|
48
|
+
def render(*args)
|
49
|
+
super.tap do |resource|
|
50
|
+
render_tags(resource)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
module DSL
|
59
|
+
## Add DSL method to template namespace
|
60
|
+
module Template
|
61
|
+
def ec2_instance(name, &block)
|
62
|
+
r = Model::Template::Resource::EC2Instance.new(name, self)
|
63
|
+
|
64
|
+
r.instance_exec(&block) if block
|
65
|
+
resources[name] = r
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative '../resource'
|
2
|
+
|
3
|
+
module Convection
|
4
|
+
module DSL
|
5
|
+
## Add DSL method to template namespace
|
6
|
+
module Template
|
7
|
+
def ec2_internet_gateway(name, &block)
|
8
|
+
r = Model::Template::Resource::EC2InternetGateway.new(name, self)
|
9
|
+
|
10
|
+
r.instance_exec(&block) if block
|
11
|
+
resources[name] = r
|
12
|
+
end
|
13
|
+
|
14
|
+
module Resource
|
15
|
+
##
|
16
|
+
# Add DSL for VPCGatewayAttachment
|
17
|
+
module EC2InternetGateway
|
18
|
+
def attach_to_vpc(vpc, &block)
|
19
|
+
a = Model::Template::Resource::EC2VPCGatewayAttachment.new("#{ name }VPCAttachment#{ vpc.name }", self)
|
20
|
+
a.vpc_id(vpc)
|
21
|
+
a.internet_gateway(self)
|
22
|
+
|
23
|
+
a.instance_exec(&block) if block
|
24
|
+
@template.resources[a.name] = a
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module Model
|
32
|
+
class Template
|
33
|
+
class Resource
|
34
|
+
##
|
35
|
+
# AWS::EC2::InternetGateway
|
36
|
+
##
|
37
|
+
class EC2InternetGateway < Resource
|
38
|
+
include Model::Mixin::Taggable
|
39
|
+
include DSL::Template::Resource::EC2InternetGateway
|
40
|
+
|
41
|
+
def initialize(*args)
|
42
|
+
super
|
43
|
+
type 'AWS::EC2::InternetGateway'
|
44
|
+
end
|
45
|
+
|
46
|
+
def render(*args)
|
47
|
+
super.tap do |resource|
|
48
|
+
render_tags(resource)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative '../resource'
|
2
|
+
|
3
|
+
module Convection
|
4
|
+
module Model
|
5
|
+
class Template
|
6
|
+
class Resource
|
7
|
+
##
|
8
|
+
# AWS::EC2::Route
|
9
|
+
##
|
10
|
+
class EC2Route < Resource
|
11
|
+
def initialize(*args)
|
12
|
+
super
|
13
|
+
type 'AWS::EC2::Route'
|
14
|
+
end
|
15
|
+
|
16
|
+
def route_table_id(value)
|
17
|
+
property('RouteTableId', value)
|
18
|
+
end
|
19
|
+
|
20
|
+
def destination(value)
|
21
|
+
property('DestinationCidrBlock', value)
|
22
|
+
end
|
23
|
+
|
24
|
+
def gateway(value)
|
25
|
+
property('GatewayId', value)
|
26
|
+
end
|
27
|
+
|
28
|
+
def instance(value)
|
29
|
+
property('InstanceId', value)
|
30
|
+
end
|
31
|
+
|
32
|
+
def interface(value)
|
33
|
+
property('NetworkInterfaceId', value)
|
34
|
+
end
|
35
|
+
|
36
|
+
def peer(value)
|
37
|
+
property('VpcPeeringConnectionId', value)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module DSL
|
45
|
+
## Add DSL method to template namespace
|
46
|
+
module Template
|
47
|
+
def ec2_route(name, &block)
|
48
|
+
r = Model::Template::Resource::EC2Route.new(name, self)
|
49
|
+
|
50
|
+
r.instance_exec(&block) if block
|
51
|
+
resources[name] = r
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require_relative '../resource'
|
2
|
+
|
3
|
+
module Convection
|
4
|
+
|
5
|
+
module DSL
|
6
|
+
## Add DSL method to template namespace
|
7
|
+
module Template
|
8
|
+
def ec2_route_table(name, &block)
|
9
|
+
r = Model::Template::Resource::EC2RouteTable.new(name, self)
|
10
|
+
|
11
|
+
r.instance_exec(&block) if block
|
12
|
+
resources[name] = r
|
13
|
+
end
|
14
|
+
|
15
|
+
module Resource
|
16
|
+
##
|
17
|
+
# DSL For routes
|
18
|
+
##
|
19
|
+
module EC2RouteTable
|
20
|
+
def route(name, &block)
|
21
|
+
r = Model::Template::Resource::EC2Route.new("#{ self.name }Route#{ name }", @template)
|
22
|
+
r.route_table_id(reference)
|
23
|
+
|
24
|
+
r.instance_exec(&block) if block
|
25
|
+
@template.resources[r.name] = r
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module Model
|
33
|
+
class Template
|
34
|
+
class Resource
|
35
|
+
##
|
36
|
+
# AWS::EC2::RouteTable
|
37
|
+
##
|
38
|
+
class EC2RouteTable < Resource
|
39
|
+
include DSL::Template::Resource::EC2RouteTable
|
40
|
+
include Model::Mixin::Taggable
|
41
|
+
|
42
|
+
def initialize(*args)
|
43
|
+
super
|
44
|
+
type 'AWS::EC2::RouteTable'
|
45
|
+
end
|
46
|
+
|
47
|
+
def vpc_id(value)
|
48
|
+
property('VpcId', value)
|
49
|
+
end
|
50
|
+
|
51
|
+
def render(*args)
|
52
|
+
super.tap do |resource|
|
53
|
+
render_tags(resource)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require_relative '../resource'
|
2
|
+
|
3
|
+
module Convection
|
4
|
+
module DSL
|
5
|
+
## Add DSL method to template namespace
|
6
|
+
module Template
|
7
|
+
def ec2_security_group(name, &block)
|
8
|
+
r = Model::Template::Resource::EC2SecurityGroup.new(name, self)
|
9
|
+
|
10
|
+
r.instance_exec(&block) if block
|
11
|
+
resources[name] = r
|
12
|
+
end
|
13
|
+
|
14
|
+
module Resource
|
15
|
+
##
|
16
|
+
# DSL For EC2SecurityGroup rules
|
17
|
+
##
|
18
|
+
module EC2SecurityGroup
|
19
|
+
def ingress_rule(&block)
|
20
|
+
r = Model::Template::Resource::EC2SecurityGroup::Rule.new("#{ name }IngressGroupRule", @template)
|
21
|
+
r.instance_exec(&block) if block
|
22
|
+
|
23
|
+
security_group_ingress << r
|
24
|
+
end
|
25
|
+
|
26
|
+
def egress_rule(&block)
|
27
|
+
r = Model::Template::Resource::EC2SecurityGroup::Rule.new("#{ name }EgressGroupRule", @template)
|
28
|
+
r.instance_exec(&block) if block
|
29
|
+
|
30
|
+
security_group_egress << r
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module Model
|
38
|
+
class Template
|
39
|
+
class Resource
|
40
|
+
##
|
41
|
+
# AWS::EC2::SecurityGroup
|
42
|
+
##
|
43
|
+
class EC2SecurityGroup < Resource
|
44
|
+
include DSL::Template::Resource::EC2SecurityGroup
|
45
|
+
include Model::Mixin::Taggable
|
46
|
+
|
47
|
+
attr_reader :security_group_ingress
|
48
|
+
attr_reader :security_group_egress
|
49
|
+
|
50
|
+
##
|
51
|
+
# Ingress/Egress Rule
|
52
|
+
#
|
53
|
+
class Rule < Resource
|
54
|
+
attribute :from
|
55
|
+
attribute :to
|
56
|
+
attribute :protocol
|
57
|
+
|
58
|
+
attribute :cidr_ip
|
59
|
+
attribute :destination_group
|
60
|
+
attribute :source_group
|
61
|
+
attribute :source_group_owner
|
62
|
+
|
63
|
+
def render
|
64
|
+
{
|
65
|
+
'IpProtocol' => protocol,
|
66
|
+
'FromPort' => from,
|
67
|
+
'ToPort' => to
|
68
|
+
}.tap do |rule|
|
69
|
+
rule['CidrIp'] = cidr_ip unless cidr_ip.nil?
|
70
|
+
rule['DestinationSecurityGroupId'] = destination_group unless destination_group.nil?
|
71
|
+
rule['SourceSecurityGroupId'] = source_group unless source_group.nil?
|
72
|
+
rule['SourceSecurityGroupOwnerId'] = source_group_owner unless source_group.nil?
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def initialize(*args)
|
78
|
+
super
|
79
|
+
|
80
|
+
type 'AWS::EC2::SecurityGroup'
|
81
|
+
@security_group_ingress = []
|
82
|
+
@security_group_egress = []
|
83
|
+
end
|
84
|
+
|
85
|
+
def description(value)
|
86
|
+
property('GroupDescription', value)
|
87
|
+
end
|
88
|
+
|
89
|
+
def vpc_id(value)
|
90
|
+
property('VpcId', value)
|
91
|
+
end
|
92
|
+
|
93
|
+
def render(*args)
|
94
|
+
super.tap do |resource|
|
95
|
+
resource['Properties']['SecurityGroupIngress'] = security_group_ingress.map(&:render)
|
96
|
+
resource['Properties']['SecurityGroupEgress'] = security_group_egress.map(&:render)
|
97
|
+
render_tags(resource)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|