From 6ce5b4abb92f1724e096b22bd66c9ec89227d714 Mon Sep 17 00:00:00 2001 From: Tung Nguyen Date: Tue, 22 Feb 2022 17:16:48 +0000 Subject: [PATCH] fix all down by building child nodes --- lib/terraspace/all/runner.rb | 3 ++- lib/terraspace/builder.rb | 8 +++++++- lib/terraspace/builder/children.rb | 13 ++++++------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/terraspace/all/runner.rb b/lib/terraspace/all/runner.rb index a5b78977..adabb33f 100644 --- a/lib/terraspace/all/runner.rb +++ b/lib/terraspace/all/runner.rb @@ -68,7 +68,8 @@ def build_modules end def build_stack(name) - builder = Terraspace::Builder.new(@options.merge(mod: name, clean: false, quiet: true, include_stacks: :root_only)) + include_stacks = @command == "down" ? :root_with_children : :root_only + builder = Terraspace::Builder.new(@options.merge(mod: name, clean: false, quiet: true, include_stacks: include_stacks)) builder.build(modules: false) end diff --git a/lib/terraspace/builder.rb b/lib/terraspace/builder.rb index 386e334d..deeedda5 100644 --- a/lib/terraspace/builder.rb +++ b/lib/terraspace/builder.rb @@ -6,9 +6,15 @@ class Builder < Terraspace::CLI::Base # @include_stacks can be 3 values: root_with_children, none, root_only # + # terraspace all: + # # none: dont build any stacks at all. used by `terraspace all up` # root_only: only build root stack. used by `terraspace all up` - # root_with_children: build all parent stacks as well as the root stack. normal `terraspace up` + # root_with_children: build all children stacks as well as the root stack. normal `terraspace all down` + # + # terraspace up: + # + # root_with_children: build all children stacks as well as the root stack. normal `terraspace up` # def initialize(options={}) super diff --git a/lib/terraspace/builder/children.rb b/lib/terraspace/builder/children.rb index 5eab3e7e..e92f8e5e 100644 --- a/lib/terraspace/builder/children.rb +++ b/lib/terraspace/builder/children.rb @@ -8,19 +8,18 @@ def initialize(mod, options={}) end def build - dependencies = Terraspace::Dependency::Registry.data # Find out if current deploy stack contains dependency - found = dependencies.find do |parent_child| + dependencies = Terraspace::Dependency::Registry.data + root = dependencies.find do |parent_child| parent, _ = parent_child.split(':') parent == @mod.name end - return unless found + return unless root - # Go down graph children, which are the dependencies to build a queue - parent, _ = found.split(':') - node = Terraspace::Dependency::Node.find_by(name: parent) + # Go down dependency graph to build a queue for processing + name, _ = root.split(':') + node = Terraspace::Dependency::Node.find_by(name: name) build_queue(node) - logger.debug "Terraspace::Builder::Children @queue #{@queue}" # Process queue in reverse order to build leaf nodes first