terraform-cdk
terraform-cdk copied to clipboard
Overriding getLogicalId causes disallowed characters in the cross-stack-output ID
Expected Behavior
When overriding getLogicalId (get_logical_id py func) to simply return the node id (as per 3433's solution), I would expect for cross-stack output's to also have correctly formatted resource IDs just like the rest of the resources.
Override function is below:
def get_logical_id(self, tf_element: Union[Construct, TerraformElement]) -> str:
return tf_element.node.id
Actual Behavior
The outputted cdk.tf.json correctly has a passable resource name, however, the following error is produced.
cdk.tf.json:
terminal output:
Steps to Reproduce
- Create cross stack dependency by reference a resource from a seperate stack
- Override getLogicalId as per #4334
- Execute a cdktf command that invokes backend initialisation (diff, deploy)
Versions
language: python cdktf-cli: 0.19.2 node: v21.5.0 cdktf: 0.20.3 constructs: 10.3.0 jsii: 1.94.0 terraform: 1.6.5 arch: arm64 os: darwin 23.2.0 python: Python 3.11.7 pip: pip 24.0 from /Users/mikeyscott/Documents/traffyk-ai-data-platform/.venv/lib/python3.11/site-packages/pip (python 3.11) pipenv: null
Providers
cdktf-cdktf-provider-archive (PREBUILT) terraform provider version: 2.4.2 prebuilt provider version: 10.0.1 cdktf version: ^0.20.0 cdktf-cdktf-provider-aws (PREBUILT) terraform provider version: 5.37.0 prebuilt provider version: 19.6.0 cdktf version: ^0.20.0 cdktf-cdktf-provider-tls (PREBUILT) terraform provider version: 4.0.5 prebuilt provider version: 10.0.0 cdktf version: ^0.20.0
Gist
No response
Possible Solutions
No response
Workarounds
Whilst not the best solution, adding a simple if condition to return the usual allocateLogicalId where the node id contains "cross-stack-output" (this doesn't seem to effect the "cross-stack-reference" id).
def get_logical_id(self, tf_element: Union[Construct, TerraformElement]) -> str:
if "cross-stack-output" in tf_element.node.id:
return self._allocate_logical_id(tf_element)
return tf_element.node.id
Anything Else?
I am using node 21 which throws the "untested node version warning". I don't suspect this would cause this issue.
This is also my first issue here so please let me know if I haven't don't anything correctly.
References
#3433
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
Hi @MWS-TAI 👋
It seems like there are dots introduced into the name by cross stack references (which is not valid Terraform). Normally they'd be replaced by the built-in logical id logic I suppose – so that would be something that would need to be replaced in your get_logical_id
implementation.
I did not test cross stack references when I looked into how to solve the outputs id request, so it seems that they require some more adjustment there.