cfndsl 0.1.16 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ MACHINES: 3
2
+ DESCRIPTION: 3 machine cluster
@@ -0,0 +1,51 @@
1
+ require 'cfndsl'
2
+
3
+ CloudFormation {
4
+ Description "Creates an AWS VPC with a couple of subnets."
5
+
6
+ VPC(:VPC) {
7
+ EnableDnsSupport true
8
+ EnableDnsHostnames true
9
+ CidrBlock "10.1.0.0/16"
10
+ addTag("Name", "Test VPC")
11
+ }
12
+
13
+ InternetGateway(:InternetGateway) {
14
+ addTag("Name", "Test VPC Gateway")
15
+ }
16
+
17
+ VPCGatewayAttachment(:GatewayToInternet) {
18
+ VpcId Ref(:VPC)
19
+ InternetGatewayId Ref(:InternetGateway)
20
+ }
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) {
28
+ VpcId Ref(:VPC)
29
+ CidrBlock "10.1.#{i}.0/24"
30
+ addTag("Name", "test vpc #{subnet}")
31
+ }
32
+
33
+ RouteTable(route_table) {
34
+ VpcId Ref(:VPC)
35
+ addTag("Name", route_table)
36
+ }
37
+
38
+ SubnetRouteTableAssociation(route_table_assoc) {
39
+ SubnetId Ref(subnet)
40
+ RouteTableId Ref(route_table)
41
+ }
42
+
43
+ Route(subnet + "GatewayRoute" ) {
44
+ DependsOn :GatewayToInternet
45
+ RouteTableId Ref(route_table)
46
+ DestinationCidrBlock "0.0.0.0/0"
47
+ GatewayId Ref(:InternetGateway)
48
+ }
49
+ end
50
+
51
+ }
@@ -0,0 +1,151 @@
1
+ require 'spec_helper'
2
+
3
+ describe CfnDsl::CloudFormationTemplate do
4
+
5
+ it 'populates an empty template' do
6
+ expect(subject.to_json).to eq('{"AWSTemplateFormatVersion":"2010-09-09"}')
7
+ end
8
+
9
+ it 'allows the format version to be set' do
10
+ subject.AWSTemplateFormatVersion 'AAAAAA'
11
+ expect(subject.to_json).to eq('{"AWSTemplateFormatVersion":"AAAAAA"}')
12
+ end
13
+
14
+ it 'sets output values' do
15
+ out = subject.Output(:Out) do
16
+ Value 'value'
17
+ Description 'desc'
18
+ end
19
+ spec = self
20
+ out.declare do
21
+ spec.expect(@Value).to spec.eq('value')
22
+ spec.expect(@Description).to spec.eq('desc')
23
+ end
24
+ subject.declare do
25
+ spec.expect(@Outputs.length).to spec.eq(1)
26
+ end
27
+ end
28
+
29
+ it 'validates references' do
30
+ q = subject.Resource('q'){ DependsOn ['r'] }
31
+ r = subject.Resource('r'){ Property('z', Ref('q')) }
32
+ q_refs = q.references Hash.new
33
+ r_refs = r.references Hash.new
34
+ expect(q_refs).to have_key('r')
35
+ expect(q_refs).to_not have_key('q')
36
+ expect(r_refs).to have_key('q')
37
+ expect(r_refs).to_not have_key('r')
38
+ expect(subject.checkRefs.length).to eq(2)
39
+ end
40
+
41
+ it 'is a data-driven language' do
42
+ spec = self
43
+ subject.declare do
44
+ EC2_Instance('Instance') do
45
+ id = ImageId 'aaaaa'
46
+ SecurityGroup 'one'
47
+ SecurityGroup 'two'
48
+ groups = @Properties['SecurityGroups'].value
49
+ spec.expect(id).to spec.eq('aaaaa')
50
+ spec.expect(groups).to spec.eq(['one', 'two'])
51
+ end
52
+ end
53
+ end
54
+
55
+ it 'singularizes indirectly' do
56
+ user = subject.User 'TestUser'
57
+ policy = user.Policy 'stuff'
58
+ expect(policy).to eq('stuff')
59
+
60
+ result2 = user.Policy do
61
+ PolicyName 'stuff'
62
+ PolicyDocument(a: 7)
63
+ end
64
+
65
+ expect(result2).to be_a(CfnDsl::AWSTypes::IAMEmbeddedPolicy)
66
+ expect(user.instance_variable_get('@Properties')['Policies'].value.length).to eq(2)
67
+ end
68
+
69
+ it 'handles pseudo parameters' do
70
+ [
71
+ 'AWS::AccountId',
72
+ 'AWS::NotificationARNs',
73
+ 'AWS::NoValue',
74
+ 'AWS::Region',
75
+ 'AWS::StackId',
76
+ 'AWS::StackName'
77
+ ].each do |param|
78
+ ref = subject.Ref param
79
+ expect(ref.to_json).to eq("{\"Ref\":\"#{param}\"}")
80
+ refs = ref.references({})
81
+ expect(refs).to have_key(param)
82
+ end
83
+ end
84
+
85
+ context 'built-in functions' do
86
+ it 'FnGetAtt' do
87
+ func = subject.FnGetAtt('A', 'B')
88
+ expect(func.to_json).to eq('{"Fn::GetAtt":["A","B"]}')
89
+ end
90
+
91
+ it 'FnJoin' do
92
+ func = subject.FnJoin('A', ['B', 'C'])
93
+ expect(func.to_json).to eq('{"Fn::Join":["A",["B","C"]]}')
94
+ end
95
+
96
+ it 'Ref' do
97
+ ref = subject.Ref 'X'
98
+ expect(ref.to_json).to eq('{"Ref":"X"}')
99
+ refs = ref.references Hash.new
100
+ expect(refs).to have_key('X')
101
+ end
102
+
103
+ it 'FnBase64' do
104
+ func = subject.FnBase64 'A'
105
+ expect(func.to_json).to eq('{"Fn::Base64":"A"}')
106
+ end
107
+
108
+ it 'FnFindInMap' do
109
+ func = subject.FnFindInMap('map', 'key', 'value')
110
+ expect(func.to_json).to eq('{"Fn::FindInMap":["map","key","value"]}')
111
+ end
112
+
113
+ it 'FnGetAZs' do
114
+ func = subject.FnGetAZs 'reg'
115
+ expect(func.to_json).to eq('{"Fn::GetAZs":"reg"}')
116
+ end
117
+
118
+ context 'FnFormat', 'String' do
119
+ it 'formats correctly' do
120
+ func = subject.FnFormat('abc%0def%1ghi%%x', 'A', 'B')
121
+ expect(func.to_json).to eq('{"Fn::Join":["",["abc","A","def","B","ghi","%","x"]]}')
122
+ end
123
+ end
124
+
125
+ context 'FnFormat', 'Hash' do
126
+ it 'formats correctly' do
127
+ func = subject.FnFormat('abc%{first}def%{second}ghi%%x', first: 'A', second: 'B')
128
+ expect(func.to_json).to eq('{"Fn::Join":["",["abc","A","def","B","ghi","%","x"]]}')
129
+ end
130
+ end
131
+
132
+ context 'FnFormat', 'Multiline' do
133
+ it 'formats correctly' do
134
+ multiline = <<-EOF.gsub(/^ {10}/, '')
135
+ This is the first line
136
+ This is the %0 line
137
+ This is a %% sign
138
+ EOF
139
+ func = subject.FnFormat(multiline, 'second')
140
+ expect(func.to_json).to eq('{"Fn::Join":["",["This is the first line\nThis is the ","second"," line\nThis is a ","%"," sign\n"]]}')
141
+ end
142
+ end
143
+
144
+ context 'FnFormat', 'Ref' do
145
+ it 'formats correctly' do
146
+ func = subject.FnFormat '123%{Test}456'
147
+ expect(func.to_json).to eq('{"Fn::Join":["",["123",{"Ref":"Test"},"456"]]}')
148
+ end
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,23 @@
1
+ Heat {
2
+ Description "Test"
3
+
4
+ Parameter("One") {
5
+ String
6
+ Default "Test"
7
+ MaxLength 15
8
+ }
9
+
10
+ Parameter('Two') {
11
+ String
12
+ Default 'Test'
13
+ MaxLength 15
14
+ }
15
+
16
+ Output(:One, FnBase64(Ref("One")))
17
+
18
+ Server("MyInstance") {
19
+ flavor "asdfa"
20
+ image "asdad"
21
+ }
22
+
23
+ }
@@ -0,0 +1,79 @@
1
+ CloudFormation {
2
+
3
+ TEST ||= "no value set"
4
+ puts TEST
5
+
6
+ Description "Test"
7
+
8
+ Parameter("One") {
9
+ String
10
+ Default "Test"
11
+ MaxLength 15
12
+ }
13
+
14
+ Parameter('Two') {
15
+ String
16
+ Default 'Test'
17
+ MaxLength 15
18
+ }
19
+
20
+ # Condition Function examples
21
+ Condition('OneIsTest', FnEquals(Ref('One'), 'Test'))
22
+ Condition('OneIsNotTest', FnNot(FnEquals(Ref('One'), 'Test')))
23
+ Condition('OneIsTestAndTwoIsTest', FnAnd([
24
+ FnEquals(Ref('One'), 'Test'),
25
+ FnNot(FnEquals(Ref('Two'), 'Test')),
26
+ ]))
27
+
28
+ Condition('OneIsTestOrTwoIsTest', FnOr([
29
+ FnEquals(Ref('One'), 'Test'),
30
+ FnEquals(Ref('Two'), 'Test'),
31
+ ]))
32
+
33
+ Output(:One, FnBase64(Ref("One")))
34
+
35
+ Resource("MyInstance") {
36
+ Condition 'OneIsNotTest'
37
+ Type "AWS::EC2::Instance"
38
+ Property("ImageId", "ami-14341342")
39
+ }
40
+
41
+ LaunchConfiguration("Second") {
42
+ Condition 'OneIsNotTest'
43
+ BlockDeviceMapping {
44
+ DeviceName "/dev/sda"
45
+ VirtualName "stuff"
46
+ Ebs {
47
+ SnapshotId "asdasdfasdf"
48
+ VolumeSize Ref("MyInstance")
49
+ }
50
+ }
51
+ }
52
+
53
+ Parameter("ElbSubnets") {
54
+ Type "CommaDelimitedList"
55
+ Default "subnet-12345, subnet-54321"
56
+ }
57
+
58
+ Resource("ElasticLoadBalancer") {
59
+ Type "AWS::ElasticLoadBalancing::LoadBalancer"
60
+ Property("Subnets", [ FnSelect("0", Ref("ElbSubnets")), FnSelect("1", Ref("ElbSubnets")) ] )
61
+ }
62
+
63
+ AutoScalingGroup("ASG") {
64
+ UpdatePolicy("AutoScalingRollingUpdate", {
65
+ "MinInstancesInService" => "1",
66
+ "MaxBatchSize" => "1",
67
+ "PauseTime" => "PT15M"
68
+ })
69
+ AvailabilityZones FnGetAZs("")
70
+ LaunchConfigurationName Ref("LaunchConfig")
71
+ MinSize 1
72
+ MaxSize FnIf('OneIsTest', 1, 3)
73
+ LoadBalancerNames Ref("ElasticLoadBalancer")
74
+ }
75
+
76
+ LaunchConfiguration("LaunchConfig")
77
+
78
+ #UndefinedResource("asddfasdf")
79
+ }
@@ -0,0 +1 @@
1
+ require 'cfndsl'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfndsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Jack
@@ -9,20 +9,20 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-06-15 00:00:00.000000000 Z
12
+ date: 2015-06-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ! '>='
19
19
  - !ruby/object:Gem::Version
