convection 0.0.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +26 -8
  4. data/.rubocop_todo.yml +77 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +10 -0
  7. data/Gemfile +9 -0
  8. data/README.md +27 -2
  9. data/Rakefile +11 -1
  10. data/bin/convection +49 -0
  11. data/convection.gemspec +5 -7
  12. data/example/.ruby-version +1 -0
  13. data/example/Cloudfile +13 -0
  14. data/example/deprecated/elb.rb +27 -0
  15. data/example/deprecated/iam_access_key.rb +18 -0
  16. data/example/deprecated/iam_group.rb +31 -0
  17. data/example/{iam_role.rb → deprecated/iam_role.rb} +21 -32
  18. data/example/deprecated/iam_user.rb +31 -0
  19. data/example/deprecated/rds.rb +70 -0
  20. data/example/{s3.rb → deprecated/s3.rb} +0 -0
  21. data/example/deprecated/sqs.rb +32 -0
  22. data/example/deprecated/vpc.rb +85 -0
  23. data/example/foobar.rb +22 -0
  24. data/example/output/vpc.json +335 -0
  25. data/example/security-groups.rb +40 -0
  26. data/example/trust_cloudtrail.rb +24 -0
  27. data/example/vpc.rb +63 -81
  28. data/ext/resource_generator.sh +21 -0
  29. data/lib/convection.rb +5 -4
  30. data/lib/convection/control/cloud.rb +59 -0
  31. data/lib/convection/control/stack.rb +261 -60
  32. data/lib/convection/dsl/helpers.rb +63 -5
  33. data/lib/convection/model/attributes.rb +60 -0
  34. data/lib/convection/model/cloudfile.rb +58 -0
  35. data/lib/convection/model/diff.rb +39 -0
  36. data/lib/convection/model/event.rb +62 -0
  37. data/lib/convection/model/exceptions.rb +18 -0
  38. data/lib/convection/model/mixin/cidr_block.rb +4 -4
  39. data/lib/convection/model/mixin/colorize.rb +20 -0
  40. data/lib/convection/model/mixin/conditional.rb +1 -3
  41. data/lib/convection/model/mixin/policy.rb +89 -0
  42. data/lib/convection/model/mixin/protocol.rb +29 -0
  43. data/lib/convection/model/mixin/taggable.rb +2 -2
  44. data/lib/convection/model/template.rb +248 -21
  45. data/lib/convection/model/template/condition.rb +56 -0
  46. data/lib/convection/model/template/mapping.rb +4 -3
  47. data/lib/convection/model/template/output.rb +9 -7
  48. data/lib/convection/model/template/parameter.rb +19 -4
  49. data/lib/convection/model/template/resource.rb +317 -23
  50. data/lib/convection/model/template/resource/aws_auto_scaling_auto_scaling_group.rb +39 -0
  51. data/lib/convection/model/template/resource/aws_auto_scaling_launch_configuration.rb +30 -0
  52. data/lib/convection/model/template/resource/aws_auto_scaling_scaling_policy.rb +20 -0
  53. data/lib/convection/model/template/resource/aws_cloud_watch_alarm.rb +31 -0
  54. data/lib/convection/model/template/resource/aws_ec2_instance.rb +10 -46
  55. data/lib/convection/model/template/resource/aws_ec2_internet_gateway.rb +3 -14
  56. data/lib/convection/model/template/resource/aws_ec2_network_acl.rb +45 -0
  57. data/lib/convection/model/template/resource/aws_ec2_network_acl_entry.rb +27 -0
  58. data/lib/convection/model/template/resource/aws_ec2_route.rb +7 -40
  59. data/lib/convection/model/template/resource/aws_ec2_route_table.rb +2 -17
  60. data/lib/convection/model/template/resource/aws_ec2_security_group.rb +24 -30
  61. data/lib/convection/model/template/resource/aws_ec2_security_group_ingres.rb +25 -0
  62. data/lib/convection/model/template/resource/aws_ec2_subnet.rb +21 -28
  63. data/lib/convection/model/template/resource/aws_ec2_subnet_network_acl_association.rb +18 -0
  64. data/lib/convection/model/template/resource/aws_ec2_subnet_route_table_association.rb +3 -24
  65. data/lib/convection/model/template/resource/aws_ec2_vpc.rb +20 -22
  66. data/lib/convection/model/template/resource/aws_ec2_vpc_gateway_attachment.rb +4 -28
  67. data/lib/convection/model/template/resource/aws_elasticache_cluster.rb +24 -0
  68. data/lib/convection/model/template/resource/aws_elasticache_parameter_group.rb +19 -0
  69. data/lib/convection/model/template/resource/aws_elasticache_security_group.rb +17 -0
  70. data/lib/convection/model/template/resource/aws_elasticache_security_group_ingress.rb +19 -0
  71. data/lib/convection/model/template/resource/aws_elb.rb +39 -0
  72. data/lib/convection/model/template/resource/aws_iam_access_key.rb +19 -0
  73. data/lib/convection/model/template/resource/aws_iam_group.rb +18 -0
  74. data/lib/convection/model/template/resource/aws_iam_instance_profile.rb +21 -0
  75. data/lib/convection/model/template/resource/aws_iam_policy.rb +28 -24
  76. data/lib/convection/model/template/resource/aws_iam_role.rb +88 -19
  77. data/lib/convection/model/template/resource/aws_iam_user.rb +53 -0
  78. data/lib/convection/model/template/resource/aws_logs_loggroup.rb +33 -0
  79. data/lib/convection/model/template/resource/aws_rds_db_instance.rb +59 -0
  80. data/lib/convection/model/template/resource/aws_rds_db_parameter_group.rb +27 -0
  81. data/lib/convection/model/template/resource/aws_rds_db_security_group.rb +40 -0
  82. data/lib/convection/model/template/resource/aws_rds_db_subnet_group.rb +26 -0
  83. data/lib/convection/model/template/resource/aws_route53_health_check.rb +17 -0
  84. data/lib/convection/model/template/resource/aws_route53_recordset.rb +30 -0
  85. data/lib/convection/model/template/resource/aws_s3_bucket.rb +8 -44
  86. data/lib/convection/model/template/resource/aws_s3_bucket_policy.rb +14 -19
  87. data/lib/convection/model/template/resource/aws_sns_topic.rb +19 -0
  88. data/lib/convection/model/template/resource/aws_sqs_queue.rb +31 -0
  89. data/lib/convection/model/template/resource/aws_sqs_queue_policy.rb +18 -0
  90. data/test/convection/model/test_conditions.rb +121 -0
  91. data/test/convection/model/test_elasticache.rb +97 -0
  92. data/test/convection/model/test_loggroups.rb +25 -0
  93. data/test/convection/model/test_rds.rb +76 -0
  94. data/test/convection/model/test_template.rb +64 -0
  95. data/test/convection/model/test_validation.rb +216 -0
  96. data/test/test_helper.rb +17 -0
  97. metadata +131 -50
