-
Notifications
You must be signed in to change notification settings - Fork 38
feat(cli): build your own fromLookup()
imports with the new context provider for CloudControl API
#138
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
A generic Context Provider for CloudControl API. Extracted from aws/aws-cdk#33258.
Signed-off-by: github-actions <[email protected]>
Signed-off-by: github-actions <[email protected]>
@@ -31,6 +31,8 @@ import { | |||
} from '../../lib/commands/migrate'; | |||
import { MockSdkProvider, mockCloudFormationClient, restoreSdkMocksToDefault } from '../util/mock-sdk'; | |||
|
|||
jest.setTimeout(120_000); |
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.
Thank you!
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.
One minor comment. Otherwise good to go.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #138 +/- ##
==========================================
- Coverage 84.76% 84.58% -0.19%
==========================================
Files 196 198 +2
Lines 35187 35380 +193
Branches 4552 4555 +3
==========================================
+ Hits 29828 29926 +98
- Misses 5208 5310 +102
+ Partials 151 144 -7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: github-actions <[email protected]>
Signed-off-by: github-actions <[email protected]>
Signed-off-by: github-actions <[email protected]>
Signed-off-by: github-actions <[email protected]>
fromLookup()
imports with the new context provider for CloudControl API
### Issue # (if applicable) Closes #33606. Closes #15115. ### Reason for this change AWS-managed prefix lists are useful to control traffic VPC and AWS managed services. The name of the AWS-managed prefix list is documented but the id should be copy&paste by hand. ### Description of changes This PR implements `PrefixList.fromLookup()` to look up an existing managed prefix list by name. ``` ts ec2.PrefixList.fromLookup(this, 'CloudFrontOriginFacing', { prefixListName: 'com.amazonaws.global.cloudfront.origin-facing', }); ``` Uses the new CloudControl context provider: aws/aws-cdk-cli#138 and cdklabs/cloud-assembly-schema#124. ### Describe any new or updated permissions being added Nothing. ### Description of how you validated changes Added unit tests and an integ test. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
### Issue # (if applicable) Closes aws#33606. Closes aws#15115. ### Reason for this change AWS-managed prefix lists are useful to control traffic VPC and AWS managed services. The name of the AWS-managed prefix list is documented but the id should be copy&paste by hand. ### Description of changes This PR implements `PrefixList.fromLookup()` to look up an existing managed prefix list by name. ``` ts ec2.PrefixList.fromLookup(this, 'CloudFrontOriginFacing', { prefixListName: 'com.amazonaws.global.cloudfront.origin-facing', }); ``` Uses the new CloudControl context provider: aws/aws-cdk-cli#138 and cdklabs/cloud-assembly-schema#124. ### Describe any new or updated permissions being added Nothing. ### Description of how you validated changes Added unit tests and an integ test. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
### Issue # (if applicable) Closes #31720 This replaces my previous PR #32901. I addressed the PR comments in this new PR. This depends on this PR: cdklabs/cloud-assembly-schema#124. Also depends on this CDK CLI PR: aws/aws-cdk-cli#138. That PR should be merged first and the CLI released, before this PR can be merged. ### Reason for this change Add DatabaseInstance.fromLookup() feature ### Description of changes * Add CC API Context Provider. Needs this PR: cdklabs/cloud-assembly-schema#124 * DatabaseInstance.fromLookup call CC API to get the database instance info from instanceIdentifier. * Add units tests. ### Describe any new or updated permissions being added User will need to have permission to run CloudControl API. ### Description of how you validated changes Tested with this code. I already have an RDS DB in my AWS account. I want to look it up and grant connect to a new user. Saved to packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/my-test-app.ts ``` import * as cdk from 'aws-cdk-lib'; import * as iam from 'aws-cdk-lib/aws-iam'; import * as rds from 'aws-cdk-lib/aws-rds'; const awsAccountId = 'XXXXXXXXXX79'; const instanceId = 'XXXXXXXXXX-instance-1'; const appWithDb = new cdk.App(); const stack = new cdk.Stack(appWithDb, 'StackWithVpc', { env: { region: 'us-east-1', account: awsAccountId, }, }); const dbFromLookup = rds.DatabaseInstance.fromLookup(stack, 'dbFromLookup', { instanceIdentifier: instanceId, }); /* eslint-disable no-console */ console.log('lookup values', dbFromLookup.dbInstanceEndpointAddress, dbFromLookup.dbInstanceEndpointPort); const consoleReadOnlyRole = new iam.Role(stack, 'TestRole', { assumedBy: new iam.ArnPrincipal('arn_for_trusted_principal'), }); dbFromLookup.grantConnect(consoleReadOnlyRole, 'dbTestUser'); ``` Ran this command: ``` ../../aws-cdk/bin/cdk -a 'npx ts-node test/aws-rds/test/my-test-app.ts' synth ``` ### Checklist - [ X ] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
### 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 - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
A generic Context Provider for CloudControl API. See aws/aws-cdk#33258 for an example how to implement a
fromLookup()
method using the new context provider.(Extracted from aws/aws-cdk#33258)
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license