Open UlaJiang opened 1 year ago
I can confirm this behavior, thanks for reporting.
This is happening because a unique hash is being generated and attached to the logical id: https://github.com/aws/aws-cdk/blob/c164a49c67def802a84f37b6ad779a78442e5a53/packages/%40aws-cdk/aws-servicecatalog/lib/portfolio.ts#L236-L246
I believe the root cause of this issue is that using a string parameter will make it so that the portfolio arn value is a token, which the token itself can have varying values between different synths (e.g. I printed ${Token[TOKEN.578]}
, ${Token[TOKEN.580]}
between different synths without changing the code at all). This differing value is taken into account when the hash is created, causing the logical ID to change.
You can work around this by using an escape hatch to override the logical ID, or as you said, dropping down to the L1 resource works as well.
I am marking this issue as p2, which means that we are unable to work on this immediately.
We use +1s to help prioritize our work, and are happy to revaluate this issue based on community feedback. You can reach out to the cdk.dev community on Slack to solicit support for reprioritization.
@peterwoodworth my team is hitting this issue and I would like to pursue resolving this. My guess is that the correct way to fix the problem is to use a Lazy
string for the tag option identifier around https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-servicecatalog/lib/tag-options.ts#L55C1-L60C12 , so that the sha hashing can be done correctly at synth time. Does that approach sound reasonable for a start, to you?
Describe the bug
cdk synth
already create a new logicID for resourceAWS::ServiceCatalog::PortfolioPrincipalAssociation
if usingvalue_for_string_parameter()
andfrom_portfolio_arn()
method.Expected Behavior
cdk synth
should generate the same template (same logicID of resources)Current Behavior
cdk synth
generatedifferent logicID of resource [AWS::ServiceCatalog::PortfolioPrincipalAssociation]Reproduction Steps
1. Use case:
value_for_string_parameter
to get the parameter value (from_role_name
to import the IAM role to our CDK projectfrom_portfolio_arn
to import the SC profile to our CDK project2. Code Replication:
) import aws_cdk as cdk
class CdkWorkshopStack(Stack):
port-xxxxxx|arn:aws:iam:::role/ already exists in stack