@@ -0,0 +1,25 @@
1
+ require_relative '../resource'
2
+
3
+ module Convection
4
+ module Model
5
+ class Template
6
+ class Resource
7
+ ##
8
+ # AWS::EC2::SecurityGroup
9
+ ##
10
+ class EC2SecurityGroupIngres < Resource
11
+ extend Mixin::Protocol
12
+
13
+ type 'AWS::EC2::SecurityGroupIngress'
14
+ property :address, 'CidrIp'
15
+ property :parent, 'GroupId'
16
+ property :from, 'FromPort'
17
+ property :to, 'ToPort'
18
+ protocol_property :protocol, 'IpProtocol'
19
+ property :source_group, 'SourceSecurityGroupId'
20
+ property :source_owner, 'SourceSecurityGroupOwnerId'
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -2,28 +2,29 @@ require_relative '../resource'
2
2
  require_relative 'aws_ec2_subnet_route_table_association'
3
3
 
4
4
  module Convection
5
-
6
5
  module DSL
7
- ## Add DSL method to template namespace
8
6
  module Template
9
- def ec2_subnet(name, &block)
10
- r = Model::Template::Resource::EC2Subnet.new(name, self)
11
-
12
- r.instance_exec(&block) if block
13
- resources[name] = r
14
- end
15
-
16
7
  module Resource
17
8
  ##
18
9
  # Add DSL for RouteTableAssocaition
10
+ ##
19
11
  module EC2Subnet
20
- def associate_route_table(table, &block)
21
- r = Model::Template::Resource::EC2SubnetRouteTableAssociation.new("#{ name }RouteTableAssociation#{ table.name }", @tamplate)
22
- r.route_table(table.reference)
23
- r.subnet(reference)
12
+ def route_table(table, &block)
13
+ assoc = Model::Template::Resource::EC2SubnetRouteTableAssociation.new("#{ name }RouteTableAssociation#{ table.name }", template)
14
+ assoc.route_table(table)
15
+ assoc.subnet(self)
24
16
 
