Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overriding getLogicalId causes disallowed characters in the cross-stack-output ID #3512

Open
1 task
MWS-TAI opened this issue Feb 20, 2024 · 1 comment
Open
1 task
Labels
bug Something isn't working

Comments

@MWS-TAI
Copy link

MWS-TAI commented Feb 20, 2024

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:
Screenshot 2024-02-20 at 1 03 08 pm

terminal output:
Screenshot 2024-02-20 at 1 02 17 pm

Steps to Reproduce

  1. Create cross stack dependency by reference a resource from a seperate stack
  2. Override getLogicalId as per #4334
  3. 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
@MWS-TAI MWS-TAI added bug Something isn't working new Un-triaged issue labels Feb 20, 2024
@ansgarm
Copy link
Member

ansgarm commented Feb 26, 2024

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.

@ansgarm ansgarm removed the new Un-triaged issue label Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants