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,39 @@
1
+ require_relative '../resource'
2
+
3
+ module Convection
4
+ module Model
5
+ class Template
6
+ class Resource
7
+ ##
8
+ # AWS::AutoScaling::AutoScalingGroup
9
+ ##
10
+ class AutoScalingGroup < Resource
11
+ include Model::Mixin::Taggable
12
+
13
+ type 'AWS::AutoScaling::AutoScalingGroup'
14
+ property :availability_zone, 'AvailabilityZones', :array
15
+ property :cooldown, 'Cooldown'
16
+ property :desired_capacity, 'DesiredCapacity'
17
+ property :health_check_grace_period, 'HealthCheckGracePeriod'
18
+ property :health_check_type, 'HealthCheckType'
19
+ property :instance_id, 'InstanceId'
20
+ property :launch_configuration_name, 'LaunchConfigurationName'
21
+ property :load_balancer_name, 'LoadBalancerNames', :array
22
+ property :max_size, 'MaxSize'
23
+ property :metrics_collection, 'MetricsCollection', :array
24
+ property :min_size, 'MinSize'
25
+ property :notification_configuration, 'NotificationConfiguration'
26
+ property :placement_group, 'PlacementGroup'
27
+ property :termination_policie, 'TerminationPolicies', :array
28
+ property :vpc_zone_identifier, 'VPCZoneIdentifier', :array
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,30 @@
1
+ require_relative '../resource'
2
+
3
+ module Convection
4
+ module Model
5
+ class Template
6
+ class Resource
7
+ ##
8
+ # AWS::AutoScaling::LaunchConfiguration
9
+ ##
10
+ class LaunchConfiguration < Resource
11
+ type 'AWS::AutoScaling::LaunchConfiguration'
12
+ property :associate_public_ip_address, 'AssociatePublicIpAddress'
13
+ property :block_device_mappings, 'BlockDeviceMappings', :array
14
+ property :ebs_optimized, 'EbsOptimized'
15
+ property :iam_instanceProfile, 'IamInstanceProfile'
16
+ property :image_id, 'ImageId'
17
+ property :instance_id, 'InstanceId'
18
+ property :instance_monitoring, 'InstanceMonitoring'
19
+ property :instance_type, 'InstanceType'
20
+ property :kernel_id, 'KernelId'
21
+ property :key_name, 'KeyName'
22
+ property :ram_diskId, 'RamDiskId'
23
+ property :security_group, 'SecurityGroups', :array
24
+ property :spot_price, 'SpotPrice'
25
+ property :user_data, 'UserData'
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ require_relative '../resource'
2
+
3
+ module Convection
4
+ module Model
5
+ class Template
6
+ class Resource
7
+ ##
8
+ # AWS::AutoScaling::ScalingPolicy
9
+ ##
10
+ class ScalingPolicy < Resource
11
+ type 'AWS::AutoScaling::ScalingPolicy'
12
+ property :adjustment_type, 'AdjustmentType'
13
+ property :auto_scaling_group_name, 'AutoScalingGroupName'
14
+ property :cooldown, 'Cooldown'
15
+ property :scaling_adjustment, 'ScalingAdjustment'
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ require_relative '../resource'
2
+
3
+ module Convection
4
+ module Model
5
+ class Template
6
+ class Resource
7
+ ##
8
+ # AWS::CloudWatch::Alarm
9
+ ##
10
+ class CloudWatchAlarm < Resource
11
+ type 'AWS::CloudWatch::Alarm'
12
+ property :actions_enabled, 'ActionsEnabled', :default => true
13
+ property :alarm_action, 'AlarmActions', :type => :list
14
+ property :alarm_description, 'AlarmDescription'
15
+ property :alarm_name, 'AlarmName'
16
+ property :comparison_operator, 'ComparisonOperator'
17
+ property :dimension, 'Dimensions', :type => :list
18
+ property :evaluation_periods, 'EvaluationPeriods'
19
+ property :insufficient_data_action, 'InsufficientDataActions', :type => :list
20
+ property :metric_name, 'MetricName'
21
+ property :namespace, 'Namespace'
22
+ property :ok_action, 'OKActions', :type => :list
23
+ property :period, 'Period'
24
+ property :statistic, 'Statistic'
25
+ property :threshold, 'Threshold'
26
+ property :unit, 'Unit'
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -10,40 +10,16 @@ module Convection
10
10
  class EC2Instance < Resource