25
- r.instance_exec(&block) if block
26
- @template.resources[r.name] = r
17
+ assoc.instance_exec(&block) if block
18
+ @template.resources[assoc.name] = assoc
19
+ end
20
+
21
+ def acl(acl_entity, &block)
22
+ assoc = Model::Template::Resource::EC2SubnetNetworkACLAssociation.new("#{ name }ACLAssociation#{ acl_entity.name }", template)
23
+ assoc.acl(acl_entity)
24
+ assoc.subnet(self)
25
+
26
+ assoc.instance_exec(&block) if block
27
+ @template.resources[assoc.name] = assoc
27
28
  end
28
29
  end
29
30
  end
@@ -38,21 +39,13 @@ module Convection
38
39
  ##
39
40
  class EC2Subnet < Resource
40
41
  include DSL::Template::Resource::EC2Subnet
41
- include Model::Mixin::CIDRBlock
42
42
  include Model::Mixin::Taggable
43
+ extend Mixin::CIDRBlock
43
44
 
44
- def initialize(*args)
45
- super
46
- type 'AWS::EC2::Subnet'
47
- end
48
-
49
- def availability_zone(value)
50
- property('AvailabilityZone', value)
51
- end
52
-
53
- def vpc_id(value)
54
- property('VpcId', value)
55
- end
45
+ type 'AWS::EC2::Subnet'
46
+ property :availability_zone, 'AvailabilityZone'
47
+ property :vpc, 'VpcId'
48
+ cidr_property :network, 'CidrBlock'
56
49
 
57
50
  def render(*args)
58
51
  super.tap do |resource|
@@ -0,0 +1,18 @@
1
+ require_relative '../resource'
2
+
3
+ module Convection
4
+ module Model
5
+ class Template
6
+ class Resource
7
+ ##
8
+ # AWS::EC2::SubnetRouteTableAssociation
9
+ ##
10
+ class EC2SubnetNetworkACLAssociation < Resource
11
+ type 'AWS::EC2::SubnetNetworkAclAssociation'
12
+ property :acl, 'NetworkAclId'
13
+ property :subnet, 'SubnetId'
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -8,32 +8,11 @@ module Convection
8
8
  # AWS::EC2::SubnetRouteTableAssociation
9
9
  ##
10
10
  class EC2SubnetRouteTableAssociation < Resource
11
- def initialize(*args)
12
- super
13
- type 'AWS::EC2::SubnetRouteTableAssociation'
14
- end
15
-
16
- def route_table(value)
17
- property('RouteTableId', value)
18
- end
19
-
20
- def subnet(value)
21
- property('SubnetId', value)
22
- end
11
+ type 'AWS::EC2::SubnetRouteTableAssociation'
12
+ property :route_table, 'RouteTableId'
13
+ property :subnet, 'SubnetId'
23
14
  end
24
15
  end
25
16
  end
26
17
  end
27
-
28
- module DSL
29
- ## Add DSL method to template namespace
30
- module Template
31
- def ec2_subnet_route_table_association(name, &block)
32
- r = Model::Template::Resource::EC2SubnetRouteTableAssociation.new(name, self)
33
-
34
- r.instance_exec(&block) if block
35
- resources[name] = r
36
- end
37
- end
38
- end
39
18
  end
@@ -2,23 +2,14 @@ require_relative '../resource'
2
2
 
3
3
  module Convection
4
4
  module DSL
5
- ## Add DSL method to template namespace
6
5
  module Template
7
- def ec2_vpc(name, &block)
8
- r = Model::Template::Resource::EC2VPC.new(name, self)
9
-
10
- r.instance_exec(&block) if block
11
- resources[name] = r
12
- end
13
-
14
6
  module Resource
15
7
  ##
16
8
  # DSL For VPC sub-entities
17
9
  ##
18
10
  module EC2VPC
19
- def stack
20
- @template.stack
21
- end
11
+ ## Expose other resource DSL handles inside of the VPC closure
12
+ include DSL::Template::Resource
22
13
 
23
14
  def add_internet_gateway(&block)
24
15
  g = Model::Template::Resource::EC2InternetGateway.new("#{ name }IG", @template)
@@ -32,9 +23,18 @@ module Convection
32
23
  @internet_gateway = g
33
24
  end
34
25
 
