cfndsl 0.1.20 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzhkNGFiZmE2M2Y4NjNhMTY4YzcwZDkzZGJjOTU5OGMwMDM1OGQ5NQ==
4
+ ZThkNTZjYmU1ZTA5YTFkYjAwODJmMTMxNzFhZGY0YzQxMDJlZDgzMw==
5
5
  data.tar.gz: !binary |-
6
- NzdjOWFiNmQ5NWM4OTAxNGMwODNkM2I1OGY3NTJkYWRhODJiZjg5YQ==
6
+ NjhjZGRkYWNkMTI5ZDlkMjY2MmYyMmI4MTRhZDk2ZWNjMGI0YjU4NA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDA5MzgzMzIzYTU3Y2VjNmVhNDcyNTY4MGQ1MDU5ZGZjZDI1M2ZiMjViMWVl
10
- ZjRjNDQ2OGYwN2Y1OTJmMzg0Nzk5NzhkNmEyZTRjZDU1YzAzZjU3MmJjNGVi
11
- OGNkMmMxOGFjZmE5NDVhYTg0NjFlNGViNTc3NmY4ZGYwMmViNTc=
9
+ Njc2OTRlNzUzN2JkYmZiNzYyYjRkMzgxOTI4NjA4ZmQ5MGRmZDA4YjBkYWYw
10
+ OWQ3YmYwMzYyOTI0NjhiNzdhMGFiZDkyMzkzZDZkODVmNzBiMmQzNTY5YTQ0
11
+ OWQzYTZmM2JmY2YwOWQ3YmQxYjRjODY4NDk0MjYwMzY4OTNjOTA=
12
12
  data.tar.gz: !binary |-
13
- OTZmZWFjZThlYjAxYjRmYmM1YjgwNWYwZDA2ZTJlZjFiNGYxZTY1ZjkxZTFl
14
- MjIzNjliMTQyODAxMWUxMWQyMWNjNTIyZTY5ZmY1ZjI5YWU2ODVlMjAwNjhh
15
- YmJmYjY4NDQ3YTU4MWZjNTRmNzczMGI4N2UyNzZjYzMxN2VjYTQ=
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
+ ```
@@ -384,6 +384,7 @@ Resources:
384
384
  SecretAccessKey: String
385
385
  "AWS::IAM::Group" :
386
386
  Properties:
387
+ ManagedPolicyArns: [ String ]
387
388
  Path: String
388
389
  Policies: [ IAMEmbeddedPolicy ]
389
390
  Attributes:
@@ -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
@@ -1,3 +1,3 @@
1
1
  module CfnDsl
2
- VERSION = "0.1.20"
2
+ VERSION = "0.2.0"
3
3
  end
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.20
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-07-22 00:00:00.000000000 Z
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