stack_master 1.15.0 → 1.16.0

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: 1acbc281b89ec3188892fac6692c4e885780efd8ba83f746a774557c0e1194ca
4
- data.tar.gz: e18cb99eb7f3e99ac0b8fee4b952cb1d21b9f1467a4bbe8dac9250695649f543
3
+ metadata.gz: f64b125495590bdb3890f184b5ecb67e2b57d13d7e8cc023fb785a543e825e2c
4
+ data.tar.gz: 0f892956233a734941107967938357400c131d3280e687a5839531aa5dbaa275
5
5
  SHA512:
6
- metadata.gz: bcc6882c647189f6f758896da7cd8084638b707af26faeb234435b99a1e5cd466c0ca90e2f30a67b4414f21f38d899414d7935e49d2a7355ccd84ad700c87ba9
7
- data.tar.gz: b48a690acadd00aa426084cc3b3b7aeb100b6fbfeaad738cb645df77ca6bd3edce347acf71d2b28ec3ff80833f15e4c55f95f5719922f0d061b2102c0ae1760c
6
+ metadata.gz: d8fdc2f1e629e1620ef5144e5990706ff0e89f390df4cf3880671676bd6ef26091011d87adcdd55e21987311ff6c0cb8724dff58353e352e3e6531c8d915cf73
7
+ data.tar.gz: 026efc1dec847d78400ea70bf087d52a2601738145790b05d70cc77b6dbd5fde337872c6226fcacf52b5bd4c91f633755ff67147ff48d820ac1ed5626f8ea99f
data/README.md CHANGED
@@ -570,7 +570,7 @@ stacks:
570
570
 