20
20
  version: '0'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ! '>='
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  description: DSL for creating AWS Cloudformation templates
@@ -34,27 +34,46 @@ executables:
34
34
  extensions: []
35
35
  extra_rdoc_files: []
36
36
  files:
37
+ - .gitignore
38
+ - .travis.yml
39
+ - Gemfile
40
+ - LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - bin/cfndsl
44
+ - cfndsl.gemspec
37
45
  - lib/cfndsl.rb
38
- - lib/cfndsl/aws_types.yaml
39
- - lib/cfndsl/os_types.yaml
40
- - lib/cfndsl/JSONable.rb
41
- - lib/cfndsl/module.rb
42
- - lib/cfndsl/RefCheck.rb
43
- - lib/cfndsl/Types.rb
44
- - lib/cfndsl/Properties.rb
46
+ - lib/cfndsl/CloudFormationTemplate.rb
45
47
  - lib/cfndsl/Conditions.rb
48
+ - lib/cfndsl/CreationPolicy.rb
49
+ - lib/cfndsl/Errors.rb
50
+ - lib/cfndsl/JSONable.rb
46
51
  - lib/cfndsl/Mappings.rb
47
- - lib/cfndsl/Resources.rb
48
52
  - lib/cfndsl/Metadata.rb
49
- - lib/cfndsl/Parameters.rb
50
53
  - lib/cfndsl/Outputs.rb
