cfndsl 0.1.20 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/README.md +39 -16
- data/lib/cfndsl/aws_types.yaml +1 -0
- data/lib/cfndsl/rake_task.rb +54 -0
- data/lib/cfndsl/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZThkNTZjYmU1ZTA5YTFkYjAwODJmMTMxNzFhZGY0YzQxMDJlZDgzMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjhjZGRkYWNkMTI5ZDlkMjY2MmYyMmI4MTRhZDk2ZWNjMGI0YjU4NA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Njc2OTRlNzUzN2JkYmZiNzYyYjRkMzgxOTI4NjA4ZmQ5MGRmZDA4YjBkYWYw
|
10
|
+
OWQ3YmYwMzYyOTI0NjhiNzdhMGFiZDkyMzkzZDZkODVmNzBiMmQzNTY5YTQ0
|
11
|
+
OWQzYTZmM2JmY2YwOWQ3YmQxYjRjODY4NDk0MjYwMzY4OTNjOTA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGJhN2FjNzIyNTBmMzg5Yzk3NzVlMzFiYzAzNjljNjY1YmI0NjVlMjRjODc0
|
14
|
+
MTg5ZDUyZWNkZTEyM2EzNWUzMWRkYjc1OTY1MDNhZWZmZGY3YTcxODhjZTE4
|
15
|
+
YWE1YzM4NDVhYTRhM2Y3ZmRkNDIyNjk1OWZhODU1NTQyM2Q5MDI=
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ maintain:
|
|
14
14
|
|
15
15
|
* All structures are JSON, so it is sometimes easy for a person
|
16
16
|
reading a template to get lost.
|
17
|
-
|
17
|
+
|
18
18
|
* References and internal functions have a particularly unpleasant syntax.
|
19
19
|
|
20
20
|
|
@@ -25,26 +25,26 @@ templates by running ruby.
|
|
25
25
|
## Getting Started
|
26
26
|
|
27
27
|
sudo gem install cfndsl
|
28
|
-
|
28
|
+
|
29
29
|
Now write a template in the dsl
|
30
|
-
|
30
|
+
|
31
31
|
```ruby
|
32
32
|
|
33
33
|
CloudFormation {
|
34
34
|
Description "Test"
|
35
|
-
|
35
|
+
|
36
36
|
Parameter("One") {
|
37
37
|
String
|
38
38
|
Default "Test"
|
39
39
|
MaxLength 15
|
40
40
|
}
|
41
|
-
|
41
|
+
|
42
42
|
Output(:One,FnBase64( Ref("One")))
|
43
43
|
|
44
44
|
EC2_Instance(:MyInstance) {
|
45
45
|
ImageId "ami-12345678"
|
46
46
|
}
|
47
|
-
|
47
|
+
|
48
48
|
}
|
49
49
|
```
|
50
50
|
|
@@ -88,12 +88,12 @@ this gem was done on a [Raspberry Pi](http://www.raspberrypi.org).*
|
|
88
88
|
## Samples
|
89
89
|
|
90
90
|
There is a more detailed example in the samples directory. The file
|
91
|
-
"autoscale.template" is one of the standard Amazon sample templates.
|
91
|
+
"autoscale.template" is one of the standard Amazon sample templates.
|
92
92
|
"autoscale.rb" generates an equivalent template file.
|
93
93
|
|
94
94
|
## Command Line Options
|
95
95
|
|
96
|
-
The cfndsl command line program now accepts some command line options.
|
96
|
+
The cfndsl command line program now accepts some command line options.
|
97
97
|
|
98
98
|
```
|
99
99
|
Usage: cfndsl [options] FILE
|
@@ -106,18 +106,18 @@ Usage: cfndsl [options] FILE
|
|
106
106
|
-h, --help Display this screen
|
107
107
|
```
|
108
108
|
|
109
|
-
By default, cfndsl will attempt to evaluate FILE as cfndsl template and print
|
109
|
+
By default, cfndsl will attempt to evaluate FILE as cfndsl template and print
|
110
110
|
the resulting cloudformation json template to stdout. With the -o option, you
|
111
|
-
can instead have it write the resulting json template to a given file. The -v
|
111
|
+
can instead have it write the resulting json template to a given file. The -v
|
112
112
|
option prints out additional information (to stderr) about what is happening
|
113
|
-
in the model generation process.
|
113
|
+
in the model generation process.
|
114
114
|
|
115
115
|
The -y, -j, -r and -D options can be used to control some things about the
|
116
116
|
environment that the template code gets evaluate in. For instance, the -D
|
117
|
-
option allows you to set a variable at the command line that can then be
|
117
|
+
option allows you to set a variable at the command line that can then be
|
118
118
|
referred to within the template itself.
|
119
119
|
|
120
|
-
This is best illustrated with a example. Consider the following cfndsl
|
120
|
+
This is best illustrated with a example. Consider the following cfndsl
|
121
121
|
template
|
122
122
|
|
123
123
|
```ruby
|
@@ -136,7 +136,7 @@ CloudFormation {
|
|
136
136
|
Type "t1.micro"
|
137
137
|
}
|
138
138
|
end
|
139
|
-
|
139
|
+
|
140
140
|
}
|
141
141
|
```
|
142
142
|
|
@@ -196,7 +196,7 @@ you get the following generated template.
|
|
196
196
|
```
|
197
197
|
|
198
198
|
The -y and -j options allow you to group several variable definitions
|
199
|
-
into a single file (formated as either yaml or ruby respectively). If
|
199
|
+
into a single file (formated as either yaml or ruby respectively). If
|
200
200
|
you had a file called 't1.yaml' that contained the following,
|
201
201
|
|
202
202
|
```yaml
|
@@ -215,7 +215,30 @@ would generate a template with 5 instances declared.
|
|
215
215
|
|
216
216
|
Finally, the -r option gives you the opportunity to execute some
|
217
217
|
arbitrary ruby code in the evaluation context before the cloudformation
|
218
|
-
template is evaluated.
|
218
|
+
template is evaluated.
|
219
219
|
|
220
|
+
### Rake task
|
221
|
+
Simply add the following to your `Rakefile`:
|
220
222
|
|
223
|
+
```ruby
|
224
|
+
require 'cfndsl/rake_task'
|
225
|
+
|
226
|
+
CfnDsl::RakeTask.new do |t|
|
227
|
+
t.cfndsl_opts = {
|
228
|
+
verbose: true,
|
229
|
+
files: [{
|
230
|
+
filename: 'templates/application.rb',
|
231
|
+
output: 'application.json'
|
232
|
+
}],
|
233
|
+
extras: [
|
234
|
+
[ :yaml, 'templates/default_params.yml' ]
|
235
|
+
]
|
236
|
+
}
|
237
|
+
end
|
238
|
+
```
|
221
239
|
|
240
|
+
And then use rake to generate the cloudformation:
|
241
|
+
|
242
|
+
```bash
|
243
|
+
$ bin/rake generate
|
244
|
+
```
|
data/lib/cfndsl/aws_types.yaml
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
require "rake"
|
2
|
+
require "rake/tasklib"
|
3
|
+
require "cfndsl"
|
4
|
+
|
5
|
+
module CfnDsl
|
6
|
+
class RakeTask < Rake::TaskLib
|
7
|
+
attr_accessor :cfndsl_opts
|
8
|
+
|
9
|
+
def initialize(name = nil)
|
10
|
+
yield self if block_given?
|
11
|
+
|
12
|
+
desc "Generate Cloudformation" unless ::Rake.application.last_comment
|
13
|
+
task(name || :generate) do |_t, _args|
|
14
|
+
cfndsl_opts[:files].each do |opts|
|
15
|
+
generate(opts)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def generate(opts)
|
23
|
+
log(opts)
|
24
|
+
outputter(opts).puts model(opts[:filename])
|
25
|
+
end
|
26
|
+
|
27
|
+
def log(opts)
|
28
|
+
type = opts[:output].nil? ? "STDOUT" : opts[:output]
|
29
|
+
verbose.puts("Writing to #{type}") if verbose
|
30
|
+
end
|
31
|
+
|
32
|
+
def outputter(opts)
|
33
|
+
opts[:output].nil? ? STDOUT : file_output(opts[:output])
|
34
|
+
end
|
35
|
+
|
36
|
+
def model(filename)
|
37
|
+
fail "#{filename} doesn't exist" unless File.exist? filename
|
38
|
+
verbose.puts("using extras #{extra}") if verbose
|
39
|
+
CfnDsl.eval_file_with_extras(filename, extra, verbose).to_json
|
40
|
+
end
|
41
|
+
|
42
|
+
def extra
|
43
|
+
cfndsl_opts.fetch(:extras, [])
|
44
|
+
end
|
45
|
+
|
46
|
+
def verbose
|
47
|
+
cfndsl_opts[:verbose] && STDERR
|
48
|
+
end
|
49
|
+
|
50
|
+
def file_output(path)
|
51
|
+
File.open(File.expand_path(path), "w")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/cfndsl/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Jack
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-08-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/cfndsl/module.rb
|
63
63
|
- lib/cfndsl/names.rb
|
64
64
|
- lib/cfndsl/os_types.yaml
|
65
|
+
- lib/cfndsl/rake_task.rb
|
65
66
|
- lib/cfndsl/version.rb
|
66
67
|
- sample/autoscale.rb
|
67
68
|
- sample/autoscale.template
|