11
11
  include Model::Mixin::Taggable
12
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
13
+ type 'AWS::EC2::Instance'
14
+ property :availability_zone, 'AvailabilityZone'
15
+ property :image_id, 'ImageId'
16
+ property :instance_type, 'InstanceType'
17
+ property :instance_profile, 'IamInstanceProfile'
18
+ property :key_name, 'KeyName'
19
+ property :subnet, 'SubnetId'
20
+ property :user_data, 'UserData'
21
+ property :security_group, 'SecurityGroupIds', :type => :list
22
+ property :src_dst_checks, 'SourceDestCheck'
47
23
 
48
24
  def render(*args)
49
25
  super.tap do |resource|
@@ -54,16 +30,4 @@ module Convection
54
30
  end
55
31
  end
56
32
  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
33
  end
@@ -2,22 +2,15 @@ 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_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
6
  module Resource
15
7
  ##
16
8
  # Add DSL for VPCGatewayAttachment
9
+ ##
17
10
  module EC2InternetGateway
18
11
  def attach_to_vpc(vpc, &block)
19
12
  a = Model::Template::Resource::EC2VPCGatewayAttachment.new("#{ name }VPCAttachment#{ vpc.name }", self)
20
- a.vpc_id(vpc)
13
+ a.vpc(vpc)
21
14
  a.internet_gateway(self)
22
15
 
23
16
  a.instance_exec(&block) if block
@@ -37,11 +30,7 @@ module Convection
37
30
  class EC2InternetGateway < Resource
38
31
  include Model::Mixin::Taggable
39
32
  include DSL::Template::Resource::EC2InternetGateway
40
-
41
- def initialize(*args)
42
- super
43
- type 'AWS::EC2::InternetGateway'
44
- end
33
+ type 'AWS::EC2::InternetGateway'
45
34
 
46
35
  def render(*args)
47
36
  super.tap do |resource|
@@ -0,0 +1,45 @@
1
+ require_relative '../resource'
2
+
3
+ module Convection
4
+ module DSL
5
+ module Template
6
+ module Resource
7
+ ##
8
+ # Add DSL helpers to EC2NetworkACL
9
+ ##
10
+ module EC2NetworkACL
11
+ def entry(name, &block)
12
+ acl_entry = Model::Template::Resource::EC2NetworkACLEntry.new("#{ self.name }Entry#{ name }", @template)
13
+ acl_entry.acl(self)
14
+
15
+ acl_entry.instance_exec(&block) if block
16
+ @template.resources[acl_entry.name] = acl_entry
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ module Model
24
+ class Template
25
+ class Resource
26
+ ##
27
+ # AWS::EC2::NetworkACL
28
+ ##
29
+ class EC2NetworkACL < Resource
30
+ include DSL::Template::Resource::EC2NetworkACL
31
+ include Model::Mixin::Taggable
32
+
33
+ type 'AWS::EC2::NetworkAcl'
34
+ property :vpc, 'VpcId'
35
+
36
+ def render(*args)
37
+ super.tap do |resource|
38
+ render_tags(resource)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,27 @@
1
+ require_relative '../resource'
2
+
3
+ module Convection
4
+ module Model
5
+ class Template
6
+ class Resource
7
+ ##
8
+ # AWS::EC2::NetworkACL
9
+ ##
10
+ class EC2NetworkACLEntry < Resource
11
+ extend Mixin::CIDRBlock
12
+ extend Mixin::Protocol
13
+
14
+ type 'AWS::EC2::NetworkAclEntry'
15
+ property :acl, 'NetworkAclId'
16
+ property :action, 'RuleAction'
17
+ property :number, 'RuleNumber'
18
+ property :egress, 'Egress'
19
+ property :icmp, 'Icmp'
20
+ property :range, 'PortRange'
21
+ cidr_property :network, 'CidrBlock'
22
+ protocol_property :protocol, 'Protocol'
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -8,48 +8,15 @@ module Convection
8
8
  # AWS::EC2::Route
9
9
  ##
10
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
11
+ type 'AWS::EC2::Route'
12
+ property :route_table_id, 'RouteTableId'
13
+ property :destination, 'DestinationCidrBlock'
14
+ property :gateway, 'GatewayId'
15
+ property :instance, 'InstanceId'
16
+ property :interface, 'NetworkInterfaceId'
17
+ property :peer, 'VpcPeeringConnectionId'
39
18
  end
