bora 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea4493a9644738e50bf62a8083150dfc6f1aa76e
4
- data.tar.gz: c32798fe76ef04770c196b5700e406b1c6f6e1e0
3
+ metadata.gz: afc84ca6ace21cd7997bea10fd35850740536f13
4
+ data.tar.gz: 5e7df220869080122165cd28082d4c1e024320fe
5
5
  SHA512:
6
- metadata.gz: 51e688533cfc524b0178efb0943e13caae0632fe4f0e38afd5006d0c8cee17e922b1ff70d5cb195a83d1a3fd17b49027decf3d116acea27ebd3e163fe1246996
7
- data.tar.gz: 06f9d9b9ae1e690b02e24542107fad4c679865220cab46f394be233c56b2f02546031235957303d2bce7ba50540b8b87210a6f2937af99e6d8c0bafc823e8503
6
+ metadata.gz: bfbf29a13e209ddd100e88150d5e6cccf76b118fea3c4f7dcc739e83cd38c33070763d6cfe92fa0c1bda3f074a079d6570e2d5d83c5f856f438c71e893c2de73
7
+ data.tar.gz: 0f34aa4bf376a58b367d61c0187a206cbc197be67c2dcb4d200d374de6c5435fde0138eebf846bb8a97c9c8deb4ea23e3521987c9a679f819b990872df5652c9
data/README.md CHANGED
@@ -126,6 +126,45 @@ end
126
126
  puts "Update #{result ? "succeeded" : "failed"}"
127
127
  ```
128
128
 
129
+ ### YAML Configuration - Experimental
130
+ You can define and configure your stacks through YAML too.
131
+ This interface is currently experimental,
132
+ but longer term is likely to become the primary way to use this gem.
133
+ Sample usage is shown below (subject to change).
134
+
135
+ Rakefile:
136
+ ```ruby
137
+ require "bora"
138
+ Bora::RakeTasks.new('templates.yml')
139
+ ```
140
+
141
+ templates.yml:
142
+ ```yaml
143
+ templates:
144
+ app:
145
+ template_file: templates/test.json
146
+ stacks:
147
+ dev: {}
148
+ uat: {}
149
+
150
+ web:
151
+ # Templates ending in ".rb" are treated as cfndsl templates
152
+ template_file: templates/test.rb
153
+ capabilities: [CAPABILITY_IAM]
154
+ stacks:
155
+ dev:
156
+ # Set stack name explicitly (otherwise would default to "web-dev")
157
+ stack_name: foo-dev
158
+ params:
159
+ # Look up a value from the outputs of the "app-dev"stack
160
+ app_sg: ${app-dev/outputs/AppSecurityGroup}
161
+ uat:
162
+ params:
163
+ app_sg: foouatdev
164
+
165
+ ```
166
+
167
+
129
168
  ## Development
130
169
 
131
170
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -7,14 +7,22 @@ module Bora
7
7
  end
8
8
 
9
9
  def resolve
10
- stack, section, name = @param.split("/")
11
- if !stack || !section || !name || section != 'outputs'
10
+ stack_name, section, name = @param.split("/")
11
+ if !stack_name || !section || !name || section != 'outputs'
12
12
  raise "Invalid parameter substitution: #{@param}"
13
13
  end
14
14
 
15
- outputs = Stack.new(stack).outputs
15
+ stack = Stack.new(stack_name)
16
+ if !stack.exists?
17
+ raise "Output #{name} not found in stack #{stack_name} as the stack does not exist"
18
+ end
19
+
20
+ outputs = stack.outputs || []
16
21
  matching_output = outputs.find { |output| output.key == name }
17
- raise "Output #{name} not found in stack #{stack}" if !matching_output
22
+ if !matching_output
23
+ raise "Output #{name} not found in stack #{stack_name}"
24
+ end
25
+
18
26
  matching_output.value
19
27
  end
20
28
 
@@ -32,15 +32,26 @@ module Bora
32
32
 
33
33
  def define_tasks(template_file, stack_name, stack_config, stack_options)
34
34
  Bora::Tasks.new(stack_name) do |t|
35
- if File.extname(template_file) == ".rb"
36
- task :generate do |_, args|
37
- params = extract_params(stack_config, args)
38
- stack_options[:template_body] = run_cfndsl(template_file, params)
35
+ t.stack_options = stack_options
36
+
37
+ task :generate do |_, args|
38
+ params = extract_params(stack_config, args)
39
+ t.stack_options[:parameters] = params.map do |k,v|
40
+ { parameter_key: k, parameter_value: v }
41
+ end
42
+
43
+ if File.extname(template_file) == ".rb"
44
+ template_body = run_cfndsl(template_file, params)
45
+ template_json = JSON.parse(template_body)
46
+ if template_json["Parameters"]
47
+ cfn_params = template_json["Parameters"].keys
48
+ t.stack_options[:parameters].keep_if {|cfn_param| cfn_params.include?(cfn_param[:parameter_key]) }
49
+ end
50
+ t.stack_options[:template_body] = template_body
51
+ else
52
+ t.stack_options[:template_url] = template_file
39
53
  end
40
- else
41
- stack_options[:template_url] = template_file
42
54
  end
43
- t.stack_options = stack_options
44
55
  end
45
56
  end
46
57
 
@@ -61,10 +72,10 @@ module Bora
61
72
  def extract_params(stack_config, args)
62
73
  params = stack_config['params'] || {}
63
74
  params.merge!(extract_params_from_args(args.extras))
64
- params.map { |k, v| [k, process_param_value(v)] }.to_h
75
+ params.map { |k, v| [k, process_param_substitutions(v)] }.to_h
65
76
  end
66
77
 
67
- def process_param_value(val)
78
+ def process_param_substitutions(val)
68
79
  old_val = nil
69
80
  while old_val != val
70
81
  old_val = val
@@ -22,7 +22,7 @@ module Bora
22
22
  define_tasks
23
23
  end
24
24
 
25
- attr_writer :stack_options
25
+ attr_accessor :stack_options
26
26
 
27
27
  def colorize=(value)
28
28
  @colorize = value
@@ -1,3 +1,3 @@
1
1
  module Bora
2
- VERSION = "0.9.2"
2
+ VERSION = "0.9.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bora
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charles Blaxland