cfndsl 0.4.4 → 0.5.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +5 -13
  2. data/.rubocop.yml +23 -0
  3. data/Gemfile +4 -0
  4. data/Rakefile +19 -17
  5. data/bin/cfndsl +20 -20
  6. data/cfndsl.gemspec +16 -15
  7. data/lib/cfndsl.rb +62 -68
  8. data/lib/cfndsl/aws/cloud_formation_template.rb +16 -0
  9. data/lib/cfndsl/aws/types.rb +12 -0
  10. data/lib/cfndsl/{aws_types.yaml → aws/types.yaml} +0 -0
  11. data/lib/cfndsl/{Conditions.rb → conditions.rb} +5 -7
  12. data/lib/cfndsl/creation_policy.rb +21 -0
  13. data/lib/cfndsl/errors.rb +29 -0
  14. data/lib/cfndsl/generate_types.rb +154 -0
  15. data/lib/cfndsl/jsonable.rb +214 -0
  16. data/lib/cfndsl/mappings.rb +23 -0
  17. data/lib/cfndsl/metadata.rb +16 -0
  18. data/lib/cfndsl/module.rb +52 -51
  19. data/lib/cfndsl/names.rb +5 -5
  20. data/lib/cfndsl/orchestration_template.rb +173 -0
  21. data/lib/cfndsl/os/heat_template.rb +16 -0
  22. data/lib/cfndsl/os/types.rb +12 -0
  23. data/lib/cfndsl/{os_types.yaml → os/types.yaml} +11 -11
  24. data/lib/cfndsl/{Outputs.rb → outputs.rb} +3 -4
  25. data/lib/cfndsl/{Parameters.rb → parameters.rb} +12 -13
  26. data/lib/cfndsl/plurals.rb +34 -0
  27. data/lib/cfndsl/properties.rb +21 -0
  28. data/lib/cfndsl/rake_task.rb +9 -7
  29. data/lib/cfndsl/ref_check.rb +44 -0
  30. data/lib/cfndsl/{Resources.rb → resources.rb} +13 -15
  31. data/lib/cfndsl/types.rb +151 -0
  32. data/lib/cfndsl/update_policy.rb +25 -0
  33. data/lib/cfndsl/version.rb +1 -1
  34. data/sample/autoscale.rb +152 -158
  35. data/sample/autoscale2.rb +151 -155
  36. data/sample/circular.rb +30 -33
  37. data/sample/codedeploy.rb +35 -36
  38. data/sample/config_service.rb +120 -0
  39. data/sample/ecs.rb +39 -39
  40. data/sample/iam_policies.rb +82 -0
  41. data/sample/lambda.rb +20 -24
  42. data/sample/s3.rb +11 -11
  43. data/sample/t1.rb +7 -9
  44. data/sample/vpc_example.rb +50 -0
  45. data/sample/vpc_with_vpn_example.rb +97 -0
  46. data/spec/cfndsl_spec.rb +22 -11
  47. data/spec/fixtures/heattest.rb +13 -14
  48. data/spec/fixtures/test.rb +56 -53
  49. metadata +36 -30
  50. data/lib/cfndsl/CloudFormationTemplate.rb +0 -267
  51. data/lib/cfndsl/CreationPolicy.rb +0 -25
  52. data/lib/cfndsl/Errors.rb +0 -31
  53. data/lib/cfndsl/JSONable.rb +0 -235
  54. data/lib/cfndsl/Mappings.rb +0 -25
  55. data/lib/cfndsl/Metadata.rb +0 -22
  56. data/lib/cfndsl/Plurals.rb +0 -35
  57. data/lib/cfndsl/Properties.rb +0 -25
  58. data/lib/cfndsl/RefCheck.rb +0 -48
  59. data/lib/cfndsl/Types.rb +0 -309
  60. data/lib/cfndsl/UpdatePolicy.rb +0 -29
  61. data/sample/config-service.rb +0 -119
  62. data/sample/iam-policies.rb +0 -82
  63. data/sample/vpc-example.rb +0 -51
  64. data/sample/vpc-with-vpn-example.rb +0 -97
