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,21 @@
1
+ require_relative '../resource'
2
+
3
+ module Convection
4
+ module Model
5
+ class Template
6
+ class Resource
7
+ ##
8
+ # AWS::IAM::IstanceProfile
9
+ ##
10
+ class IAMInstanceProfile < Resource
11
+ type 'AWS::IAM::InstanceProfile'
12
+ property :path, 'Path'
13
+
14
+ ## List of references to AWS::IAM::Roles.
15
+ ## Currently, a maximum of one role can be assigned to an instance profile.
16
+ property :role, 'Roles', :type => :list
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,18 +1,7 @@
1
+ require 'forwardable'
1
2
  require_relative '../resource'
2
3
 
3
4
  module Convection
4
- module DSL
5
- ## Add DSL method to template namespace
6
- module Template
7
- def iam_policy(name, &block)
8
- r = Model::Template::Resource::IAMPolicy.new(name, self)
9
- r.instance_exec(&block) if block
10
-
11
- resources[name] = r
12
- end
13
- end
14
- end
15
-
16
5
  module Model
17
6
  class Template
18
7
  class Resource
@@ -20,23 +9,38 @@ module Convection
20
9
  # AWS::IAM::Policy
21
10
  ##
22
11
  class IAMPolicy < Resource
23
- def initialize(*args)
24
- super
12
+ extend Forwardable
25
13
 
26
- type 'AWS::IAM::Policy'
27
- @properties['Roles'] = []
28
- end
14
+ type 'AWS::IAM::Policy'
15
+ property :group, 'Groups', :type => :list,
16
+ :transform => (proc do |resource|
17
+ depends_on(resource)
18
+ resource
19
+ end)
20
+ property :role, 'Roles', :type => :list,
21
+ :transform => (proc do |resource|
22
+ depends_on(resource)
23
+ resource
24
+ end)
25
+ property :user, 'Users', :type => :list,
26
+ :transform => (proc do |resource|
27
+ depends_on(resource)
28
+ resource
29
+ end)
29
30
 
30
- def role(value)
31
- @properties['Roles'] << value
32
- end
31
+ attr_reader :document
32
+ def_delegators :@document, :allow, :id, :version, :statement
33
+ def_delegator :@document, :name, :policy_name
33
34
 
34
- def name(value)
35
- property('PolicyName', value)
35
+ def initialize(*args)
36
+ super
37
+ @document = Model::Mixin::Policy.new(:template => @template)
36
38
  end
37
39
 
38
- def policy_document(value)
39
- property('PolicyDocument', value)
40
+ def render
41
+ super.tap do |r|
42
+ document.render(r['Properties'])
43
+ end
40
44
  end
41
45
  end
42
46
  end
@@ -2,13 +2,86 @@ 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 iam_role(name, &block)
8
- r = Model::Template::Resource::IAMRole.new(name, self)
9
- r.instance_exec(&block) if block
6
+ module Resource
7
+ ## Role DSL
8
+ module IAMRole
9
+ def policy(policy_name, &block)
10
+ add_policy = Model::Mixin::Policy.new(:name => policy_name, :template => @template)
11
+ add_policy.instance_exec(&block) if block
10
12
 
11
- resources[name] = r
13
+ policies << add_policy
14
+ end
15
+
16
+ ## Create an IAM Instance Profile for this role
17
+ def with_instance_profile(&block)
18
+ profile = Model::Template::Resource::IAMInstanceProfile.new("#{ name }Profile", @template)
19
+ profile.role(self)
20
+ profile.path(path)
21
+
22
+ profile.instance_exec(&block) if block
23
+ @instance_profile = profile
24
+ @template.resources[profile.name] = profile
25
+ end
26
+
27
+ ## Add a canned trust policy for EC2 instances
28
+ def trust_ec2_instances(&block)
29
+ @trust_relationship = Model::Mixin::Policy.new(:name => 'trust-ec2-instances', :template => @template)
30
+ trust_relationship.allow do
31
+ action 'sts:AssumeRole'
32
+ principal :Service => 'ec2.amazonaws.com'
33
+ end
34
+ trust_relationship.instance_exec(&block) if block
35
+ trust_relationship
36
+ end
37
+
38
+ ## Add a canned trust policy for Flow Logs
39
+ def trust_flow_logs(&block)
40
+ @trust_relationship = Model::Mixin::Policy.new(:name => 'trust-flow-logs', :template => @template)
41
+ trust_relationship.allow do
42
+ action 'sts:AssumeRole'
43
+ principal :Service => 'vpc-flow-logs.amazonaws.com'
44
+ end
45
+ trust_relationship.instance_exec(&block) if block
46
+ trust_relationship
47
+ end
48
+
49
+ ## Add a canned trust policy for Cloudtrail
50
+ def trust_cloudtrail(&block)
51
+ @trust_relationship =
52
+ Model::Mixin::Policy.new(:name => 'trust-cloudtrail-instances', :template => @template)
53
+
54
+ trust_relationship.allow do
55
+ action 'sts:AssumeRole'
56
+ principal :Service => 'cloudtrail.amazonaws.com'
57
+ end
58
+
59
+ trust_relationship.instance_exec(&block) if block
60
+ trust_relationship
61
+ end
62
+
63
+ ## Add a policy to allow instance to self-terminate
64
+ def allow_instance_termination(&block)
65
+ with_instance_profile if instance_profile.nil?
66
+
67
+ term_policy = Model::Template::Resource::IAMPolicy.new("#{ name }TerminationPolicy", @template)
68
+ term_policy.policy_name('allow-instance-termination')
69
+
70
+ parent_role = self
71
+ term_policy.allow do
72
+ action 'ec2:TerminateInstances'
73
+ resource '*'
74
+ condition :StringEquals => {
75
+ 'ec2:InstanceProfile' => get_att(parent_role.instance_profile.name, 'Arn')
76
+ }
77
+ end
78
+ term_policy.role(self)
79
+ term_policy.depends_on(instance_profile)
80
+
81
+ term_policy.instance_exec(&block) if block
82
+ @template.resources[term_policy.name] = term_policy
83
+ end
84
+ end
12
85
  end