51
- - lib/cfndsl/Errors.rb
54
+ - lib/cfndsl/Parameters.rb
52
55
  - lib/cfndsl/Plurals.rb
53
- - lib/cfndsl/names.rb
54
- - lib/cfndsl/CloudFormationTemplate.rb
55
- - lib/cfndsl/CreationPolicy.rb
56
+ - lib/cfndsl/Properties.rb
57
+ - lib/cfndsl/RefCheck.rb
58
+ - lib/cfndsl/Resources.rb
59
+ - lib/cfndsl/Types.rb
56
60
  - lib/cfndsl/UpdatePolicy.rb
57
- - bin/cfndsl
61
+ - lib/cfndsl/aws_types.yaml
62
+ - lib/cfndsl/module.rb
63
+ - lib/cfndsl/names.rb
64
+ - lib/cfndsl/os_types.yaml
65
+ - lib/cfndsl/version.rb
66
+ - sample/autoscale.rb
67
+ - sample/autoscale.template
68
+ - sample/autoscale2.rb
69
+ - sample/circular.rb
70
+ - sample/t1.rb
71
+ - sample/t1.yaml
72
+ - sample/vpc-example.rb
73
+ - spec/cfndsl_spec.rb
74
+ - spec/fixtures/heattest.rb
75
+ - spec/fixtures/test.rb
76
+ - spec/spec_helper.rb
58
77
  homepage: https://github.com/stevenjack/cfndsl
59
78
  licenses:
60
79
  - MIT
@@ -65,18 +84,22 @@ require_paths:
65
84
  - lib
66
85
  required_ruby_version: !ruby/object:Gem::Requirement
67
86
  requirements:
68
- - - '>='
87
+ - - ! '>='
69
88
  - !ruby/object:Gem::Version
70
89
  version: '0'
71
90
  required_rubygems_version: !ruby/object:Gem::Requirement
72
91
  requirements:
73
- - - '>='
92
+ - - ! '>='
74
93
  - !ruby/object:Gem::Version
75
94
  version: '0'
76
95
  requirements: []
77
96
  rubyforge_project:
78
- rubygems_version: 2.0.14
97
+ rubygems_version: 2.4.5
79
98
  signing_key:
80
99
  specification_version: 4
81
100
  summary: AWS Cloudformation DSL
82
- test_files: []
101
+ test_files:
102
+ - spec/cfndsl_spec.rb
103
+ - spec/fixtures/heattest.rb
104
+ - spec/fixtures/test.rb
105
+ - spec/spec_helper.rb