aws-cdk-lib: NestedStacks dont perform lookups on a cross-account setup #25624
Labels
@aws-cdk/core
Related to core CDK functionality
bug
This issue is a bug.
duplicate
This issue is a duplicate.
p1
Describe the bug
When setting a cross-account CDK project, if one of the Stacks being deployed on a target account (different than the deployment account) has a NestedStacks which needs to perform a lookup operation (for example, to create a VPC), then CDK is having credential issues, not being able of doing those lookups and interrupting the synth process.
This is because the NestedStack's synthesizer doesn't receive the lookupRoleArn from the parent stack synthesizer, so the NestedStack tries with local credentials (of the deployment account) instead of assuming a cross-account role (on the target account) as regular non-nested Stack would do.
A workaround for this is to manually define the required context on cdk.context.json so CDK doesn't try to fetch the information.
This is of special interest on CDK's projects being deployed by cdk-pipelines
Expected Behavior
An CDK's NestedStack should have the parent's lookupRoleArn so it can perform a succesful lookup and add the information to the context provider.
Current Behavior
When trying an cdk synth, the following error is being thrown:
[Error at /PipelineStack/App/AppStack/Nested-Stack] Need to perform AWS calls for account XXXXXXXX, but the current credentials are for YYYYYYYY
Where YYYYYYY is the deployment account (where the synth is being made) and XXXXXXXX is the target account.
Reproduction Steps
pipeline.ts
pipeline-stack.ts
Possible Solution
Add the variable lookupRoleArn on the Synthesizers Interfaces and invoke the function synthesizeTemplate of class NestedStackSynthesizer accordingly
Additional Information/Context
No response
CDK CLI Version
2.79.1 (build 2e7f8b7)
Framework Version
No response
Node.js Version
v16.20.0
OS
Amazon Linux 2
Language
Typescript, Python
Language Version
No response
Other information
#21690
The text was updated successfully, but these errors were encountered: