-
Notifications
You must be signed in to change notification settings - Fork 4.2k
feat(iam): support Role.fromLookup()
method
#33603
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(This review is outdated)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #33603 +/- ##
=======================================
Coverage 83.98% 83.98%
=======================================
Files 120 120
Lines 6976 6976
Branches 1178 1178
=======================================
Hits 5859 5859
Misses 1005 1005
Partials 112 112
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
…PI context provider (#211) CDK app with CC API Context Provider fails if the resource we want to get doesn't exist. ``` [Error at /LookupStack] Encountered CC API error while getting resource MyLookupTestRole. Error: ResourceNotFoundException: AWS::IAM::Role Handler returned status FAILED: The role with name MyLookupTestRole cannot be found. (Service: Iam, Status Code: 404, Request ID: xxxx-xxx-xxxx-xxxx) (HandlerErrorCode: NotFound, RequestToken: xxxx-xxx-xxxx-xxxx) ``` Also CC API Context Provider (`CcApiContextProviderPlugin`) cannot ignore errors even if `ignoreErrorOnMissingContext` is passed in aws-cdk-lib because the current code in aws-cdk-**cli** doesn't handle the property. Sample cdk-lib code (based on my [PR](aws/aws-cdk#33603) for IAM Role fromLookup): ```ts const response: {[key: string]: any}[] = ContextProvider.getValue(scope, { provider: cxschema.ContextProvider.CC_API_PROVIDER, props: { typeName: 'AWS::IAM::Role', exactIdentifier: options.roleName, propertiesToReturn: [ 'Arn', ], } as cxschema.CcApiContextQuery, dummyValue: [ { // eslint-disable-next-line @cdklabs/no-literal-partition Arn: 'arn:aws:iam::123456789012:role/DUMMY_ARN', }, ], ignoreErrorOnMissingContext: options.returnDummyRoleOnMissing, // added }).value; ``` However it would be good if the provider can ignore errors and return any dummy value to cdk library. This allows all resources to be **used if available, or created if not.** Actually, SSM and KMS provider can ignore errors: KMS: https://github.com/aws/aws-cdk-cli/blob/main/packages/aws-cdk/lib/context-providers/keys.ts#L43-L48 SSM: https://github.com/aws/aws-cdk-cli/blob/main/packages/aws-cdk/lib/context-providers/ssm-parameters.ts#L27-L30 For example, in cdk-lib, we can specify [ignoreErrorOnMissingContext](https://github.com/aws/aws-cdk/blob/v2.182.0/packages/aws-cdk-lib/aws-kms/lib/key.ts#L741-L744) in the `fromLookup`. The `dummyValue` and `ignoreErrorOnMissingContext` properties can also be specified in [GetContextValueOptions](https://github.com/go-to-k/aws-cdk/blob/45a276fd0fc9b7b08f69f7faf3d0091796ab1663/packages/aws-cdk-lib/core/lib/context-provider.ts#L31-L45). ## cli-integ aws/aws-cdk-cli-testing#50 --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license --------- Co-authored-by: Rico Hermans <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @go-to-k, thanks for the contribution! Just one small change and then I'm happy to approve!
Co-authored-by: paulhcsun <[email protected]>
@paulhcsun Thanks for your review! I fixed it. |
@Mergifyio update Thanks for the contribution @go-to-k!! |
✅ Branch has been successfully updated |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Comments on closed issues and PRs are hard for our team to see. |
Issue # (if applicable)
Closes #33602.
Reason for this change
There will be many cases where IAM roles will be created outside the CFn stack and used.
Importing actual existing roles from AWS accounts is very convenience. It is also useful to be able to make an error if a role does not exist.
On the other hand, a generic Context Provider for CloudControl API has been added in aws-cdk-cli.
aws/aws-cdk-cli#138
This allows us to implement new context methods.
Description of changes
Add
Role.fromLookup
method using the new context provider.Describe any new or updated permissions being added
Description of how you validated changes
Both unit and integ tests.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license