Plan stack trace error after making change to existing infra

Hello,
I have a stack that uses data resources to lookup security groups in AWS and then passes the id’s as a list to a module that creates a Rabbit MQ cluster. This was all working fine until today when I added another security group to the list that’s passed to the module and I now get a stack trace when I run a plan. What could be causing this?

TS_ENV=dev terraspace plan migrate-rmq
Building .terraspace-cache/us-west-2/dev/stacks/migrate-rmq
Traceback (most recent call last):
        23: from /Users/mark/.rvm/gems/ruby-2.5.5/bin/ruby_executable_hooks:22:in `<main>'
        22: from /Users/mark/.rvm/gems/ruby-2.5.5/bin/ruby_executable_hooks:22:in `eval'
        21: from /Users/mark/.rvm/gems/ruby-2.5.5/bin/terraspace:23:in `<main>'
        20: from /Users/mark/.rvm/gems/ruby-2.5.5/bin/terraspace:23:in `load'
        19: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-0.6.18/exe/terraspace:14:in `<top (required)>'
        18: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/thor-1.1.0/lib/thor/base.rb:485:in `start'
        17: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-0.6.18/lib/terraspace/command.rb:61:in `dispatch'
        16: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch'
        15: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command'
        14: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/thor-1.1.0/lib/thor/command.rb:27:in `run'
        13: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-0.6.18/lib/terraspace/cli.rb:145:in `plan'
        12: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-0.6.18/lib/terraspace/cli/commander.rb:9:in `run'
        11: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-0.6.18/lib/terraspace/builder.rb:20:in `run'
        10: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-0.6.18/lib/terraspace/hooks/concern.rb:6:in `run_hooks'
         9: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-0.6.18/lib/terraspace/hooks/builder.rb:25:in `run_hooks'
         8: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-0.6.18/lib/terraspace/builder.rb:24:in `block in run'
         7: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-0.6.18/lib/terraspace/builder.rb:39:in `build_batches'
         6: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-0.6.18/lib/terraspace/dependency/graph.rb:14:in `build'
         5: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-0.6.18/lib/terraspace/dependency/graph.rb:55:in `build_nodes_with_dependencies'
         4: from /Users/mark/.rvm/rubies/ruby-2.5.5/lib/ruby/2.5.0/set.rb:338:in `each'
         3: from /Users/mark/.rvm/rubies/ruby-2.5.5/lib/ruby/2.5.0/set.rb:338:in `each_key'
         2: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-0.6.18/lib/terraspace/dependency/graph.rb:57:in `block in build_nodes_with_dependencies'
         1: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-0.6.18/lib/terraspace/dependency/graph.rb:64:in `save_node_parent'
/Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-0.6.18/lib/terraspace/dependency/node.rb:20:in `parent!': undefined method `children' for nil:NilClass (NoMethodError)

It seems that this could be related to the stack being included in the config.all.include_stacks in our config. After removing it from that, we don’t get the error when planning this single stack as expected per the docs. Is there a newer version with this fixed?

Dug into this. Don’t think there’s enough info here to help.

Created this test repo to try and debug: https://github.com/tongueroo/terraspace-graph-demo-nil-parent Wasn’t able to reproduce.

It’s covered in the repo README. Basically, configured config.all.include_stacks and was able to still drop down and run terraspace up on an individual stack.

Wondering if you can try a few things when you get a chance:

  • Upgrade to the latest version of terraspace
  • Take the example repo provided above and try to reproduce with that.
  • If can reproduce, then can stand a better fighting chance at figuring it out.

Hi Tung, thanks for taking a look at this.

I upgraded to Terraspace 1.0.6 and cloned your example repo. I wasn’t able to reproduce the error with the config.all.ignore_stacks = ["a3", "b1", "d1"] setting. But there was a suggestion to use the config.all.exclude_stacks method in the console output when I executed the ignore version. So I tried that and was able to reproduce the error by adding config.all.exclude_stacks = ["a3", "b1", "d1"] in the app.rb file and executing terraspace plan b1.

Here’s the full stack trace

terraspace plan b1
Building .terraspace-cache/us-west-2/dev/stacks/b1
WARN: The b1 stack does not exist
Here's the line in app/stacks/a1/tfvars/base.tfvars with the error:

1 length1 = <%= output("b1.length") %>
2 length2 = <%= output("b2.length") %>
WARN: The d1 stack does not exist
Here's the line in app/stacks/c2/tfvars/base.tfvars with the error:

1 length = <%= output("d1.length") %>
Traceback (most recent call last):
        24: from /Users/mark/.rvm/gems/ruby-2.5.5/bin/ruby_executable_hooks:22:in `<main>'
        23: from /Users/mark/.rvm/gems/ruby-2.5.5/bin/ruby_executable_hooks:22:in `eval'
        22: from /Users/mark/.rvm/gems/ruby-2.5.5/bin/terraspace:23:in `<main>'
        21: from /Users/mark/.rvm/gems/ruby-2.5.5/bin/terraspace:23:in `load'
        20: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-1.0.6/exe/terraspace:14:in `<top (required)>'
        19: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-1.0.6/lib/terraspace/cli/concern.rb:65:in `start'
        18: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/thor-1.2.1/lib/thor/base.rb:485:in `start'
        17: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-1.0.6/lib/terraspace/command.rb:61:in `dispatch'
        16: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
        15: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
        14: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
        13: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-1.0.6/lib/terraspace/cli.rb:154:in `plan'
        12: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-1.0.6/lib/terraspace/cli/commander.rb:9:in `run'
        11: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-1.0.6/lib/terraspace/builder.rb:20:in `run'
        10: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-1.0.6/lib/terraspace/hooks/concern.rb:6:in `run_hooks'
         9: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-1.0.6/lib/terraspace/hooks/builder.rb:25:in `run_hooks'
         8: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-1.0.6/lib/terraspace/builder.rb:23:in `block in run'
         7: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-1.0.6/lib/terraspace/builder.rb:38:in `build_batches'
         6: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-1.0.6/lib/terraspace/dependency/graph.rb:14:in `build'
         5: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-1.0.6/lib/terraspace/dependency/graph.rb:55:in `build_nodes_with_dependencies'
         4: from /Users/mark/.rvm/rubies/ruby-2.5.5/lib/ruby/2.5.0/set.rb:338:in `each'
         3: from /Users/mark/.rvm/rubies/ruby-2.5.5/lib/ruby/2.5.0/set.rb:338:in `each_key'
         2: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-1.0.6/lib/terraspace/dependency/graph.rb:57:in `block in build_nodes_with_dependencies'
         1: from /Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-1.0.6/lib/terraspace/dependency/graph.rb:64:in `save_node_parent'
/Users/mark/.rvm/gems/ruby-2.5.5/gems/terraspace-1.0.6/lib/terraspace/dependency/node.rb:20:in `parent!': undefined method `children' for nil:NilClass (NoMethodError)

Thanks for putting together the reproduction of the issue. Stuff like that really helps.

Okiedokie. Figured it out. It required quite a change to how terraspace builds and processes the batches as part of terraspace all. Details in this PR: https://github.com/boltops-tools/terraspace/pull/196

Upgrade to terraspace 1.1.0 and give it a go.

See: https://terraspace.cloud/docs/install/updating/

Thanks, that’s fixed it for us!

1 Like