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/s3.rb CHANGED
@@ -1,9 +1,9 @@
1
- CloudFormation {
2
- S3_Bucket('Bucket') {
1
+ CloudFormation do
2
+ S3_Bucket('Bucket') do
3
3
  BucketName 'MyBucket'
4
4
  VersioningConfiguration(Status: 'Enabled')
5
5
  NotificationConfiguration(
6
- LambdaConfigurations: [
6
+ LambdaConfigurations: [
7
7
  {
8
8
  Function: 'MyLambdaFunction',
9
9
  Event: 'S3:ObjectCreated:*'
@@ -13,13 +13,13 @@ CloudFormation {
13
13
  Event: 's3:ObjectRemoved:*'
14
14
  }
15
15
  ],
16
- QueueConfigurations: [
16
+ QueueConfigurations: [
17
17
  {
18
18
  Queue: 'SQSQueue',
19
19
  Event: 'S3:ObjectCreated:*'
20
20
  }
21
21
  ],
22
- TopicConfigurations: [
22
+ TopicConfigurations: [
23
23
  {
24
24
  Topic: 'SNSTopic',
25
25
  Event: 'S3:ObjectCreated:*'
@@ -32,15 +32,15 @@ CloudFormation {
32
32
  RoutingRules: [
33
33
  {
34
34
  RoutingRuleCondition: {
35
- HttpErrorCodeReturnedEquals: "404",
36
- KeyPrefixEquals: "out1/"
35
+ HttpErrorCodeReturnedEquals: '404',
36
+ KeyPrefixEquals: 'out1/'
37
37
  },
38
38
  RedirectRule: {
39
- HostName: "ec2-11-22-333-44.compute-1.amazonaws.com",
40
- ReplaceKeyPrefixWith: "report-404/"
39
+ HostName: 'ec2-11-22-333-44.compute-1.amazonaws.com',
40
+ ReplaceKeyPrefixWith: 'report-404/'
41
41
  }
42
42
  }
43
43
  ]
44
44
  )
45
- }
46
- }
45
+ end
46
+ end
data/sample/t1.rb CHANGED
@@ -1,16 +1,14 @@
1
- CloudFormation {
2
-
3
- DESCRIPTION ||= "default description"
1
+ CloudFormation do
2
+ DESCRIPTION ||= 'default description'.freeze
4
3
  MACHINES ||= 1
5
4
 
6
5
  Description DESCRIPTION
7
6
 
8
7
  (1..MACHINES).each do |i|
9
8
  name = "machine#{i}"
10
- Instance(name) {
11
- ImageId "ami-12345678"
12
- Type "t1.micro"
13
- }
9
+ Instance(name) do
10
+ ImageId 'ami-12345678'
11
+ Type 't1.micro'
12
+ end
14
13
  end
15
-
16
- }
14
+ end
@@ -0,0 +1,50 @@
1
+ require 'cfndsl'
2
+
3
+ CloudFormation do
4
+ Description 'Creates an AWS VPC with a couple of subnets.'
5
+
6
+ VPC(:VPC) do
7
+ EnableDnsSupport true
8
+ EnableDnsHostnames true
9
+ CidrBlock '10.1.0.0/16'
10
+ addTag('Name', 'Test VPC')
11
+ end
12
+
13
+ InternetGateway(:InternetGateway) do
14
+ addTag('Name', 'Test VPC Gateway')
15
+ end
16
+
17
+ VPCGatewayAttachment(:GatewayToInternet) do
18
+ VpcId Ref(:VPC)
19
+ InternetGatewayId Ref(:InternetGateway)
20
+ end
21
+
22
+ 10.times do |i|
23
+ subnet = "subnet#{i}"
24
+ route_table = subnet + 'RouteTable'
25
+ route_table_assoc = route_table + 'Assoc'
26
+
27
+ Subnet(subnet) do
28
+ VpcId Ref(:VPC)
29
+ CidrBlock "10.1.#{i}.0/24"
30
+ addTag('Name', "test vpc #{subnet}")
31
+ end
32
+
33
+ RouteTable(route_table) do
34
+ VpcId Ref(:VPC)
35
+ addTag('Name', route_table)
36
+ end
37
+
38
+ SubnetRouteTableAssociation(route_table_assoc) do
39
+ SubnetId Ref(subnet)
40
+ RouteTableId Ref(route_table)
41
+ end
42
+
43
+ Route(subnet + 'GatewayRoute') do
44
+ DependsOn :GatewayToInternet
45
+ RouteTableId Ref(route_table)
46
+ DestinationCidrBlock '0.0.0.0/0'
47
+ GatewayId Ref(:InternetGateway)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,97 @@
1
+ require 'cfndsl'
2
+
3
+ CloudFormation do
4
+ Description 'Creates an AWS VPC with a couple of subnets.'
5
+
6
+ Parameter('VPNAddress') do
7
+ Type 'String'
8
+ Description 'IP Address range for your existing infrastructure'
9
+ MinLength '9'
10
+ MaxLength '18'
11
+ AllowedPattern '(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})'
12
+ ConstraintDescription 'must be a valid IP CIDR range of the form x.x.x.x/x.'
13
+ end
14
+
15
+ Parameter('RouterIPAddress') do
16
+ Type 'String'
17
+ Description 'IP Address of your VPN device'
18
+ MinLength '7'
19
+ MaxLength '15'
20
+ AllowedPattern '(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})'
21
+ ConstraintDescription 'must be a valid IP address of the form x.x.x.x'
22
+ end
23
+
24
+ VPC(:VPC) do
25
+ EnableDnsSupport true
26
+ EnableDnsHostnames true
27
+ CidrBlock '10.1.0.0/16'
28
+ addTag('Name', 'Test VPC')
29
+ end
30
+
31
+ InternetGateway(:InternetGateway) do
32
+ addTag('Name', 'Test VPC Gateway')
33
+ end
34
+
35
+ VPCGatewayAttachment(:GatewayToInternet) do
36
+ VpcId Ref(:VPC)
37
+ InternetGatewayId Ref(:InternetGateway)
38
+ end
39
+
40
+ 10.times do |i|
41
+ subnet = "subnet#{i}"
42
+ route_table = subnet + 'RouteTable'
43
+ route_table_assoc = route_table + 'Assoc'
44
+
45
+ Subnet(subnet) do
46
+ VpcId Ref(:VPC)
47
+ CidrBlock "10.1.#{i}.0/24"
48
+ addTag('Name', "test vpc #{subnet}")
49
+ end
50
+
51
+ RouteTable(route_table) do
52
+ VpcId Ref(:VPC)
53
+ addTag('Name', route_table)
54
+ end
55
+
56
+ SubnetRouteTableAssociation(route_table_assoc) do
57
+ SubnetId Ref(subnet)
58
+ RouteTableId Ref(route_table)
59
+ end
60
+
61
+ Route(subnet + 'GatewayRoute') do
62
+ DependsOn :GatewayToInternet
63
+ RouteTableId Ref(route_table)
64
+ DestinationCidrBlock '0.0.0.0/0'
65
+ GatewayId Ref(:InternetGateway)
66
+ end
67
+ end
68
+
69
+ VPNGateway(:VirtualPrivateNetworkGateway) do
70
+ Type 'ipsec.1'
71
+ addTag('Name', 'Test VPN Gateway')
72
+ end
73
+
74
+ VPCGatewayAttachment(:VPNGatewayAttachment) do
75
+ VpcId Ref(:VPC)
76
+ VpnGatewayId Ref(:VirtualPrivateNetworkGateway)
77
+ end
78
+
79
+ CustomerGateway(:CustomerVPNGateway) do
80
+ Type 'ipsec.1'
81
+ BgpAsn '65000'
82
+ IpAddress Ref('RouterIPAddress')
83
+ addTag('Name', 'Test Customer VPN Gateway')
84
+ end
85
+
86
+ VPNConnection(:VPNConnection) do
87
+ Type 'ipsec.1'
88
+ StaticRoutesOnly 'true'
89
+ CustomerGatewayId Ref(:CustomerVPNGateway)
90
+ VpnGatewayId Ref(:VirtualPrivateNetworkGateway)
91
+ end
92
+
93
+ VPNConnectionRoute(:VPNConnectionRoute) do
94
+ VpnConnectionId Ref(:VPNConnection)
95
+ DestinationCidrBlock Ref('VPNAddress')
96
+ end
97
+ end
data/spec/cfndsl_spec.rb CHANGED
@@ -1,5 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
+ describe CfnDsl do
4
+ it 'evaluates a cloud formation' do
5
+ filename = "#{File.dirname(__FILE__)}/fixtures/test.rb"
6
+ subject.eval_file_with_extras(filename)
7
+ end
8
+
9
+ it 'evaluates a heat' do
10
+ filename = "#{File.dirname(__FILE__)}/fixtures/heattest.rb"
11
+ subject.eval_file_with_extras(filename)
12
+ end
13
+ end
14
+
3
15
  describe CfnDsl::HeatTemplate do
4
16
  it 'honors last-set value for non-array properties' do
5
17
  spec = self
@@ -15,7 +27,6 @@ describe CfnDsl::HeatTemplate do
15
27
  end
16
28
 
17
29
  describe CfnDsl::CloudFormationTemplate do
18
-
19
30
  it 'populates an empty template' do
20
31
  expect(subject.to_json).to eq('{"AWSTemplateFormatVersion":"2010-09-09"}')
21
32
  end
@@ -41,15 +52,15 @@ describe CfnDsl::CloudFormationTemplate do
41
52
  end
42
53
 
43
54
  it 'validates references' do
44
- q = subject.Resource('q'){ DependsOn ['r'] }
45
- r = subject.Resource('r'){ Property('z', Ref('q')) }
46
- q_refs = q.references Hash.new
47
- r_refs = r.references Hash.new
55
+ q = subject.Resource('q') { DependsOn ['r'] }
56
+ r = subject.Resource('r') { Property('z', Ref('q')) }
57
+ q_refs = q.build_references({})
58
+ r_refs = r.build_references({})
48
59
  expect(q_refs).to have_key('r')
49
60
  expect(q_refs).to_not have_key('q')
50
61
  expect(r_refs).to have_key('q')
51
62
  expect(r_refs).to_not have_key('r')
52
- expect(subject.checkRefs.length).to eq(2)
63
+ expect(subject.check_refs.length).to eq(2)
53
64
  end
54
65
 
55
66
  it 'is a data-driven language' do
@@ -61,7 +72,7 @@ describe CfnDsl::CloudFormationTemplate do
61
72
  SecurityGroup 'two'
62
73
  groups = @Properties['SecurityGroups'].value
63
74
  spec.expect(id).to spec.eq('aaaaa')
64
- spec.expect(groups).to spec.eq(['one', 'two'])
75
+ spec.expect(groups).to spec.eq(%w(one two))
65
76
  end
66
77
  end
67
78
  end
@@ -76,7 +87,7 @@ describe CfnDsl::CloudFormationTemplate do
76
87
  PolicyDocument(a: 7)
77
88
  end
78
89
 
79
- expect(result2).to be_a(CfnDsl::AWSTypes::IAMEmbeddedPolicy)
90
+ expect(result2).to be_a(CfnDsl::AWS::Types::IAMEmbeddedPolicy)
80
91
  expect(user.instance_variable_get('@Properties')['Policies'].value.length).to eq(2)
81
92
  end
82
93
 
@@ -91,7 +102,7 @@ describe CfnDsl::CloudFormationTemplate do
91
102
  ].each do |param|
92
103
  ref = subject.Ref param
93
104
  expect(ref.to_json).to eq("{\"Ref\":\"#{param}\"}")
94
- refs = ref.references({})
105
+ refs = ref.build_references({})
95
106
  expect(refs).to have_key(param)
96
107
  end
97
108
  end
@@ -115,14 +126,14 @@ describe CfnDsl::CloudFormationTemplate do
115
126
  end
116
127
 
117
128
  it 'FnJoin' do
118
- func = subject.FnJoin('A', ['B', 'C'])
129
+ func = subject.FnJoin('A', %w(B C))
119
130
  expect(func.to_json).to eq('{"Fn::Join":["A",["B","C"]]}')
120
131
  end
121
132
 
122
133
  it 'Ref' do
123
134
  ref = subject.Ref 'X'
124
135
  expect(ref.to_json).to eq('{"Ref":"X"}')
125
- refs = ref.references Hash.new
136
+ refs = ref.build_references({})
126
137
  expect(refs).to have_key('X')
127
138
  end
128
139
 
@@ -1,23 +1,22 @@
1
- Heat {
2
- Description "Test"
1
+ Heat do
2
+ Description 'Test'
3
3
 
4
- Parameter("One") {
4
+ Parameter('One') do
5
5
  String
6
- Default "Test"
6
+ Default 'Test'
7
7
  MaxLength 15
8
- }
8
+ end
9
9
 
10
- Parameter('Two') {
10
+ Parameter('Two') do
11
11
  String
12
12
  Default 'Test'
13
13
  MaxLength 15
14
- }
15
-
16
- Output(:One, FnBase64(Ref("One")))
14
+ end
17
15
 
18
- Server("MyInstance") {
19
- flavor "asdfa"
20
- image "asdad"
21
- }
16
+ Output(:One, FnBase64(Ref('One')))
22
17
 
23
- }
18
+ Server('MyInstance') do
19
+ flavor 'asdfa'
20
+ image 'asdad'
21
+ end
22
+ end
@@ -1,79 +1,82 @@
1
- CloudFormation {
2
-
3
- TEST ||= "no value set"
1
+ CloudFormation do
2
+ TEST ||= 'no value set'.freeze
4
3
  puts TEST
5
4
 
6
- Description "Test"
5
+ Description 'Test'
7
6
 
8
- Parameter("One") {
7
+ Parameter('One') do
9
8
  String
10
- Default "Test"
9
+ Default 'Test'
11
10
  MaxLength 15
12
- }
11
+ end
13
12
 
14
- Parameter('Two') {
13
+ Parameter('Two') do
15
14
  String
16
15
  Default 'Test'
17
16
  MaxLength 15
18
- }
17
+ end
19
18
 
20
19
  # Condition Function examples
21
20
  Condition('OneIsTest', FnEquals(Ref('One'), 'Test'))
22
21
  Condition('OneIsNotTest', FnNot(FnEquals(Ref('One'), 'Test')))
23
- Condition('OneIsTestAndTwoIsTest', FnAnd([
24
- FnEquals(Ref('One'), 'Test'),
25
- FnNot(FnEquals(Ref('Two'), 'Test')),
26
- ]))
22
+ Condition('OneIsTestAndTwoIsTest',
23
+ FnAnd(
24
+ [
25
+ FnEquals(Ref('One'), 'Test'),
26
+ FnNot(FnEquals(Ref('Two'), 'Test'))
27
+ ]))
27
28
 
28
- Condition('OneIsTestOrTwoIsTest', FnOr([
29
- FnEquals(Ref('One'), 'Test'),
30
- FnEquals(Ref('Two'), 'Test'),
31
- ]))
29
+ Condition('OneIsTestOrTwoIsTest',
30
+ FnOr(
31
+ [
32
+ FnEquals(Ref('One'), 'Test'),
33
+ FnEquals(Ref('Two'), 'Test')
34
+ ]))
32
35
 
33
- Output(:One, FnBase64(Ref("One")))
36
+ Output(:One, FnBase64(Ref('One')))
34
37
 
35
- Resource("MyInstance") {
38
+ Resource('MyInstance') do
36
39
  Condition 'OneIsNotTest'
37
- Type "AWS::EC2::Instance"
38
- Property("ImageId", "ami-14341342")
39
- }
40
+ Type 'AWS::EC2::Instance'
41
+ Property('ImageId', 'ami-14341342')
42
+ end
40
43
 
41
- LaunchConfiguration("Second") {
44
+ LaunchConfiguration('Second') do
42
45
  Condition 'OneIsNotTest'
43
- BlockDeviceMapping {
44
- DeviceName "/dev/sda"
45
- VirtualName "stuff"
46
- Ebs {
47
- SnapshotId "asdasdfasdf"
48
- VolumeSize Ref("MyInstance")
49
- }
50
- }
51
- }
46
+ BlockDeviceMapping do
47
+ DeviceName '/dev/sda'
48
+ VirtualName 'stuff'
49
+ Ebs do
50
+ SnapshotId 'asdasdfasdf'
51
+ VolumeSize Ref('MyInstance')
52
+ end
53
+ end
54
+ end
52
55
 
53
- Parameter("ElbSubnets") {
54
- Type "CommaDelimitedList"
55
- Default "subnet-12345, subnet-54321"
56
- }
56
+ Parameter('ElbSubnets') do
57
+ Type 'CommaDelimitedList'
58
+ Default 'subnet-12345, subnet-54321'
59
+ end
57
60
 
58
- Resource("ElasticLoadBalancer") {
59
- Type "AWS::ElasticLoadBalancing::LoadBalancer"
60
- Property("Subnets", [ FnSelect("0", Ref("ElbSubnets")), FnSelect("1", Ref("ElbSubnets")) ] )
61
- }
61
+ Resource('ElasticLoadBalancer') do
62
+ Type 'AWS::ElasticLoadBalancing::LoadBalancer'
63
+ Property('Subnets', [FnSelect('0', Ref('ElbSubnets')), FnSelect('1', Ref('ElbSubnets'))])
64
+ end
62
65
 
63
- AutoScalingGroup("ASG") {
64
- UpdatePolicy("AutoScalingRollingUpdate", {
65
- "MinInstancesInService" => "1",
66
- "MaxBatchSize" => "1",
67
- "PauseTime" => "PT15M"
68
- })
69
- AvailabilityZones FnGetAZs("")
70
- LaunchConfigurationName Ref("LaunchConfig")
66
+ AutoScalingGroup('ASG') do
67
+ UpdatePolicy('AutoScalingRollingUpdate',
68
+ 'MinInstancesInService' => '1',
69
+ 'MaxBatchSize' => '1',
70
+ 'PauseTime' => 'PT15M'
71
+ )
72
+ AvailabilityZones FnGetAZs('')
73
+ LaunchConfigurationName Ref('LaunchConfig')
71
74
  MinSize 1
72
75
  MaxSize FnIf('OneIsTest', 1, 3)
73
- LoadBalancerNames Ref("ElasticLoadBalancer")
74
- }
76
+ LoadBalancerNames Ref('ElasticLoadBalancer')
77
+ end
75
78
 
76
- LaunchConfiguration("LaunchConfig")
79
+ LaunchConfiguration('LaunchConfig')
77
80
 
78
- #UndefinedResource("asddfasdf")
79
- }
81
+ # UndefinedResource('asddfasdf')
82
+ end