data/sample/circular.rb CHANGED
@@ -1,33 +1,30 @@
1
-
2
- CloudFormation {
3
- AWSTemplateFormatVersion "2010-09-09"
4
-
5
- Description "Circular Reference"
6
-
7
- Parameter("InstanceType") {
8
- Description "Type of EC2 instance to launch"
9
- Type "String"
10
- Default "m1.small"
11
- }
12
-
13
- Resource("WebServerGroup") {
14
- Type "AWS::AutoScaling::AutoScalingGroup"
15
- Property("AvailabilityZones", FnGetAZs("") )
16
- Property("LaunchConfigurationName", Ref( "LaunchConfig") )
17
- Property("MinSize", "1")
18
- Property("MaxSize", "3")
19
- }
20
-
21
-
22
- Resource( "LaunchConfig" ) {
23
- Type "AWS::AutoScaling::LaunchConfiguration"
24
- DependsOn ["WebServerGroup"]
25
- Property("InstanceType", Ref("InstanceType") )
26
- }
27
-
28
-
29
- Output( "URL" ) {
30
- Description "The URL of the website"
31
- Value FnJoin( "", [ "http://", FnGetAtt( "LaunchConfig", "DNSName" ) ] )
32
- }
33
- }
1
+ CloudFormation do
2
+ AWSTemplateFormatVersion '2010-09-09'
3
+
4
+ Description 'Circular Reference'
5
+
6
+ Parameter('InstanceType') do
7
+ Description 'Type of EC2 instance to launch'
8
+ Type 'String'
9
+ Default 'm1.small'
10
+ end
11
+
12
+ Resource('WebServerGroup') do
13
+ Type 'AWS::AutoScaling::AutoScalingGroup'
14
+ Property('AvailabilityZones', FnGetAZs(''))
15
+ Property('LaunchConfigurationName', Ref('LaunchConfig'))
16
+ Property('MinSize', '1')
17
+ Property('MaxSize', '3')
18
+ end
19
+
20
+ Resource('LaunchConfig') do
21
+ Type 'AWS::AutoScaling::LaunchConfiguration'
22
+ DependsOn ['WebServerGroup']
23
+ Property('InstanceType', Ref('InstanceType'))
24
+ end
25
+
26
+ Output('URL') do
27
+ Description 'The URL of the website'
28
+ Value FnJoin('', ['http://', FnGetAtt('LaunchConfig', 'DNSName')])
29
+ end
30
+ end
data/sample/codedeploy.rb CHANGED
@@ -1,48 +1,47 @@
1
- CloudFormation {
2
- DESCRIPTION ||= "CodeDeploy description"
1
+ CloudFormation do
2
+ DESCRIPTION ||= 'CodeDeploy description'.freeze
3
3
 
4
4
  Description DESCRIPTION
5
5
 
6
- Parameter("ServiceRoleArn") {
7
- Description "CodeDeploy Service Role"
8
- Type "String"
9
- }
6
+ Parameter('ServiceRoleArn') do
7
+ Description 'CodeDeploy Service Role'
8
+ Type 'String'
9
+ end
10
10
 
11
- Resource('MyCodeDeployApp') {
11
+ Resource('MyCodeDeployApp') do
12
12
  Type 'AWS::CodeDeploy::Application'
13
- }
13
+ end
14
14
 
15
- Resource('MyDeploymentConfig') {
15
+ Resource('MyDeploymentConfig') do
16
16
  Type 'AWS::CodeDeploy::DeploymentConfig'
17
- Property('MinimumHealthyHosts', {
18
- Type: "FLEET_PERCENT",
19
- Value: "50"
20
- })
21
- }
17
+ Property('MinimumHealthyHosts',
18
+ Type: 'FLEET_PERCENT',
19
+ Value: '50'
20
+ )
21
+ end
22
22
 
23
- Resource('MyDeploymentGroup') {
23
+ Resource('MyDeploymentGroup') do
24
24
  Type 'AWS::CodeDeploy::DeploymentGroup'
25
25
  Property('ApplicationName', Ref('MyCodeDeployApp'))
26
- Property('Deployment', {
27
- Description: 'My App CodeDeploy',
28
- IgnoreApplicationStopFailures: true,
29
- Revision: {
30
- RevisionType: 'S3',
31
- S3Location: {
32
- Bucket: 'my_code_deploy_bucket',
33
- Key: '/my_app_code_deloy',
34
- BundleType: 'zip',
35
- ETag: '1234567890ABCDEF',
36
- Version: '10'
37
- }
38
- }
39
- })
26
+ Property('Deployment',
27
+ Description: 'My App CodeDeploy',
28
+ IgnoreApplicationStopFailures: true,
29
+ Revision: {
30
+ RevisionType: 'S3',
31
+ S3Location: {
32
+ Bucket: 'my_code_deploy_bucket',
33
+ Key: '/my_app_code_deloy',
34
+ BundleType: 'zip',
35
+ ETag: '1234567890ABCDEF',
36
+ Version: '10'
37
+ }
38
+ }
39
+ )
40
40
  Property('Ec2TagFilters', [{
41
- Key: 'Role',
42
- Value: 'myapp',
43
- Type: 'KEY_AND_VALUE',
44
- }])
41
+ Key: 'Role',
42
+ Value: 'myapp',
43
+ Type: 'KEY_AND_VALUE'
44
+ }])
45
45
  Property('ServiceRoleArn', Ref('ServiceRoleArn'))
