Skip to content

Commit

Permalink
Merge pull request #215 from boltops-tools/all
Browse files Browse the repository at this point in the history
fix all down by building child nodes
  • Loading branch information
tongueroo authored Feb 22, 2022
2 parents ffcdcf6 + 6ce5b4a commit 1e37b03
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lib/terraspace/all/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion lib/terraspace/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions lib/terraspace/builder/children.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1e37b03

Please # to comment.