(aws_servicecatalog): `cdk synth` already create a new logicID for resource [AWS::ServiceCatalog::PortfolioPrincipalAssociation]
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
`cdk synth` already create a new logicID for resource `AWS::ServiceCatalog::PortfolioPrincipalAssociation` if using `value_for_string_parameter()` and `from_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:
1. we have an existing IAM Role, and Service Catalog Portfolio in AWS account.
2. We store the Service Catalog Portfolio ARN into the SSM Parameter Store,
```
parameter name = PortfolioARN
parameter value = ARN of SC profile
```
3. we use `value_for_string_parameter` to get the parameter value () from SSM Parameter Store
3. we use `from_role_name` to import the IAM role to our CDK project
4. we use `from_portfolio_arn` to import the SC profile to our CDK project
## 2. Code Replication:
```
from constructs import Construct
from aws_cdk import (
Duration,
Stack,
aws_servicecatalog as sc,
aws_s3 as s3,
aws_iam as iam,
aws_ssm as ssm,
)
import aws_cdk as cdk
class CdkWorkshopStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
s3CopyRole = iam.Role.from_role_name(self, "s3CopyRole", "testS3bucketempty-role-caldj1zo")
myPortfolioArn = ssm.StringParameter.value_for_string_parameter(self,"PortfolioARN");
myPortfolio = sc.Portfolio.from_portfolio_arn(self,"test",myPortfolioArn)
myPortfolio.give_access_to_role(s3CopyRole);
```
-------
- when we run `cdk synth` several times, we can confirm the generated CFN template will already create a new new LogicalID of `AWS::ServiceCatalog::PortfolioPrincipalAssociation`. this will cause the error:
```
port-xxxxxx|arn:aws:iam:::role/ already exists in stack
```
- If we hardcode the `myPortfolioArn`, and re-run the `cdk synth`, LogicalID of `AWS::ServiceCatalog::PortfolioPrincipalAssociation` will keep the same.
### Possible Solution
CfnPortfolioPrincipalAssociation L1 construct works all good.
### Additional Information/Context
N/A
### CDK CLI Version
$ cdk --version 2.59.0 (build b24095d)
### Framework Version
_No response_
### Node.js Version
$ npm --v 8.15.0
### OS
Cloud9 Linux
### Language
Python
### Language Version
Python (3.7)
### Other information
N/A
Contributor guide
Research direction
Start with the Python APIs value_for_string_parameter(), from_portfolio_arn(), and give_access_to_role(), then compare synthesized templates across repeated runs. Use the working CfnPortfolioPrincipalAssociation L1 construct as a comparison point; done means the association keeps the same logical ID when the portfolio ARN comes from SSM, with regression coverage for the reproduction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100