46
- }
47
-
48
- }
46
+ end
47
+ end
@@ -0,0 +1,120 @@
1
+ CloudFormation do
2
+ AWSTemplateFormatVersion '2010-09-09'
3
+
4
+ Description 'Creates SNS, SQS, S3 bucket and enables AWS Config.'
5
+
6
+ Queue('ConfigServiceQueue') do
7
+ QueueName 'ConfigServiceQueue'
8
+ end
9
+
10
+ Bucket('ConfigServiceBucket') do
11
+ end
12
+
13
+ Policy('ConfigServiceS3BucketAccessPolicy') do
14
+ PolicyName 'ConfigServiceS3BucketAccessPolicy'
15
+ PolicyDocument(
16
+ 'Version' => '2012-10-17',
17
+ 'Statement' =>
18
+ [
19
+ {
20
+ 'Effect' => 'Allow',
21
+ 'Action' => ['s3:PutObject'],
22
+ 'Resource' => FnJoin('', ['arn:aws:s3:::', Ref('ConfigServiceBucket'), '/AWSLogs/', Ref('AWS::AccountId'), '/*']),
23
+ 'Condition' =>
24
+ {
25
+ 'StringLike' =>
26
+ {
27
+ 's3:x-amz-acl' => 'bucket-owner-full-control'
28
+ }
29
+ }
30
+ },
31
+ {
32
+ 'Effect' => 'Allow',
33
+ 'Action' => ['s3:GetBucketAcl'],
34
+ 'Resource' => FnJoin('', ['arn:aws:s3:::', Ref('ConfigServiceBucket')])
35
+ }
36
+ ]
37
+ )
38
+ Role Ref('ConfigServiceIAMRole')
39
+ end
40
+
41
+ Role('ConfigServiceIAMRole') do
42
+ AssumeRolePolicyDocument(
43
+ 'Version' => '2012-10-17',
44
+ 'Statement' => [
45
+ {
46
+ 'Effect' => 'Allow',
47
+ 'Principal' => {
48
+ 'Service' => 'config.amazonaws.com'
49
+ },
50
+ 'Action' => 'sts:AssumeRole'
51
+ }
52
+ ]
53
+ )
54
+ ManagedPolicyArns(
55
+ [
56
+ 'arn:aws:iam::aws:policy/service-role/AWSConfigRole'
57
+ ])
58
+ end
59
+
60
+ Topic('ConfigServiceTopic') do
61
+ DisplayName 'ConfigSvc'
62
+ Subscription [{
63
+ 'Endpoint' => FnGetAtt('ConfigServiceQueue', 'Arn'),
64
+ 'Protocol' => 'sqs'
65
+ }]
66
+ end
67
+
68
+ Policy('ConfigServiceSNSTopicAccessPolicy') do
69
+ PolicyName 'ConfigServiceSNSTopicAccessPolicy'
70
+ PolicyDocument(
71
+ 'Version' => '2012-10-17',
72
+ 'Statement' =>
73
+ [
74
+ {
75
+ 'Effect' => 'Allow',
76
+ 'Action' => 'sns:Publish',
77
+ 'Resource' => Ref('ConfigServiceTopic')
78
+ }
79
+ ]
80
+ )
81
+ Role Ref('ConfigServiceIAMRole')
82
+ end
83
+
84
+ QueuePolicy('ConfigServiceQueuePolicy') do
85
+ PolicyDocument(
86
+ 'Version' => '2012-10-17',
87
+ 'Statement' => [
88
+ {
89
+ 'Sid' => 'Allow-SendMessage-To-ConfigService-Queue-From-SNS-Topic',
90
+ 'Effect' => 'Allow',
91
+ 'Principal' => '*',
92
+ 'Action' => ['sqs:SendMessage'],
93
+ 'Resource' => '*',
94
+ 'Condition' => {
95
+ 'ArnEquals' => {
96
+ 'aws:SourceArn' => Ref('ConfigServiceTopic')
97
+ }
98
+ }
99
+ }
100
+ ]
101
+ )
102
+ Queues [Ref('ConfigServiceQueue')]
103
+ end
104
+
105
+ DeliveryChannel('ConfigDeliveryChannel') do
106
+ ConfigSnapshotDeliveryProperties(
107
+ 'DeliveryFrequency' => 'Six_Hours'
108
+ )
109
+ S3BucketName Ref('ConfigServiceBucket')
110
+ SnsTopicARN Ref('ConfigServiceTopic')
111
+ end
112
+
113
+ ConfigurationRecorder('ConfigRecorder') do
114
+ Name 'DefaultRecorder'
115
+ RecordingGroup(
116
+ 'AllSupported' => true
117
+ )
118
+ RoleARN FnGetAtt('ConfigServiceIAMRole', 'Arn')
119
+ end
120
+ end
data/sample/ecs.rb CHANGED
@@ -1,51 +1,51 @@
1
- CloudFormation {
2
- DESCRIPTION ||= "ecs description"
1
+ CloudFormation do
2
+ DESCRIPTION ||= 'ecs description'.freeze
3
3
 
4
4
  Description DESCRIPTION
5
5
 
6
- Resource('MyECSCluster') {
6
+ Resource('MyECSCluster') do
7
7
  Type 'AWS::ECS::Cluster'
8
- }
8
+ end
9
9
 
10
- Resource('MyTaskDef') {
10
+ Resource('MyTaskDef') do
11
11
  Type 'AWS::ECS::Service'
12
- Property('ContainerDefinitions', [
13
- {
14
- Command: ['echo hello'],
15
- Cpu: 300,
16
- EntryPoint: ['/bin/bash'],
17
- Environment: [{
18
- Name: 'test',
19
- Value: 'testvalue'
20
- }],
21
- Essential: true,
22
- Image: 'ubuntu:latest',
23
- Links: ['myothercontainer'],
24
- Memory: 1024,
25
- MountPoints: [{
26
- ContainerPath: '/var/log',
27
- SourceVolume: 'log_volume',
28
- ReadOnly: false
29
- }],
30
- Name: 'MyTaskDef',
31
- PortMappings: [{
32
- ContainerPort: 80,
33
- HostPort: 8080
34
- }],
35
- VolumesFrom: [{
36
- SourceContainer: 'myothercontainer',
37
- ReadOnly: true
38
- }]
12
+ Property('ContainerDefinitions',
13
+ [
14
+ {
15
+ Command: ['echo hello'],
16
+ Cpu: 300,
17
+ EntryPoint: ['/bin/bash'],
18
+ Environment: [{
19
+ Name: 'test',
20
+ Value: 'testvalue'
21
+ }],
22
+ Essential: true,
23
+ Image: 'ubuntu:latest',
24
+ Links: ['myothercontainer'],
25
+ Memory: 1024,
26
+ MountPoints: [{
27
+ ContainerPath: '/var/log',
28
+ SourceVolume: 'log_volume',
29
+ ReadOnly: false
30
+ }],
31
+ Name: 'MyTaskDef',
32
+ PortMappings: [{
33
+ ContainerPort: 80,
34
+ HostPort: 8080
35
+ }],
36
+ VolumesFrom: [{
37
+ SourceContainer: 'myothercontainer',
38
+ ReadOnly: true
39
+ }]
40
+ }
41
+ ])
42
+ end
39
43
 
40
- }
41
- ])
42
- }
43
-
44
- Resource('MyECSService') {
44
+ Resource('MyECSService') do
45
45
  Type 'AWS::ECS::Service'
46
46
  Property('Cluster', Ref('MyECSCluster'))
47
47
  Property('DesiredCount', 10)
48
48
  Property('Role', 'ecsServiceRole')
49
49
  Property('TaskDefinition', 'MyTask:1')
50
- }
51
- }
50
+ end
51
+ end
@@ -0,0 +1,82 @@
1
+ CloudFormation do
2
+ AWSTemplateFormatVersion '2010-09-09'
3
+
4
+ Description 'Creates sample IAM policies'
5
+
6
+ ManagedPolicy('AllowUserManagePasswordAccessKeys') do
7
+ Description 'Allows user to manage passwords and access keys'
8
+ PolicyDocument(
9
+ 'Version' => '2012-10-17',
10
+ 'Statement' => [
11
+ {
12
+ 'Effect' => 'Allow',
13
+ 'Action' => [
14
+ 'iam:*LoginProfile',
15
+ 'iam:*AccessKey*',
16
+ 'iam:*SSHPublicKey*'
17
+ ],
18
+ 'Resource' => FnJoin('', ['arn:aws:iam::', Ref('AWS::AccountId'), ':user/${aws:username}'])
19
+ }
20
+ ]
21
+ )
22
+ end
23
+
24
+ ManagedPolicy('AllowUserManageVirtualMFA') do
25
+ Description 'Allows user to manage their virtual MFA device'
26
+ PolicyDocument(
27
+ 'Version' => '2012-10-17',
28
+ 'Statement' => [
29
+ {
30
+ 'Sid' => 'AllowUsersToCreateEnableResyncTheirOwnVirtualMFADevice',
31
+ 'Effect' => 'Allow',
32
+ 'Action' => [
33
+ 'iam:CreateVirtualMFADevice',
34
+ 'iam:EnableMFADevice',
35
+ 'iam:ResyncMFADevice'
36
+ ],
37
+ 'Resource' => [
38
+ FnJoin('', ['arn:aws:iam::', Ref('AWS::AccountId'), ':mfa/${aws:username}']),
39
+ FnJoin('', ['arn:aws:iam::', Ref('AWS::AccountId'), ':user/${aws:username}'])
40
+ ]
41
+ },
42
+ {
43
+ 'Sid' => 'AllowUsersToDeactivateDeleteTheirOwnVirtualMFADevice',
44
+ 'Effect' => 'Allow',
45
+ 'Action' => [
46
+ 'iam:DeactivateMFADevice',
47
+ 'iam:DeleteVirtualMFADevice'
48
+ ],
49
+ 'Resource' => [
50
+ FnJoin('', ['arn:aws:iam::', Ref('AWS::AccountId'), ':mfa/${aws:username}']),
51
+ FnJoin('', ['arn:aws:iam::', Ref('AWS::AccountId'), ':user/${aws:username}'])
52
+ ],
53
+ 'Condition' => {
54
+ 'Bool' => {
55
+ 'aws:MultiFactorAuthPresent' => true
56
+ }
57
+ }
58
+ },
59
+ {
60
+ 'Sid' => 'AllowUsersToListMFADevicesandUsersForConsole',
61
+ 'Effect' => 'Allow',
62
+ 'Action' => [
63
+ 'iam:ListMFADevices',
64
+ 'iam:ListVirtualMFADevices',
65
+ 'iam:ListUsers'
66
+ ],
67
+ 'Resource' => '*'
68
+ }
69
+ ]
70
+ )
71
+ end
72
+
73
+ Output('AllowUserManagePasswordAccessKeysPolicyArn') do
74
+ Description 'The ARN of the AllowUserManagePasswordAccessKeys IAM policy'
75
+ Value Ref('AllowUserManagePasswordAccessKeys')
76
+ end
77
+
78
+ Output('AllowUserManageVirtualMFAPolicyArn') do
79
+ Description 'The ARN of the AllowUserManageVirtualMFA IAM policy'
80
+ Value Ref('AllowUserManageVirtualMFA')
81
+ end
82
+ end
data/sample/lambda.rb CHANGED
@@ -1,38 +1,34 @@
1
- CloudFormation {
2
- DESCRIPTION ||= "lambda description"
1
+ CloudFormation do
2
+ DESCRIPTION ||= 'lambda description'.freeze
3
3
 
4
4
  Description DESCRIPTION
5
5
 
6
- Parameter('Role') { Type "String" }
6
+ Parameter('Role') { Type 'String' }
7
7
 
8
- Resource('LambdaFunction') {
8
+ Resource('LambdaFunction') do
9
9
  Type 'AWS::Lambda::Function'
10
- Property('Handler','index.handler')
11
- Property('Role',Ref('Role'))
12
- Property('Code',{
13
- S3Bucket: "lambda-functions",
14
- S3Key: "amilookup.zip"
15
- })
16
- Property('Runtime','nodejs')
17
- Property('Timeout','25')
18
- }
10
+ Property('Handler', 'index.handler')
11
+ Property('Role', Ref('Role'))
12
+ Property('Code',
13
+ S3Bucket: 'lambda-functions',
14
+ S3Key: 'amilookup.zip'
15
+ )
16
+ Property('Runtime', 'nodejs')
17
+ Property('Timeout', '25')
18
+ end
19
19
 
20
- Resource('EventSourceMapping') {
20
+ Resource('EventSourceMapping') do
21
21
  Type 'AWS::Lambda::EventSourceMapping'
22
- Property('EventSourceArn', FnJoin('',["arn:aws:kinesis:", Ref('AWS::Region'), ":", Ref('AWS::AccountId'), ':stream/test']))
22
+ Property('EventSourceArn', FnJoin('', ['arn:aws:kinesis:', Ref('AWS::Region'), ':', Ref('AWS::AccountId'), ':stream/test']))
23
23
  Property('FunctionName', FnGetAtt('LambdaFunction', 'Arn'))
24
24
  Property('StartingPosition', 'TRIM_HORIZON')
25
- }
25
+ end
26
26
 
27
- Resource('LambdaInvokePermission') {
27
+ Resource('LambdaInvokePermission') do
28
28
  Type 'AWS::Lambda::Permission'
29
29
  Property('FunctionName', FnGetAtt('LambdaFunction', 'Arn'))
30
- Property('Action', [
31
- 'lambda:InvokeFunction'
32
- ])
30
+ Property('Action', ['lambda:InvokeFunction'])
33
31
  Property('Principal', 's3.amazonaws.com')
34
32
  Property('SourceAccount', Ref('AWS::AccountId'))
35
-
36
- }
37
-
38
- }
33
+ end
34
+ end