cloudformation-ruby-dsl 0.5.1 → 0.5.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 136b30b07166c41199b836ca01955ae5802bde26
4
- data.tar.gz: aa047bfbdec4b38c0f3412ca8d9a94978493ba6e
3
+ metadata.gz: e0b2bb25bca9454ecbfbfbed8c3c5ce751734f22
4
+ data.tar.gz: a650a529257a400c4ff9aa1d09e0c4ac49d3ab52
5
5
  SHA512:
6
- metadata.gz: 768328127126da0d6f7ef90400aa8a9916041c530fae8b64504888c7669ea0d6c98bb275aebd324f46e6298a3d276a8e8d5fe8f52a76bfa56fb3ece0fedeeb57
7
- data.tar.gz: 0515089919cd33907c83614330684b4ae6225095e64c44243546704fba4905aca5c7b3041eb2e86d376204bf9ae875d9f310e8654c5d59e0882befe743ee829e
6
+ metadata.gz: b3a22a8bac4c06712e353ef355c59e420347f60e95b33a985b273c7489e522b04eb012033ee2d7e25f3a2bd135599895923ef75b8f8f62cedb473d5da835d925
7
+ data.tar.gz: c7723d3e2c358621615d173f7b32877b510b78ba5939a8f29d04c85290939d500b3ac6a7276a435b4f94d063953e1a842aeb3136073bd7591f9bb075f72d4d50
@@ -167,8 +167,8 @@ template do
167
167
  {:DeviceName => '/dev/sdd', :VirtualName => 'ephemeral2'},
168
168
  {:DeviceName => '/dev/sde', :VirtualName => 'ephemeral3'},
169
169
  ],
170
- # Loads an external userdata script.
171
- :UserData => base64(interpolate(file('userdata.sh'))),
170
+ # Loads an external userdata script with an interpolated argument.
171
+ :UserData => base64(interpolate(file('userdata.sh'), time: Time.now)),
172
172
  }
173
173
 
174
174
  resource 'InstanceProfile', :Type => 'AWS::IAM::InstanceProfile', :Properties => {
data/examples/userdata.sh CHANGED
@@ -1,2 +1,4 @@
1
1
  #!/usr/bin/env bash
2
- echo "put initialization script here"
2
+ echo "put initialization script here"
3
+ echo "the time is {{ locals[:time] }}"
4
+ echo "the aws region is {{ ref('AWS::Region') }}"
@@ -325,7 +325,7 @@ class TemplateDSL < JsonObjectDSL
325
325
  begin
326
326
  # Figure out what the file extension is and process accordingly.
327
327
  contents = case File.extname(filename)
328
- when ".rb"; eval(file.read)
328
+ when ".rb"; eval(file.read, nil, filename)
329
329
  when ".json"; JSON.load(file)
330
330
  when ".yaml"; YAML::load(file)
331
331
  else; raise("Do not recognize extension of #{filename}.")
@@ -414,12 +414,13 @@ def file(filename) File.read(File.absolute_path(filename, File.dirname($PROGRAM_
414
414
  # Interpolates a string like "NAME={{ref('Service')}}" and returns a CloudFormation "Fn::Join"
415
415
  # operation to collect the results. Anything between {{ and }} is interpreted as a Ruby expression
416
416
  # and eval'd. This is especially useful with Ruby "here" documents.
417
- def interpolate(string)
417
+ # Local variables may also be exposed to the string via the `locals` hash.
418
+ def interpolate(string, locals={})
418
419
  list = []
419
420
  while string.length > 0
420
421
  head, match, string = string.partition(/\{\{.*?\}\}/)
421
422
  list << head if head.length > 0
422
- list << eval(match[2..-3]) if match.length > 0
423
+ list << eval(match[2..-3], nil, 'interpolated string') if match.length > 0
423
424
  end
424
425
 
425
426
  # Split out strings in an array by newline, for visibility
@@ -15,7 +15,7 @@
15
15
  module Cfn
16
16
  module Ruby
17
17
  module Dsl
18
- VERSION = "0.5.1"
18
+ VERSION = "0.5.2"
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.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shawn Smith