13
86
  end
14
87
  end
@@ -20,23 +93,19 @@ module Convection
20
93
  # AWS::IAM::Role
21
94
  ##
22
95
  class IAMRole < Resource
23
- def initialize(*args)
24
- super
96
+ include DSL::Template::Resource::IAMRole
25
97
 
26
- type 'AWS::IAM::Role'
27
- @properties['Policies'] = []
28
- end
98
+ type 'AWS::IAM::Role'
99
+ property :path, 'Path'
100
+ property :policies, 'Policies', :type => :list
29
101
 
30
- def path(value)
31
- property('Path', value)
32
- end
33
-
34
- def policies(value)
35
- @properties['Policies'] << value
36
- end
102
+ attr_accessor :trust_relationship
103
+ attr_reader :instance_profile
37
104
 
38
- def assume_role_policy_document(value)
39
- property('AssumeRolePolicyDocument', value)
105
+ def render
106
+ super.tap do |r|
107
+ r['Properties']['AssumeRolePolicyDocument'] = trust_relationship.document unless trust_relationship.nil?
108
+ end
40
109
  end
41
110
  end
42
111
  end
@@ -0,0 +1,53 @@
1
+ require_relative '../resource'
2
+
3
+ module Convection
4
+ module DSL
5
+ module Template
6
+ module Resource
7
+ ## Role DSL
8
+ module IAMUser
9
+ def policy(policy_name, &block)
10
+ add_policy = Model::Mixin::Policy.new(:name => policy_name, :template => @template)
11
+ add_policy.instance_exec(&block) if block
12
+
13
+ policies << add_policy
14
+ end
15
+
16
+ def with_key(serial = 0, &block)
17
+ key = Model::Template::Resource::IAMAccessKey.new("#{ name }Key", @template)
18
+ key.user_name = self
19
+ key.serial = serial
20
+
21
+ key.depends_on(self)
22
+
23
+ key.with_output("#{ name }Id", key.reference)
24
+ key.with_output("#{ name }Secret", get_att(key.name, 'SecretAccessKey'))
25
+
26
+ key.instance_exec(&block) if block
27
+
28
+ @template.resources[key.name] = key
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ module Model
36
+ class Template
37
+ class Resource
38
+ ##
39
+ # AWS::IAM::User
40
+ ##
41
+ class IAMUser < Resource
42
+ include DSL::Template::Resource::IAMUser
43
+
44
+ type 'AWS::IAM::User'
45
+ property :path, 'Path'
46
+ property :login_profile, 'LoginProfile'
47
+ property :group, 'Groups', :type => :list
48
+ property :policies, 'Policies', :type => :list
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,33 @@
1
+ require_relative '../resource'
2
+
3
+ module Convection
4
+ module Model
5
+ class Template
6
+ class Resource
7
+ ##
8
+ # AWS::Logs::LogGroup
9
+ ##
10
+ class LogGroup < Resource
11
+ property :retention_in_days, 'RetentionInDays'
12
+
13
+ def initialize(*args)
14
+ super
15
+ type 'AWS::Logs::LogGroup'
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ module DSL
23
+ ## Add DSL method to template namespace
24
+ module Template
25
+ def logs_log_group(name, &block)
26
+ r = Model::Template::Resource::LogGroup.new(name, self)
27
+
28
+ r.instance_exec(&block) if block
29
+ resources[name] = r
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,59 @@
1
+ require_relative '../resource'
2
+
3
+ module Convection
4
+ module Model
5
+ class Template
6
+ class Resource
7
+ ##
8
+ # AWS::RDS::DBInstance
9
+ ##
10
+ class RDSDBInstance < Resource
11
+ include Model::Mixin::Taggable
12
+
13
+ type 'AWS::RDS::DBInstance', :rds_instance
14
+ property :identifier, 'DBInstanceIdentifier'
15
+ property :source_identifier, 'SourceDBInstanceIdentifier'
16
+ property :instance_class, 'DBInstanceClass'
17
+ property :engine, 'Engine'
18
+ property :engine_version, 'EngineVersion'
19
+ property :license_model, 'LicenseModel'
20
+ property :storage_type, 'StorageType'
21
+ property :storage_encrypted, 'StorageEncrypted'
22
+ property :iops, 'Iops'
23
+ property :port, 'Port'
24
+ property :master, 'SourceDBInstanceIdentifier'
25
+
26
+ property :database_name, 'DBName'
27
+ property :master_username, 'MasterUsername'
28
+ property :master_password, 'MasterUserPassword'
29
+
30
+ property :parameter_group, 'DBParameterGroupName'
31
+ property :option_group, 'OptionGroupName'
32
+
33
+ property :storage_encrypted, 'StorageEncrypted'
34
+ property :kms_key_id, 'KmsKeyId'
35
+ property :allocated_storage, 'AllocatedStorage'
36
+ property :allow_major_version_upgrade, 'AllowMajorVersionUpgrade'
37
+ property :auto_minor_version_upgrade, 'AutoMinorVersionUpgrade'
38
+ property :snapshot_identifier, 'DBSnapshotIdentifier'
39
+ property :backup_retention_period, 'BackupRetentionPeriod'
40
+ property :preferred_backup_window, 'PreferredBackupWindow'
41
+ property :preferred_maintenance_window, 'PreferredMaintenanceWindow'
42
+
43
+ property :availability_zone, 'AvailabilityZone'
44
+ property :multi_az, 'MultiAZ'
45
+ property :publicly_accessible, 'PubliclyAccessible'
46
+ property :subnet_group, 'DBSubnetGroupName'
47
+ property :security_group, 'DBSecurityGroups', :type => :list
48
+ property :vpc_security_group, 'VPCSecurityGroups', :type => :list
49
+
50
+ def render(*args)
51
+ super.tap do |resource|
52
+ render_tags(resource)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ 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::RDS::DBParameterGroup
9
+ ##
10
+ class RDSDBParameterGroup < Resource
11
+ include Model::Mixin::Taggable
12
+
13
+ type 'AWS::RDS::DBParameterGroup', :rds_parameter_group
14
+ property :description, 'Description'
15
+ property :family, 'Family'
16
+ property :parameter, 'Parameters', :type => :hash
17
+
18
+ def render(*args)
19
+ super.tap do |resource|
20
+ render_tags(resource)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,40 @@
1
+ require_relative '../resource'
2
+
3
+ module Convection
4
+ module Model
5
+ class Template
6
+ class Resource
7
+ ##
8
+ # AWS::RDS::DBSecurityGroup
9
+ ##
10
+ class RDSDBSecurityGroup < Resource
11
+ include Model::Mixin::Taggable
12
+
13
+ type 'AWS::RDS::DBSecurityGroup', :rds_security_group
14
+ property :description, 'GroupDescription'
15
+ property :vpc, 'EC2VpcId'
16
+ property :ingress, 'DBSecurityGroupIngress', :type => :list
17
+
18
+ def ec2_security_group(group, owner)
19
+ ingress(
20
+ :EC2SecurityGroupName => group,
21
+ :EC2SecurityGroupOwnerId => owner
22
+ )
23
+ end
24
+
25
+ def cidr_ip(cidr_block)
26
+ ingress(
27
+ :CIDRIP => cidr_block
28
+ )
29
+ end
30
+
31
+ def render(*args)
32
+ super.tap do |resource|
33
+ render_tags(resource)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,26 @@
1
+ require_relative '../resource'
2
+
3
+ module Convection
4
+ module Model
5
+ class Template
6
+ class Resource
7
+ ##
8
+ # AWS::RDS::DBSubnetGroup
9
+ ##
10
+ class RDSDBSubnetGroup < Resource
11
+ include Model::Mixin::Taggable
12
+
13
+ type 'AWS::RDS::DBSubnetGroup', :rds_subnet_group
14
+ property :subnet, 'SubnetIds', :type => :list
15
+ property :description, 'DBSubnetGroupDescription'
16
+
17
+ def render(*args)
18
+ super.tap do |resource|
19
+ render_tags(resource)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end