26
+ def add_network_acl(name, &block)
27
+ network_acl = Model::Template::Resource::EC2NetworkACL.new("#{ self.name }ACL#{ name }", @template)
28
+ network_acl.vpc(self)
29
+ network_acl.tag('Name', network_acl.name)
30
+
31
+ network_acl.instance_exec(&block) if block
32
+ @template.resources[network_acl.name] = network_acl
33
+ end
34
+
35
35
  def add_route_table(name, options = {}, &block)
36
36
  route_table = Model::Template::Resource::EC2RouteTable.new("#{ self.name }Table#{ name }", @template)
37
- route_table.vpc_id(self)
37
+ route_table.vpc(self)
38
38
  route_table.tag('Name', route_table.name)
39
39
 
40
40
  route_table.instance_exec(&block) if block
@@ -56,11 +56,11 @@ module Convection
56
56
  def add_subnet(name, &block)
57
57
  s = Model::Template::Resource::EC2Subnet.new("#{ self.name }Subnet#{ name }", @template)
58
58
  s.tag('Name', s.name)
59
- s.vpc_id(self)
59
+ s.vpc(self)
60
60
 
61
61
  ## Allocate the next available subnet
62
62
  @subnet_allocated += 1
63
- s.network(@network.subnet(
63
+ s.network(network.subnet(
64
64
  :Bits => @subnet_length,
65
65
  :NumSubnets => @subnet_allocated)[@subnet_allocated - 1])
66
66
 
@@ -80,30 +80,28 @@ module Convection
80
80
  ##
81
81
  class EC2VPC < Resource
82
82
  include DSL::Template::Resource::EC2VPC
83
- include Model::Mixin::CIDRBlock
84
- include Model::Mixin::Taggable
83
+ include Mixin::Taggable
84
+ extend Mixin::CIDRBlock
85
85
 
86
+ type 'AWS::EC2::VPC'
86
87
  attribute :subnet_length
88
+ property :instance_tenancy, 'InstanceTenancy'
89
+ cidr_property :network, 'CidrBlock'
87
90
 
88
91
  def initialize(*args)
89
92
  super
90
93
 
91
- type 'AWS::EC2::VPC'
92
94
  @subnet_allocated = 0
93
95
  @subnet_length = 24
94
96
 
95
97
  @internet_gateway = nil
96
98
  end
97
99
 
98
- def enable_dns(value)
100
+ def enable_dns(value = true)
99
101
  property('EnableDnsSupport', value)
100
102
  property('EnableDnsHostnames', value)
101
103
  end
102
104
 
103
- def instance_tenancy(value)
104
- property('InstanceTenancy', value)
105
- end
106
-
107
105
  def render(*args)
108
106
  super.tap do |resource|
109
107
  render_tags(resource)
@@ -8,36 +8,12 @@ module Convection
8
8
  # AWS::EC2::VPCGatewayAttachment
9
9
  ##
10
10
  class EC2VPCGatewayAttachment < Resource
11
- def initialize(*args)
12
- super
13
- type 'AWS::EC2::VPCGatewayAttachment'
14
- end
15
-
16
- def vpc_id(value)
17
- property('VpcId', value)
18
- end
19
-
20
- def internet_gateway(value)
21
- property('InternetGatewayId', value)
22
- end
23
-
24
- def vpn_gateway(value)
25
- property('VpnGatewayId', value)
26
- end
11
+ type 'AWS::EC2::VPCGatewayAttachment'
12
+ property :vpc, 'VpcId'
13
+ property :internet_gateway, 'InternetGatewayId'
14
+ property :vpn_gateway, 'VpnGatewayId'
27
15
  end
28
16
  end
29
17
  end
30
18
  end
31
-
32
- module DSL
33
- ## Add DSL method to template namespace
34
- module Template
35
- def ec2_vpc_gateway_attachment(name, &block)
36
- r = Model::Template::Resource::EC2VPCGatewayAttachment.new(name, self)
37
-
38
- r.instance_exec(&block) if block
39
- resources[name] = r
40
- end
41
- end
42
- end
43
19
  end
@@ -0,0 +1,24 @@
1
+ require_relative '../resource'
2
+
3
+ module Convection
4
+ module Model
5
+ class Template
6
+ class Resource
7
+ ##
8
+ # AWS::ElastiCache::CacheCluster
9
+ ##
10
+ class ElastiCacheCluster < Resource
11
+ type 'AWS::ElastiCache::CacheCluster', :elasticache_cache_cluster
12
+ property :auto_minor_version_upgrade, 'AutoMinorVersionUpgrade'
13
+ property :cache_node_type, 'CacheNodeType'
14
+ property :cache_security_group_names, 'CacheSecurityGroupNames'
15
+ property :cache_parameter_group_name, 'CacheParameterGroupName'
16
+ property :cluster_name, 'ClusterName'
17
+ property :engine, 'Engine'
18
+ property :engine_version, 'EngineVersion'
19
+ property :num_cache_nodes, 'NumCacheNodes'
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ require_relative '../resource'
2
+
3
+ module Convection
4
+ module Model
5
+ class Template
6
+ class Resource
7
+ ##
8
+ # AWS::ElastiCache::ParameterGroup
9
+ ##
10
+ class ElastiCacheParameterGroup < Resource
11
+ type 'AWS::ElastiCache::ParameterGroup', :elasticache_parameter_group
12
+ property :cache_parameter_group_family, 'CacheParameterGroupFamily'
13
+ property :description, 'Description'
14
+ property :parameter, 'Properties', :type => :hash
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ require_relative '../resource'
2
+
3
+ module Convection
4
+ module Model
5
+ class Template
6
+ class Resource
7
+ ##
8
+ # AWS::ElastiCache::SecurityGroup
9
+ ##
10
+ class ElastiCacheSecurityGroup < Resource
11
+ type 'AWS::ElastiCache::SecurityGroup', :elasticache_security_group
12
+ property :description, 'Description'
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ require_relative '../resource'
2
+
3
+ module Convection
4
+ module Model
5
+ class Template
6
+ class Resource
7
+ ##
8
+ # AWS::ElastiCache::SecurityGroupIngress
9
+ ##
10
+ class ElastiCacheSecurityGroupIngress < Resource
11
+ type 'AWS::ElastiCache::SecurityGroupIngress', :elasticache_security_group_ingress
12
+ property :cache_security_group_name, 'CacheSecurityGroupName'
13
+ property :ec2_security_group_name, 'EC2SecurityGroupName'
14
+ property :ec2_security_group_owner_id, 'EC2SecurityGroupOwnerId'
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,39 @@
1
+ require_relative '../resource'
2
+
3
+ module Convection
4
+ module Model
5
+ class Template
6
+ class Resource
7
+ ##
8
+ # AWS::ElasticLoadBalancing::LoadBalancer
9
+ ##
10
+ class ELB < Resource
11
+ include Model::Mixin::Taggable
12
+
13
+ type 'AWS::ElasticLoadBalancing::LoadBalancer', :elb
14
+ property :access_logging_policy, 'AccessLoggingPolicy'
15
+ property :app_cookie_stickiness_policy, 'AppCookieStickinessPolicy', :type => :list
16
+ property :lb_cookie_stickiness_policy, 'LBCookieStickinessPolicy', :type => :list
17
+ property :availability_zone, 'AvailabilityZones', :type => :list
18
+ property :connection_draining_policy, 'ConnectionDrainingPolicy'
19
+ property :connection_settings, 'ConnectionSettings'
20
+ property :cross_zone, 'CrossZone'
21
+ property :health_check, 'HealthCheck'
22
+ property :instance, 'Instances', :type => :list
23
+ property :load_balancer_name, 'LoadBalancerName'
24
+ property :listener, 'Listeners', :type => :list
25
+ property :policy, 'Policies', :type => :list
26
+ property :scheme, 'Scheme'
27
+ property :security_group, 'SecurityGroups', :type => :list
28
+ property :subnet, 'Subnets', :type => :list
29
+
30
+ def render(*args)
31
+ super.tap do |resource|
32
+ render_tags(resource)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,19 @@
1
+ require_relative '../resource'
2
+
3
+ module Convection
4
+ module Model
5
+ class Template
6
+ class Resource
7
+ ##
8
+ # AWS::IAM::AccessKey
9
+ ##
10
+ class IAMAccessKey < Resource
11
+ type 'AWS::IAM::AccessKey'
12
+ property :serial, 'Serial', :default => 0
13
+ property :status, 'Status', :default => 'Active'
14
+ property :user_name, 'UserName'
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ require_relative '../resource'
2
+
3
+ module Convection
4
+ module Model
5
+ class Template
6
+ class Resource
7
+ ##
8
+ # AWS::IAM::Group
9
+ ##
10
+ class IAMGroup < Resource
11
+ type 'AWS::IAM::Group'
12
+ property :path, 'Path'
13
+ property :policy, 'Policies', :type => :list
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end