terraspace 1.1.0 → 1.1.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: c6c8809128dbbbf51d0f654c92784a879c88cab49d31e15e2a1d827c4b40d051
4
- data.tar.gz: c557bd4692fddd9a1bf859a986566780cb6ccd6024dcdb3e7979138a42f1e00e
3
+ metadata.gz: c07e843df9e61e62be834feba56f4d5fa058f3dbb130ed7e15edca66ef23e22d
4
+ data.tar.gz: a7d7c3946e2485ccb369a5d76d413118aed14592750880a48990ca83cdca5bca
5
5
  SHA512:
6
- metadata.gz: 8b28d7d1b8565fa0f646fda57163b6d21486db7e7f704ebe657a219335e66504206769e487cec9dc3f30da06ac793e28d81b1709ebd4c32a39a70a5d8668be05
7
- data.tar.gz: 1a09efc8d460c9267371aca9dbb130e4dbb1c9268ea870e19d6a9734aa48e0134b3cee09aedfe894acfd2c7e956a1fed4bf7b38cad9cf9b13b935802bd2fa4a7
6
+ metadata.gz: 026aa5128ce2bea7deb3e5b0fdb6e99c7cf50297c20f5292bbe6896dabb0ba995e62ecd14526ea2ea7e8e1a4be3895e29021620a89b26df49ad34ee0b95ffd1d
7
+ data.tar.gz: c2df058d2fe9848834fc4e166c1382ccb0e782170fb52f8fd264e4e948a1032916cc9d77662eac1969f4d2101e66b3655e07d944b217e5749581ac0d3ec04916
data/CHANGELOG.md CHANGED
@@ -3,6 +3,9 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [1.1.1] - 2022-02-02
7
+ - [#199](https://github.com/boltops-tools/terraspace/pull/199) build required dependent stacks as part of terraspace up
8
+
6
9
  ## [1.1.0] - 2022-01-30
7
10
  - [#196](https://github.com/boltops-tools/terraspace/pull/196) terraspace all: build modules in batches and only each specific stack
8
11
  - [#197](https://github.com/boltops-tools/terraspace/pull/197) all plan --output and all up --plan options
@@ -54,13 +54,13 @@ module Terraspace::All
54
54
  end
55
55
 
56
56
  def build_modules
57
- builder = Terraspace::Builder.new(@options.merge(mod: "placeholder", quiet: true, clean: true))
58
- builder.build(modules: true, stack: false)
57
+ builder = Terraspace::Builder.new(@options.merge(mod: "placeholder", clean: true, quiet: true, include_stacks: :none))
58
+ builder.build(modules: true)
59
59
  end
60
60
 
61
61
  def build_stack(name)
62
- builder = Terraspace::Builder.new(@options.merge(mod: name, quiet: true, clean: false))
63
- builder.build(modules: false, stack: true)
62
+ builder = Terraspace::Builder.new(@options.merge(mod: name, clean: false, quiet: true, include_stacks: :root_only))
63
+ builder.build(modules: false)
64
64
  end
65
65
 
66
66
  def wait_for_child_proccess
@@ -16,7 +16,7 @@ module Terraspace
16
16
  config.all = ActiveSupport::OrderedOptions.new
17
17
  config.all.concurrency = 5
18
18
  config.all.exit_on_fail = ActiveSupport::OrderedOptions.new
19
- config.all.exit_on_fail.down = true
19
+ config.all.exit_on_fail.down = false
20
20
  config.all.exit_on_fail.plan = true
21
21
  config.all.exit_on_fail.up = true
22
22
 
@@ -0,0 +1,42 @@
1
+ class Terraspace::Builder
2
+ class Children
3
+ include Terraspace::Util::Logging
4
+
5
+ def initialize(mod, options={})
6
+ @mod, @options = mod, options
7
+ @queue = []
8
+ end
9
+
10
+ def build
11
+ dependencies = Terraspace::Dependency::Registry.data
12
+ # Find out if current deploy stack contains dependency
13
+ found = dependencies.find do |parent_child|
14
+ parent, _ = parent_child.split(':')
15
+ parent == @mod.name
16
+ end
17
+ return unless found
18
+
19
+ # Go down graph children, which are the dependencies to build a queue
20
+ parent, _ = found.split(':')
21
+ node = Terraspace::Dependency::Node.find_by(name: parent)
22
+ build_queue(node)
23
+
24
+ logger.debug "Terraspace::Builder::Children @queue #{@queue}"
25
+
26
+ # Process queue in reverse order to build leaf nodes first
27
+ @queue.reverse.each do |node|
28
+ mod = Terraspace::Mod.new(node.name, @options)
29
+ Terraspace::Compiler::Perform.new(mod).compile
30
+ end
31
+ end
32
+
33
+ # Use depth first traversal to build queue
34
+ def build_queue(node)
35
+ node.children.each do |child|
36
+ @queue << child
37
+ build_queue(child)
38
+ end
39
+ @queue
40
+ end
41
+ end
42
+ end
@@ -4,23 +4,40 @@ module Terraspace
4
4
  include Compiler::DirsConcern
5
5
  include Hooks::Concern
6
6
 
7
+ # @include_stacks can be 3 values: root_with_children, none, root_only
8
+ #
9
+ # none: dont build any stacks at all. used by `terraspace all up`
10
+ # root_only: only build root stack. used by `terraspace all up`
11
+ # root_with_children: build all parent stacks as well as the root stack. normal `terraspace up`
12
+ #
13
+ def initialize(options={})
14
+ super
15
+ @include_stacks = @options[:include_stacks] || :root_with_children
16
+ end
17
+
7
18
  def run
8
19
  return if @options[:build] == false
9
20
  Terraspace::CLI::Setup::Check.check!
10
21
  check_allow!
11
22
  @mod.root_module = true
12
23
  clean
24
+ resolve_dependencies if @include_stacks == :root_with_children
13
25
  build
14
26
  end
15
27
 
16
- def build(modules: true, stack: true)
28
+ def resolve_dependencies
29
+ resolver = Terraspace::Dependency::Resolver.new(@options.merge(quiet: true))
30
+ resolver.resolve # returns batches
31
+ end
32
+
33
+ def build(modules: true)
17
34
  build_dir = Util.pretty_path(@mod.cache_dir)
18
35
  placeholder_stack_message
19
36
  logger.info "Building #{build_dir}" unless @options[:quiet] # from terraspace all
20
37
  FileUtils.mkdir_p(@mod.cache_dir) # so terraspace before build hooks work
21
38
  run_hooks("terraspace.rb", "build") do
22
39
  build_dir("modules") if modules
23
- build_root_module if stack
40
+ build_stacks
24
41
  logger.info "Built in #{build_dir}" unless @options[:quiet] # from terraspace all
25
42
  end
26
43
  end
@@ -29,16 +46,23 @@ module Terraspace
29
46
  Allow.new(@mod).check!
30
47
  end
31
48
 
32
- def build_root_module
33
- @mod.resolved = true
34
- Compiler::Perform.new(@mod).compile
49
+ def build_stacks
50
+ return if @include_stacks == :none
51
+ build_children_stacks if @include_stacks == :root_with_children
52
+ Compiler::Perform.new(@mod).compile # @include_stacks :root or :root_with_children
53
+ end
54
+
55
+ # Build stacks that are part of the dependency graph. Because .terraspace-cache folders
56
+ # need to exist so `terraform state pull` works to get the state info.
57
+ def build_children_stacks
58
+ children = Children.new(@mod, @options)
59
+ children.build
35
60
  end
36
61
 
37
62
  def build_dir(type_dir)
38
63
  with_each_mod(type_dir) do |mod|
39
- mod.resolved = true
40
64
  is_root_module = mod.cache_dir == @mod.cache_dir
41
- next if is_root_module # handled by build_root_module
65
+ next if is_root_module # handled by build_stacks
42
66
  Compiler::Perform.new(mod).compile
43
67
  end
44
68
  end
@@ -8,6 +8,7 @@ module Terraspace::Dependency
8
8
 
9
9
  def resolve
10
10
  with_each_mod("stacks") do |mod|
11
+ mod.resolved = false
11
12
  Terraspace::Compiler::Perform.new(mod).compile_tfvars(write: false)
12
13
  end
13
14
 
@@ -15,6 +15,7 @@ module Terraspace
15
15
  @name, @options = placeholder(name), options
16
16
  @consider_stacks = options[:consider_stacks].nil? ? true : options[:consider_stacks]
17
17
  @instance = options[:instance]
18
+ @resolved = true # more common case
18
19
  end
19
20
 
20
21
  def placeholder(name)
@@ -49,7 +49,7 @@ module Terraspace::Plugin::Summary
49
49
  def download_statefiles
50
50
  return unless download?
51
51
  FileUtils.rm_rf(@dest_folder)
52
- logger.info("Downloading statefiles to #{@dest_folder}")
52
+ logger.debug("Downloading statefiles to #{@dest_folder}")
53
53
  download # INTERFACE METHOD
54
54
  end
55
55
 
@@ -48,7 +48,7 @@ module Terraspace::Terraform::RemoteState
48
48
  def output_error(type)
49
49
  msg = case type
50
50
  when :key_not_found
51
- "Output #{@output_key} was not found for the #{@parent.name} tfvars file. Either #{@child.name} stack has not been deployed yet or it does not have this output: #{@output_key}"
51
+ "Output #{@output_key} was not found for the #{@parent.name} tfvars file. Either #{@child.name} stack has not been deployed yet or it does not have this output: #{@output_key}. Also, if local backend is being used and has been removed/cleaned, then it will also result zero-byte state.json with the 'terraform state pull' used to download the terraform state and output will not be found."
52
52
  when :state_not_found
53
53
  "Output #{@output_key} could not be looked up for the #{@parent.name} tfvars file. #{@child.name} stack needs to be deployed"
54
54
  when :bucket_not_found
@@ -63,7 +63,7 @@ module Terraspace::Terraform::RemoteState
63
63
  @@download_shown = false
64
64
  def pull
65
65
  return if @@pull_successes[cache_key]
66
- logger.info "Downloading tfstate files for dependencies defined in tfvars..." unless @@download_shown || @options[:quiet]
66
+ logger.debug "Downloading tfstate files for dependencies defined in tfvars..." unless @@download_shown || @options[:quiet]
67
67
  @@download_shown = true
68
68
  logger.debug "Downloading tfstate for stack: #{@child.name}"
69
69
 
@@ -1,3 +1,3 @@
1
1
  module Terraspace
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -1,6 +1,10 @@
1
1
  describe Terraspace::Compiler::Erb::Render do
2
2
  let(:render) { described_class.new(mod, src_path) }
3
- let(:mod) { Terraspace::Mod.new("a1") }
3
+ let(:mod) do
4
+ mod = Terraspace::Mod.new("a1")
5
+ mod.resolved = false
6
+ mod
7
+ end
4
8
 
5
9
  # Only testing mod unresolved as a sanity check and its worth the ROI.
6
10
  # The resolved would the Fetcher. We have unit tests to cover those other changes.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terraspace
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-30 00:00:00.000000000 Z
11
+ date: 2022-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -490,6 +490,7 @@ files:
490
490
  - lib/terraspace/builder/allow/env.rb
491
491
  - lib/terraspace/builder/allow/region.rb
492
492
  - lib/terraspace/builder/allow/stack.rb
493
+ - lib/terraspace/builder/children.rb
493
494
  - lib/terraspace/bundle.rb
494
495
  - lib/terraspace/cli.rb
495
496
  - lib/terraspace/cli/all.rb