stack_master 2.10.0 → 2.13.1

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
  SHA256:
3
- metadata.gz: 404a38ded90b0e30b4e7dbca97185e298959c0541d7ed507880cd6654f45868f
4
- data.tar.gz: a0459cf8623da399abc16482d3ec3674b418a369406e465d9a6245ea7d3de48e
3
+ metadata.gz: 9c003a9755154a92dc52a3ed8c4e834caf66eb92c520ca8b695be7661ab47404
4
+ data.tar.gz: 5a3b2c9e0afef8120f6fcc0df4041ef003b1e42e86c0584a33148a4ec1ef74be
5
5
  SHA512:
6
- metadata.gz: b9a25c80259fe178287eaa6c13ee43cbb04e9a5288c1a6d4b429499df35a27bf7437873492e338221e0a2744252244889ce7b7d9e82521eb95883c5520bce4ed
7
- data.tar.gz: 8187cf1cc0ff902a8fa90274a15ed8d0e9ea989e0020b942bce488a4b7881da7a544554c2949305681748349c991401e65308f65e039c04e2290018892fc15ed
6
+ metadata.gz: 58df6d821a3048a1edda08a3bf63407093b4a942d185491e4d686f74fea0718c2973790aaf8d8e4c5f609b58bedd25a8dcf601d58d92a3be5b3d90e859477c9e
7
+ data.tar.gz: b54493fb2e7b2ec35bb2abfa88da2dde6cfc16e3187037a890031760b5bab136848680a6a1d22a9ee101a2a0ae47cac6d8a3677519da3b6bc996208aa4006478
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![License MIT](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/envato/stack_master/blob/master/LICENSE.md)
4
4
  [![Gem Version](https://badge.fury.io/rb/stack_master.svg)](https://badge.fury.io/rb/stack_master)
5
- [![Build Status](https://travis-ci.org/envato/stack_master.svg?branch=master)](https://travis-ci.org/envato/stack_master)
5
+ [![Build Status](https://github.com/envato/stack_master/workflows/tests/badge.svg?branch=master)](https://github.com/envato/stack_master/actions?query=workflow%3Atests+branch%3Amaster)
6
6
 
7
7
  StackMaster is a CLI tool to manage [CloudFormation](https://aws.amazon.com/cloudformation/) stacks, with the following features:
8
8
 
@@ -143,7 +143,8 @@ stacks:
143
143
  ## Templates
144
144
 
145
145
  StackMaster supports CloudFormation templates in plain JSON or YAML. Any `.yml` or `.yaml` file will be processed as
146
- YAML, while any `.json` file will be processed as JSON.
146
+ YAML, while any `.json` file will be processed as JSON. Additionally, YAML files can be pre-processed using ERB and
147
+ compile-time parameters.
147
148
 
148
149
  ### Ruby DSLs
149
150
  By default, any template ending with `.rb` will be processed as a [SparkleFormation](https://github.com/sparkleformation/sparkle_formation)
@@ -199,12 +200,13 @@ stacks:
199
200
 
200
201
  ### Compile Time Parameters
201
202
 
202
- Compile time parameters can be used for [SparkleFormation](http://www.sparkleformation.io) templates. It conforms and
203
- allows you to use the [Compile Time Parameters](http://www.sparkleformation.io/docs/sparkle_formation/compile-time-parameters.html) feature.
203
+ Compile time parameters can be defined in a stack's parameters file, using the key `compile_time_parameters`. Keys in
204
+ parameter files are automatically converted to camel case.
204
205
 
205
- A simple example looks like this
206
+ As an example:
206
207
 
207
208
  ```yaml
209
+ # parameters/some_stack.yml
208
210
  vpc_cidr: 10.0.0.0/16
209
211
  compile_time_parameters:
210
212
  subnet_cidrs:
@@ -212,7 +214,37 @@ compile_time_parameters:
212
214
  - 10.0.2.0/28
213
215
  ```
214
216
 
215
- Keys in parameter files are automatically converted to camel case.
217
+ #### SparkleFormation
218
+
219
+ Compile time parameters can be used for [SparkleFormation](http://www.sparkleformation.io) templates. It conforms and
220
+ allows you to use the [Compile Time Parameters](http://www.sparkleformation.io/docs/sparkle_formation/compile-time-parameters.html) feature.
221
+
222
+ #### CloudFormation YAML ERB
223
+
224
+ Compile time parameters can be used to pre-process YAML CloudFormation templates. An example template:
225
+
226
+ ```yaml
227
+ # templates/some_stack_template.yml.erb
228
+ Parameters:
229
+ VpcCidr:
230
+ Type: String
231
+ Resources:
232
+ Vpc:
233
+ Type: AWS::EC2::VPC
234
+ Properties:
235
+ CidrBlock: !Ref VpcCidr
236
+ # Given the two subnet_cidrs parameters, this creates two resources:
237
+ # SubnetPrivate0 with a CidrBlock of 10.0.0.0/28, and
238
+ # SubnetPrivate1 with a CidrBlock of 10.0.2.0/28
239
+ <% params["SubnetCidrs"].each_with_index do |cidr, index| %>
240
+ SubnetPrivate<%= index %>:
241
+ Type: AWS::EC2::Subnet
242
+ Properties:
243
+ VpcId: !Ref Vpc
244
+ AvailabilityZone: ap-southeast-2
245
+ CidrBlock: <%= cidr %>
246
+ <% end %>
247
+ ```
216
248
 
217
249
  ## Parameter Resolvers
218
250
 
@@ -709,6 +741,10 @@ stack_master outputs [region-or-alias] [stack-name] # Display outputs for a stac
709
741
  stack_master resources [region-or-alias] [stack-name] # Display outputs for a stack
710
742
  stack_master status # Displays the status of each stack
711
743
  stack_master tidy # Find missing or extra templates or parameter files
744
+ stack_master compile # Print the compiled version of a given stack
745
+ stack_master validate # Validate a template
746
+ stack_master lint # Check the stack definition locally using cfn-lint
747
+ stack_master nag # Check the stack template with cfn_nag
712
748
  ```
713
749
 
714
750
  ## Applying updates - `stack_master apply`
@@ -7,7 +7,7 @@ module StackMaster
7
7
 
8
8
  def initialize(argv, stdin=STDIN, stdout=STDOUT, stderr=STDERR, kernel=Kernel)
9
9
  @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel
10
- Commander::Runner.instance_variable_set('@singleton', Commander::Runner.new(argv))
10
+ Commander::Runner.instance_variable_set('@instance', Commander::Runner.new(argv))
11
11
  StackMaster.stdout = @stdout
12
12
  StackMaster.stderr = @stderr
13
13
  TablePrint::Config.io = StackMaster.stdout
@@ -5,7 +5,7 @@ module StackMaster
5
5
  include Commander::UI
6
6
 
7
7
  def perform
8
- puts(proposed_stack.template_body)
8
+ StackMaster.stdout.puts(proposed_stack.template_body)
9
9
  end
10
10
 
11
11
  private
@@ -92,6 +92,7 @@ module StackMaster
92
92
  json: :json,
93
93
  yml: :yaml,
94
94
  yaml: :yaml,
95
+ erb: :yaml_erb,
95
96
  }
96
97
  end
97
98
 
@@ -1,12 +1,17 @@
1
1
  module StackMaster
2
2
  class Identity
3
+ AllowedAccountAliasesError = Class.new(StandardError)
3
4
  MissingIamPermissionsError = Class.new(StandardError)
4
5
 
5
6
  def running_in_account?(accounts)
6
- accounts.nil? ||
7
- accounts.empty? ||
8
- contains_account_id?(accounts) ||
9
- contains_account_alias?(accounts)
7
+ return true if accounts.nil? || accounts.empty? || contains_account_id?(accounts)
8
+
9
+ # skip alias check (which makes an API call) if all values are account IDs
10
+ return false if accounts.all? { |account| account_id?(account) }
11
+
12
+ contains_account_alias?(accounts)
13
+ rescue MissingIamPermissionsError
14
+ raise AllowedAccountAliasesError, 'Failed to validate whether the current AWS account is allowed'
10
15
  end
11
16
 
12
17
  def account
@@ -40,5 +45,11 @@ module StackMaster
40
45
  def contains_account_alias?(aliases)
41
46
  account_aliases.any? { |account_alias| aliases.include?(account_alias) }
42
47
  end
48
+
49
+ def account_id?(id_or_alias)
50
+ # While it's not explicitly documented as prohibited, it cannot (currently) be possible to set an account alias of
51
+ # 12 digits, as that could cause one console sign-in URL to resolve to two separate accounts.
52
+ /^[0-9]{12}$/.match?(id_or_alias)
53
+ end
43
54
  end
44
55
  end
@@ -19,7 +19,7 @@ module StackMaster
19
19
 
20
20
  def has_invalid_values?
21
21
  values = build_values(@definition, @parameter)
22
- values.include?(nil) || values.include?('')
22
+ values.include?(nil)
23
23
  end
24
24
 
25
25
  def create_error
@@ -2,14 +2,15 @@ module StackMaster::TemplateCompilers
2
2
  class Cfndsl
3
3
  def self.require_dependencies
4
4
  require 'cfndsl'
5
+ require 'json'
5
6
  end
6
7
 
7
8
  def self.compile(template_dir, template, compile_time_parameters, _compiler_options = {})
8
- CfnDsl.disable_binding
9
9
  CfnDsl::ExternalParameters.defaults.clear # Ensure there's no leakage across invocations
10
10
  CfnDsl::ExternalParameters.defaults(compile_time_parameters.symbolize_keys)
11
11
  template_file_path = File.join(template_dir, template)
12
- ::CfnDsl.eval_file_with_extras(template_file_path).to_json
12
+ json_hash = ::CfnDsl.eval_file_with_extras(template_file_path).as_json
13
+ JSON.pretty_generate(json_hash)
13
14
  end
14
15
 
15
16
  StackMaster::TemplateCompiler.register(:cfndsl, self)
@@ -22,7 +22,7 @@ module StackMaster::TemplateCompilers
22
22
  sparkle_template.compile_state = create_state(definitions, compile_time_parameters)
23
23
  end
24
24
 
25
- JSON.pretty_generate(sparkle_template)
25
+ JSON.pretty_generate(sparkle_template.dump)
26
26
  end
27
27
 
28
28
  private
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StackMaster::TemplateCompilers
4
+ class YamlErb
5
+ def self.require_dependencies
6
+ require 'erubis'
7
+ require 'yaml'
8
+ end
9
+
10
+ def self.compile(template_dir, template, compile_time_parameters, _compiler_options = {})
11
+ template_file_path = File.join(template_dir, template)
12
+ template = Erubis::Eruby.new(File.read(template_file_path))
13
+ template.filename = template_file_path
14
+
15
+ template.result(params: compile_time_parameters)
16
+ end
17
+
18
+ StackMaster::TemplateCompiler.register(:yaml_erb, self)
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module StackMaster
2
- VERSION = "2.10.0"
2
+ VERSION = "2.13.1"
3
3
  end
data/lib/stack_master.rb CHANGED
@@ -52,6 +52,7 @@ module StackMaster
52
52
  require 'stack_master/template_compilers/sparkle_formation'
53
53
  require 'stack_master/template_compilers/json'
54
54
  require 'stack_master/template_compilers/yaml'
55
+ require 'stack_master/template_compilers/yaml_erb'
55
56
  require 'stack_master/template_compilers/cfndsl'
56
57
 
57
58
  module Commands
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stack_master
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.0
4
+ version: 2.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Hodgkiss
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-07-28 00:00:00.000000000 Z
12
+ date: 2021-10-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -143,7 +143,7 @@ dependencies:
143
143
  requirements:
144
144
  - - ">="
145
145
  - !ruby/object:Gem::Version
146
- version: 4.5.2
146
+ version: 4.6.0
147
147
  - - "<"
148
148
  - !ruby/object:Gem::Version
149
149
  version: '5'
@@ -153,7 +153,7 @@ dependencies:
153
153
  requirements:
154
154
  - - ">="
155
155
  - !ruby/object:Gem::Version
156
- version: 4.5.2
156
+ version: 4.6.0
157
157
  - - "<"
158
158
  - !ruby/object:Gem::Version
159
159
  version: '5'
@@ -371,16 +371,16 @@ dependencies:
371
371
  name: cfndsl
372
372
  requirement: !ruby/object:Gem::Requirement
373
373
  requirements:
374
- - - "<"
374
+ - - "~>"
375
375
  - !ruby/object:Gem::Version
376
- version: '1.0'
376
+ version: '1'
377
377
  type: :runtime
378
378
  prerelease: false
379
379
  version_requirements: !ruby/object:Gem::Requirement
380
380
  requirements:
381
- - - "<"
381
+ - - "~>"
382
382
  - !ruby/object:Gem::Version
383
- version: '1.0'
383
+ version: '1'
384
384
  - !ruby/object:Gem::Dependency
385
385
  name: multi_json
386
386
  requirement: !ruby/object:Gem::Requirement
@@ -441,16 +441,22 @@ dependencies:
441
441
  name: cfn-nag
442
442
  requirement: !ruby/object:Gem::Requirement
443
443
  requirements:
444
- - - "~>"
444
+ - - ">="
445
445
  - !ruby/object:Gem::Version
446
446
  version: 0.6.7
447
+ - - "<"
448
+ - !ruby/object:Gem::Version
449
+ version: 0.8.0
447
450
  type: :runtime
448
451
  prerelease: false
449
452
  version_requirements: !ruby/object:Gem::Requirement
450
453
  requirements:
451
- - - "~>"
454
+ - - ">="
452
455
  - !ruby/object:Gem::Version
453
456
  version: 0.6.7
457
+ - - "<"
458
+ - !ruby/object:Gem::Version
459
+ version: 0.8.0
454
460
  description: ''
455
461
  email:
456
462
  - steve@hodgkiss.me
@@ -539,6 +545,7 @@ files:
539
545
  - lib/stack_master/template_compilers/json.rb
540
546
  - lib/stack_master/template_compilers/sparkle_formation.rb
541
547
  - lib/stack_master/template_compilers/yaml.rb
548
+ - lib/stack_master/template_compilers/yaml_erb.rb
542
549
  - lib/stack_master/template_utils.rb
543
550
  - lib/stack_master/test_driver/cloud_formation.rb
544
551
  - lib/stack_master/test_driver/s3.rb
@@ -556,8 +563,8 @@ licenses:
556
563
  metadata:
557
564
  bug_tracker_uri: https://github.com/envato/stack_master/issues
558
565
  changelog_uri: https://github.com/envato/stack_master/blob/master/CHANGELOG.md
559
- documentation_uri: https://www.rubydoc.info/gems/stack_master/2.10.0
560
- source_code_uri: https://github.com/envato/stack_master/tree/v2.10.0
566
+ documentation_uri: https://www.rubydoc.info/gems/stack_master/2.13.1
567
+ source_code_uri: https://github.com/envato/stack_master/tree/v2.13.1
561
568
  post_install_message:
562
569
  rdoc_options: []
563
570
  require_paths:
@@ -573,7 +580,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
573
580
  - !ruby/object:Gem::Version
574
581
  version: '0'
575
582
  requirements: []
576
- rubygems_version: 3.0.3
583
+ rubygems_version: 3.0.4
577
584
  signing_key:
578
585
  specification_version: 4
579
586
  summary: StackMaster is a sure-footed way of creating, updating and keeping track