Hey everyone, I hit an issue with using the `!terr...
# atmos
s
Hey everyone, I hit an issue with using the
!terraform.output
function in a circular manner. It caused a recursive loop. FWIW I'm using the most recent version of atmos binary
Copy code
runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0x14044e80b60 stack=[0x14044e80000, 0x14064e80000]
fatal error: stack overflow
So I was wondering what the recommended approach was for sharing state information. My situation is as follows: I've got 2 stacks,
core
and
staging
and 1 component
vpc
The
vpc
component in
core
uses an output from the
vpc
component in
staging
which contains transit gateway attachment IDs, VPC CIDR ranges The
vpc
component in
staging
uses an output from the
vpc
component in
core
containing a transit gateway ID So now when I plan the component in either stack it errors with the above (and a massive stack trace). I would appreciate any guidance on how to do this in a better way as I am new to atmos.
a
thanks for reporting
we have a task to detect circular dependencies and show an error instead of panicking
use
!terraform.state
instead of
!terraform.output
, it's 10x faster and reads the state from the backend directly instead of executing
terraform output
let me know if using
!terraform.state
fixes the issue
s
Sadly the issue still occurs having swapped over to !terraform.state, not sure if the stack trace is different but it does error more quickly
p
if you do not keep your dependencies in check you are going to have this problems. This is is true without atmos and using depends_on all over the place in your hcl, so be careful
to avoid part of this problem you can use
depends_on
in atmos to always plan/apply resources base on the dependency tree BUT, BUT, BUT do not expect a plan to be successful right the first time you added a VPC and then you are asking for the
vpc_id
and the freaking thing has not been applied yet, avoid catch-22 and create a
process
around that instead of automation( what I means is that you document what are the hard required components for all other components to work and you go an apply those first)
s
oh yeah I completely agree on process, that's the approach I've taken. I've been making a disaster recovery document as I've been going to capture the order of operations from scratch
e
Yes, our plan is to error when we catch a cycle like this.
There is no way to know how to untangle a cycle automatically.
s
Awesome, that will definitely help having a suitable error. I'll just use the actual values from the output instead of using
!terraform.state
a
we can prob add an argument to the YAML function to not process YAML functions when it executes. This way, even if there's a cycle, the first encountered
terraform.state
or
terraform.output
will not process the other YAML functions. something like that, but we need to think about all edge cases
e