cloudformation-ruby-dsl 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,18 +1,18 @@
1
1
  # cloudformation-ruby-dsl
2
2
 
3
- A Ruby DSL and helper utilities for building Cloudformation templates dynamically.
3
+ A Ruby DSL and helper utilities for building CloudFormation templates dynamically.
4
4
 
5
5
  Written by [Bazaarvoice](http://www.bazaarvoice.com): see [the contributors page](https://github.com/bazaarvoice/cloudformation-ruby-dsl/graphs/contributors) and [the initial contributions](https://github.com/bazaarvoice/cloudformation-ruby-dsl/blob/master/initial_contributions.md) for more details.
6
6
 
7
7
  ## Motivation
8
8
 
9
- Cloudformation templates often contain repeated stanzas, information which must be loaded from external sources, and other functionality that would be easier handled as code, instead of configuration.
9
+ CloudFormation templates often contain repeated stanzas, information which must be loaded from external sources, and other functionality that would be easier handled as code, instead of configuration.
10
10
 
11
- Consider when a userdata script needs to be added to a Cloudformation template. Traditionally, you would re-write the script by hand in a valid JSON format. Using the DSL, you can specify the file containing the script and generate the correct information at runtime.
11
+ Consider when a userdata script needs to be added to a CloudFormation template. Traditionally, you would re-write the script by hand in a valid JSON format. Using the DSL, you can specify the file containing the script and generate the correct information at runtime.
12
12
 
13
13
  :UserData => base64(interpolate(file('userdata.sh')))
14
14
 
15
- Additionally, Cloudformation templates are just massive JSON documents, making general readability and reusability an issue. The DSL allows not only a cleaner format (and comments!), but will also allow the same DSL template to be reused as needed.
15
+ Additionally, CloudFormation templates are just massive JSON documents, making general readability and reusability an issue. The DSL allows not only a cleaner format (and comments!), but will also allow the same DSL template to be reused as needed.
16
16
 
17
17
  ## Installation
18
18
 
@@ -46,9 +46,9 @@ Add the named object to the appropriate collection.
46
46
  - `resource(name, options)`
47
47
  - `output(name, options)`
48
48
 
49
- ### Cloudformation Function Calls
49
+ ### CloudFormation Function Calls
50
50
 
51
- Invoke a native Cloudformation function.
51
+ Invoke an intrinsic CloudFormation function.
52
52
  - `base64(value)`
53
53
  - `find_in_map(map, key, name)`
54
54
  - `get_att(resource, attribute)`
@@ -56,7 +56,14 @@ Invoke a native Cloudformation function.
56
56
  - `join(delim, *list)`
57
57
  - `select(index, list)`
58
58
  - `ref(name)`
59
- - `no_value()`
59
+
60
+ Reference a CloudFormation pseudo parameter.
61
+ - `aws_account_id()`
62
+ - `aws_notification_arns()`
63
+ - `aws_no_value()`
64
+ - `aws_region()`
65
+ - `aws_stack_id()`
66
+ - `aws_stack_name()`
60
67
 
61
68
  ### Utility Functions
62
69
 
@@ -286,6 +286,14 @@ def fmt_string(s)
286
286
  end
287
287
  end
288
288
 
289
+ def many(val)
290
+ if val.is_a?(Array)
291
+ val
292
+ else
293
+ [ val ]
294
+ end
295
+ end
296
+
289
297
  def simplify(val)
290
298
  if val.is_a?(Hash)
291
299
  val = Hash[val.map { |k,v| [k, simplify(v)] }]
@@ -304,11 +312,19 @@ def simplify(val)
304
312
  when k == 'Fn::GetAZs'
305
313
  FnCall.new 'get_azs', v != '' ? [v] : []
306
314
  when k == 'Fn::Join'
307
- FnCall.new 'join', [v[0]] + v[1], true
315
+ FnCall.new 'join', [v[0]] + many(v[1]), true
308
316
  when k == 'Fn::Select'
309
317
  FnCall.new 'select', v
318
+ when k == 'Ref' && v == 'AWS::AccountId'
319
+ FnCall.new 'aws_account_id', []
320
+ when k == 'Ref' && v == 'AWS::NotificationARNs'
321
+ FnCall.new 'aws_notification_arns', []
322
+ when k == 'Ref' && v == 'AWS::NoValue'
323
+ FnCall.new 'aws_no_value', []
310
324
  when k == 'Ref' && v == 'AWS::Region'
311
325
  FnCall.new 'aws_region', []
326
+ when k == 'Ref' && v == 'AWS::StackId'
327
+ FnCall.new 'aws_stack_id', []
312
328
  when k == 'Ref' && v == 'AWS::StackName'
313
329
  FnCall.new 'aws_stack_name', []
314
330
  when k == 'Ref'
@@ -19,7 +19,7 @@ require 'cloudformation-ruby-dsl/cfntemplate'
19
19
  require 'cloudformation-ruby-dsl/table'
20
20
 
21
21
  # Note: this is only intended to demonstrate the cloudformation-ruby-dsl. It compiles
22
- # and validates correctly, but won't produce a viable Cloudformation stack.
22
+ # and validates correctly, but won't produce a viable CloudFormation stack.
23
23
 
24
24
  template do
25
25
 
@@ -95,7 +95,7 @@ template do
95
95
  vpc.get_multimap({ :visibility => 'private', :zone => ['a', 'c'] }, :env, :region, :subnet)
96
96
 
97
97
  # The tag type is a Ruby CFN extension. These tags are excised from the template and used to generate a series of --tag arguments
98
- # which are passed to cfn-cmd. They do not ultimately appear in the expanded Cloudformation template. The diff subcommand will
98
+ # which are passed to cfn-cmd. They do not ultimately appear in the expanded CloudFormation template. The diff subcommand will
99
99
  # compare tags with the running stack and identify any changes, but cfn-update-stack will do the diff and throw an error on any
100
100
  # changes. The tags are propagated to all resources created by the stack, including the stack itself.
101
101
  #
@@ -376,7 +376,21 @@ def select(index, list) { :'Fn::Select' => [ index, list ] } end
376
376
 
377
377
  def ref(name) { :Ref => name } end
378
378
 
379
- def no_value() ref("AWS::NoValue") end
379
+ def aws_account_id() ref("AWS::AccountId") end
380
+
381
+ def aws_notification_arns() ref("AWS::NotificationARNs") end
382
+
383
+ def aws_no_value() ref("AWS::NoValue") end
384
+
385
+ def aws_stack_id() ref("AWS::StackId") end
386
+
387
+ def aws_stack_name() ref("AWS::StackName") end
388
+
389
+ # deprecated, for backward compatibility
390
+ def no_value()
391
+ warn_deprecated('no_value()', 'aws_no_value()')
392
+ aws_no_value()
393
+ end
380
394
 
381
395
  # Read the specified file and return its value as a string literal
382
396
  def file(filename) File.read(File.absolute_path(filename, File.dirname($PROGRAM_NAME))) end
@@ -417,3 +431,7 @@ end
417
431
  def erb_template(filename, params = {})
418
432
  ERB.new(file(filename), nil, '-').result(Namespace.new(params).get_binding)
419
433
  end
434
+
435
+ def warn_deprecated(old, new)
436
+ $stderr.puts "Warning: '#{old}' has been deprecated. Please update your template to use '#{new}' instead."
437
+ end
@@ -37,7 +37,7 @@ SPOT_PRICES_BY_INSTANCE_TYPE = {
37
37
 
38
38
  def spot_price(spot_price_string, instance_type)
39
39
  case spot_price_string
40
- when 'false', '' then no_value()
40
+ when 'false', '' then aws_no_value()
41
41
  when 'true' then spot_price_for_instance_type(instance_type)
42
42
  else spot_price_string
43
43
  end
@@ -15,7 +15,7 @@
15
15
  module Cfn
16
16
  module Ruby
17
17
  module Dsl
18
- VERSION = "0.4.5"
18
+ VERSION = "0.4.6"
19
19
  end
20
20
  end
21
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudformation-ruby-dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -16,7 +16,7 @@ authors:
16
16
  autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
- date: 2014-07-17 00:00:00.000000000 Z
19
+ date: 2014-08-12 00:00:00.000000000 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: detabulator