40
19
  end
41
20
  end
42
21
  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
22
  end
@@ -1,17 +1,8 @@
1
1
  require_relative '../resource'
2
2
 
3
3
  module Convection
4
-
5
4
  module DSL
6
- ## Add DSL method to template namespace
7
5
  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
6
  module Resource
16
7
  ##
17
8
  # DSL For routes
@@ -39,14 +30,8 @@ module Convection
39
30
  include DSL::Template::Resource::EC2RouteTable
40
31
  include Model::Mixin::Taggable
41
32
 
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
33
+ type 'AWS::EC2::RouteTable'
34
+ property :vpc, 'VpcId'
50
35
 
51
36
  def render(*args)
52
37
  super.tap do |resource|
@@ -2,32 +2,31 @@ 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_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
6
  module Resource
15
7
  ##
16
8
  # DSL For EC2SecurityGroup rules
17
9
  ##
18
10
  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
11
+ def ingress_rule(protocol = nil, port = nil, source = nil, &block)
12
+ rule = Model::Template::Resource::EC2SecurityGroup::Rule.new("#{ name }IngressGroupRule", @template)
13
+ rule.protocol = protocol unless protocol.nil?
14
+ rule.from = port unless port.nil?
15
+ rule.to = port unless port.nil?
16
+ rule.source = source unless source.nil?
17
+
18
+ rule.instance_exec(&block) if block
19
+ security_group_ingress << rule
24
20
  end
25
21
 
26
- def egress_rule(&block)
27
- r = Model::Template::Resource::EC2SecurityGroup::Rule.new("#{ name }EgressGroupRule", @template)
28
- r.instance_exec(&block) if block
22
+ def egress_rule(protocol = nil, port = nil, &block)
23
+ rule = Model::Template::Resource::EC2SecurityGroup::Rule.new("#{ name }EgressGroupRule", @template)
24
+ rule.protocol = protocol unless protocol.nil?
25
+ rule.from = port unless port.nil?
26
+ rule.to = port unless port.nil?
29
27
 
30
- security_group_egress << r
28
+ rule.instance_exec(&block) if block
29
+ security_group_egress << rule
31
30
  end
32
31
  end
33
32
  end
@@ -55,41 +54,36 @@ module Convection
55
54
  attribute :to
56
55
  attribute :protocol
57
56
 
58
- attribute :cidr_ip
57
+ attribute :source
59
58
  attribute :destination_group
60
59
  attribute :source_group
61
60
  attribute :source_group_owner
62
61
 
63
62
  def render
64
63
  {
65
- 'IpProtocol' => protocol,
64
+ 'IpProtocol' => Mixin::Protocol.lookup(protocol),
66
65
  'FromPort' => from,
67
66
  'ToPort' => to
68
67
  }.tap do |rule|
69
- rule['CidrIp'] = cidr_ip unless cidr_ip.nil?
68
+ rule['CidrIp'] = source unless source.nil?
70
69
  rule['DestinationSecurityGroupId'] = destination_group unless destination_group.nil?
71
70
  rule['SourceSecurityGroupId'] = source_group unless source_group.nil?
72
- rule['SourceSecurityGroupOwnerId'] = source_group_owner unless source_group.nil?
71
+ rule['SourceSecurityGroupOwnerId'] = source_group_owner unless source_group_owner.nil?
73
72
  end
74
73
  end
75
74
  end
76
75
 
76
+ type 'AWS::EC2::SecurityGroup'
77
+ property :description, 'GroupDescription'
78
+ property :vpc, 'VpcId'
79
+
77
80
  def initialize(*args)
78
81
  super
79
82
 
80
- type 'AWS::EC2::SecurityGroup'
81
83
  @security_group_ingress = []
82
84
  @security_group_egress = []
83
85
  end
84
86
 
85
- def description(value)
86
- property('GroupDescription', value)
87
- end
88
-
89
- def vpc_id(value)
90
- property('VpcId', value)
91
- end
92
-
93
87
  def render(*args)
94
88
  super.tap do |resource|
95
89
  resource['Properties']['SecurityGroupIngress'] = security_group_ingress.map(&:render)