571
571
  ```yaml
572
572
  stacks:
573
- us-east-1
573
+ us-east-1:
574
574
  my-stack:
575
575
  template: my-stack-with-dynamic.rb
576
576
  compiler_options:
@@ -588,6 +588,26 @@ end
588
588
 
589
589
  Note though that if a dynamic with the same name exists in your `templates/dynamics/` directory it will get loaded since it has higher precedence.
590
590
 
591
+ Templates can be also loaded from sparkle packs by defining `sparkle_pack_template`. The name corresponds to the registered symbol rather than specific name. That means for a sparkle pack containing:
592
+
593
+ ```ruby
594
+ SparkleFormation.new(:template_name) do
595
+ ...
596
+ end
597
+ ```
598
+
599
+ we can use stack defined as follows:
600
+
601
+ ```yaml
602
+ stacks:
603
+ us-east-1:
604
+ my-stack:
605
+ sparkle_pack_template: template_name
606
+ compiler_options:
607
+ sparkle_packs:
608
+ - some-sparkle-pack
609
+ ```
610
+
591
611
  ## Allowed accounts
592
612
 
593
613
  The AWS account the command is executing in can be restricted to a specific list of allowed accounts. This is useful in reducing the possibility of applying non-production changes in a production account. Each stack definition can specify the `allowed_accounts` property with an array of AWS account IDs the stack is allowed to work with.
@@ -65,7 +65,7 @@ module StackMaster
65
65
  parameter_hash = ParameterLoader.load(stack_definition.parameter_files)
66
66
  template_parameters = ParameterResolver.resolve(config, stack_definition, parameter_hash[:template_parameters])
67
67
  compile_time_parameters = ParameterResolver.resolve(config, stack_definition, parameter_hash[:compile_time_parameters])
68
- template_body = TemplateCompiler.compile(config, stack_definition.template_file_path, compile_time_parameters, stack_definition.compiler_options)
68
+ template_body = TemplateCompiler.compile(config, stack_definition.template_dir, stack_definition.template_file_path, stack_definition.sparkle_pack_template, compile_time_parameters, stack_definition.compiler_options)
69
69
  template_format = TemplateUtils.identify_template_format(template_body)
70
70
  stack_policy_body = if stack_definition.stack_policy_file_path
71
71
  File.read(stack_definition.stack_policy_file_path)
@@ -3,6 +3,7 @@ module StackMaster
3
3
  attr_accessor :region,
4
4
  :stack_name,
5
5
  :template,
6
+ :sparkle_pack_template,
6
7
  :tags,
7
8
  :role_arn,
8
9
  :allowed_accounts,
@@ -39,6 +40,7 @@ module StackMaster
39
40
  @region == other.region &&
40
41
  @stack_name == other.stack_name &&
41
42
  @template == other.template &&
43
+ @sparkle_pack_template == other.sparkle_pack_template &&
42
44
  @tags == other.tags &&
43
45
  @role_arn == other.role_arn &&
44
46
  @allowed_accounts == other.allowed_accounts &&
@@ -55,6 +57,7 @@ module StackMaster
55
57
  end
56
58
 
57
59
  def template_file_path
60
+ return unless template
58
61
  File.expand_path(File.join(template_dir, template))
59
62
  end
60
63
 
@@ -2,12 +2,12 @@ module StackMaster
2
2
  class TemplateCompiler
3
3
  TemplateCompilationFailed = Class.new(RuntimeError)
4
4
 
5
- def self.compile(config, template_file_path, compile_time_parameters, compiler_options = {})
6
- compiler = template_compiler_for_file(template_file_path, config)
5
+ def self.compile(config, template_dir, template_file_path, sparkle_pack_template, compile_time_parameters, compiler_options = {})
6
+ compiler = template_compiler_for_stack(template_file_path, sparkle_pack_template, config)
7
7
  compiler.require_dependencies
8
- compiler.compile(template_file_path, compile_time_parameters, compiler_options)
8
+ compiler.compile(template_dir, template_file_path, sparkle_pack_template, compile_time_parameters, compiler_options)
9
9
  rescue StandardError => e
10
- raise TemplateCompilationFailed.new("Failed to compile #{template_file_path} with error #{e}.\n#{e.backtrace}")
10
+ raise TemplateCompilationFailed.new("Failed to compile #{template_file_path || sparkle_pack_template} with error #{e}.\n#{e.backtrace}")
11
11
  end
12
12
 
13
13
  def self.register(name, klass)
@@ -16,11 +16,16 @@ module StackMaster
16
16
  end
17
17
 
18
18
  # private
19
- def self.template_compiler_for_file(template_file_path, config)
20
- compiler_name = config.template_compilers.fetch(file_ext(template_file_path))
19
+ def self.template_compiler_for_stack(template_file_path, sparkle_pack_template, config)
20
+ ext = if sparkle_pack_template
21
+ :rb
22
+ else
23
+ file_ext(template_file_path)
24
+ end
25
+ compiler_name = config.template_compilers.fetch(ext)
21
26
  @compilers.fetch(compiler_name)
22
27
  end
23
- private_class_method :template_compiler_for_file
28
+ private_class_method :template_compiler_for_stack
24
29
 
25
30
  def self.file_ext(template_file_path)
26
31
  File.extname(template_file_path).gsub('.', '').to_sym
@@ -4,7 +4,7 @@ module StackMaster::TemplateCompilers
4
4
  require 'cfndsl'
5
5
  end
6
6
 
7
- def self.compile(template_file_path, compile_time_parameters, _compiler_options = {})
7
+ def self.compile(_template_dir, template_file_path, _sparkle_pack_template, compile_time_parameters, _compiler_options = {})
8
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)
@@ -7,7 +7,7 @@ module StackMaster::TemplateCompilers
7
7
  require 'json'
8
8
  end
9
9
 
10
- def self.compile(template_file_path, _compile_time_parameters, _compiler_options = {})
10
+ def self.compile(_template_dir, template_file_path, _sparkle_pack_template, _compile_time_parameters, _compiler_options = {})
11
11
  template_body = File.read(template_file_path)
12
12
  if template_body.size > MAX_TEMPLATE_SIZE
13
13
  # Parse the json and rewrite compressed
@@ -12,8 +12,8 @@ module StackMaster::TemplateCompilers
12
12
  require 'stack_master/sparkle_formation/template_file'
13
13
  end
14
14
 
15
- def self.compile(template_file_path, compile_time_parameters, compiler_options = {})
16
- sparkle_template = compile_sparkle_template(template_file_path, compiler_options)
15
+ def self.compile(template_dir, template_file_path, sparkle_pack_template, compile_time_parameters, compiler_options = {})
16
+ sparkle_template = compile_sparkle_template(template_dir, template_file_path, sparkle_pack_template, compiler_options)
17
17
  definitions = sparkle_template.parameters
18
18
  validate_definitions(definitions)
19
19
  validate_parameters(definitions, compile_time_parameters)
@@ -27,9 +27,12 @@ module StackMaster::TemplateCompilers
27
27
 
28
28
  private
29
29
 
30
- def self.compile_sparkle_template(template_file_path, compiler_options)
31
- sparkle_path = compiler_options['sparkle_path'] ?
32
- File.expand_path(compiler_options['sparkle_path']) : File.dirname(template_file_path)
30
+ def self.compile_sparkle_template(template_dir, template_file_path, sparkle_pack_template, compiler_options)
31
+ sparkle_path = if compiler_options['sparkle_path']
32
+ File.expand_path(compiler_options['sparkle_path'])
33
+ else
34
+ template_dir
35
+ end
33
36
 
34
37
  collection = ::SparkleFormation::SparkleCollection.new
35
38
  root_pack = ::SparkleFormation::Sparkle.new(
@@ -44,6 +47,11 @@ module StackMaster::TemplateCompilers
44
47
  end
45
48
  end
46
49
 
50
+ if sparkle_pack_template
51
+ raise ArgumentError.new("Template #{sparkle_pack_template} not found in any sparkle pack") unless collection.templates['aws'].include? sparkle_pack_template
52
+ template_file_path = collection.templates['aws'][sparkle_pack_template].top['path']
53
+ end
54
+
47
55
  sparkle_template = compile_template_with_sparkle_path(template_file_path, sparkle_path)
48
56
  sparkle_template.sparkle.apply(collection)
49
57
  sparkle_template
@@ -5,7 +5,7 @@ module StackMaster::TemplateCompilers
5
5
  require 'json'
6
6
  end
7
7
 
8
- def self.compile(template_file_path, _compile_time_parameters, _compiler_options = {})
8
+ def self.compile(_template_dir, template_file_path, _sparkle_pack_template, _compile_time_parameters, _compiler_options = {})
9
9
  File.read(template_file_path)
10
10
  end
11
11
 
@@ -14,7 +14,7 @@ module StackMaster
14
14
  compile_time_parameters = ParameterResolver.resolve(@config, @stack_definition, parameter_hash[:compile_time_parameters])
15
15
 
16
16
  StackMaster.stdout.print "#{@stack_definition.stack_name}: "
17
- template_body = TemplateCompiler.compile(@config, @stack_definition.template_file_path, compile_time_parameters, @stack_definition.compiler_options)
17
+ template_body = TemplateCompiler.compile(@config, @stack_definition.template_dir, @stack_definition.template_file_path, @stack_definition.sparkle_pack_template, compile_time_parameters, @stack_definition.compiler_options)
18
18
  cf.validate_template(template_body: TemplateUtils.maybe_compressed_template_body(template_body))
19
19
  StackMaster.stdout.puts "valid"
20
20
  true
@@ -1,3 +1,3 @@
1
1
  module StackMaster
2
- VERSION = "1.15.0"
2
+ VERSION = "1.16.0"
3
3
  end
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: 1.15.0
4
+ version: 1.16.0
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: 2019-08-09 00:00:00.000000000 Z
12
+ date: 2019-08-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -529,7 +529,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
529
529
  - !ruby/object:Gem::Version
530
530
  version: '0'
531
531
  requirements: []
532
- rubygems_version: 3.0.3
532
+ rubyforge_project:
533
+ rubygems_version: 2.7.6.2
533
534
  signing_key:
534
535
  specification_version: 4
535
536
  summary: StackMaster is a sure-footed way of creating, updating and keeping track