Exit On Failure Behaviour with Non-Dependant Stacks

Hello,

I am trying to understand how terraspace all up behaves when there are multiple non-dependant stacks in a project and one of them fails. Will it let the other stacks complete but have terraspace finish with non-zero exit code or will Terraspace send a kill signal to the other terraform apply commands running for the other stacks?

Thanks in advance!

+1
(I’m also interested in knowing what the behaviour would be too)

E.g. if I have

  • s3 (independent stack)
  • iam (independent stack)
  • vpc (parent stack)
  • subnets (child stack - dependent on the vpc stack)
  • ec2 (child stack - dependent on the subnets stack)

What happens if the iam stack fails (but not the s3, vpc, subnets or ec2 stacks)?

And perhaps still related to the original topic… Is it possible to target only the ec2 stack (and it’s dependencies i.e. the vpc and subnets stack, but not the s3 and iam stacks)? I.e. doing terraspace all up would run all stacks (including the independent s3 and iam stacks), but doing a terraspace up ec2 might fail due to dependencies on the vpc and subnet stacks?

Many thanks,
James

RE: Will it let the other stacks complete but have terraspace finish with non-zero exit code or will Terraspace send a kill signal to the other terraform apply commands running for the other stacks?

@nmorey-ratehub When a stack fails, Terraspace will stop and exit with a non-zero error code after that batch is finished. For example:

  • batch 1: stack1, stack2, stack3
  • batch 2: stack4, stack5

Once batch1 starts, all stack1, stack2, stack3 run in parallel. Let’s say stack2 fails, no signals are sent to stack1 and stack3, they will finish. Stacks running in parallel are considered independent. Terraspace will exit with a non-zero exit code after batch1 is done, and batch2 will not run.

This is the default behavior. Additionally, this behavior can be changed with configs:

config/app.rb

Terraspace.configure do |config|
  # These are the defaults
  all.exit_on_fail.down = true
  all.exit_on_fail.up = true
end

See: https://terraspace.cloud/docs/config/reference/

RE: Is it possible to target only the [specific stacks]

@jalam You can target subgraphs of the dependency tree. Just specify the stacks you want to target.

Example full graph in text form.

$ terraspace all graph --format text
β”œβ”€β”€ a1
β”‚   β”œβ”€β”€ b1
β”‚   β”‚   └── c1
β”‚   └── b2
β”‚       β”œβ”€β”€ c1
β”‚       └── c2
β”‚           └── d1
β”‚               └── e1
└── a2
    β”œβ”€β”€ c1
    └── b3
        └── c3

Targeting only parts of the graph:

$ terraspace all graph a2 b2 --format text 
β”œβ”€β”€ a2
β”‚   β”œβ”€β”€ c1
β”‚   └── b3
β”‚       └── c3
└── b2
    β”œβ”€β”€ c1
    └── c2
        └── d1
            └── e1

See: https://terraspace.cloud/docs/dependencies/subgraphs/

2 Likes

Hi Tung,

Got it, thanks! :smiley:

Cheers,
James