Skip to content

Cross-stack dependencies: When referring to a terraform resource across stacks, I receive an invalid reference error #3023

Open
@fathom-parth

Description

@fathom-parth

Expected Behavior

I expect to be able to pass a terraform resource from one stack to another to be used within a resource's depends_on argument.

Actual Behavior

Instead, the cross-stack reference errors when running a command like cdktf diff or cdktf deploy (though succeeds with synth) complaining that the resource in depends_on is invalid and must be a reference to a "whole object".

Steps to Reproduce

  1. Create 2 stacks, stack1 and stack2
  2. Set an instance variable of stack1 to a terraform resource. In our case, this is a service_networking_connection.
  3. Pass stack1.service_networking_connection to stack2 and have stack2 pass it to a construct. In that construct define a terraform resource (in our case a notebooks_runtime) that adds the service_networking_connection to its depends_on.
  4. Run cdktf diff 'stack1'
  5. Run cdktf deploy 'stack2'
  6. Verify this errors with an invalid depends_on error.

Versions

language: python
cdktf-cli: 0.17.1
node: v18.16.1
cdktf: 0.17.1
constructs: 10.2.69
jsii: 1.85.0
terraform: 1.4.6
arch: x64
os: linux 5.15.49-linuxkit
python: Python 3.7.16
pip: pip 21.3.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
pipenv: null

Providers

┌───────────────┬──────────────────┬─────────┬────────────┬──────────────────────────────────┬─────────────────┐
│ Provider Name │ Provider Version │ CDKTF │ Constraint │ Package Name │ Package Version │
├───────────────┼──────────────────┼─────────┼────────────┼──────────────────────────────────┼─────────────────┤
│ google │ 4.72.1 │ ^0.17.0 │ │ cdktf-cdktf-provider-google │ 8.0.4 │
├───────────────┼──────────────────┼─────────┼────────────┼──────────────────────────────────┼─────────────────┤
│ google-beta │ 4.72.1 │ ^0.17.0 │ │ cdktf-cdktf-provider-google-beta │ 8.0.4 │
└───────────────┴──────────────────┴─────────┴────────────┴──────────────────────────────────┴─────────────────┘

Gist

https://gist.github.com/fathom-parth/b98e9e5c451e1da0e6a5d4494275554b

Possible Solutions

No response

Workarounds

Currently, rather than granularly passing the TerraformResource to the relevant resource's depends_on argument, I instead set the 2nd stack to be on dependent on the 1st by running

stack2.add_dependency(stack1)

Anything Else?

It's possible that passing complete TerraformResource objects isn't supported since cross-stack references look at remote state? However, I don't see anything in the documentation that states this.

Please let me know if I missed something very obvious.

References

Help Wanted

  • I'm interested in contributing a fix myself

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingbug/has-workaroundA bug with a workaround (may not be elegant)cdktfconfirmedindependently reproduced by an engineer on the teamfeature/multi-stackhelp wantedCommunity contributions welcome as the core team is unlikely to work on this soonpriority/backlogLow priority (though possibly still important). Unlikely to be worked on within the next 6 months.size/mediumestimated < 1 weekux/configuration

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions