aws / aws/aws-cdk

cli: automatic cross account integration tests

Open
#32,085 0 comments 0 reactions 1 assignee Claimed by @sai-ray View on GitHub
effort/medium feature-request p1 package/tools
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the feature

When running integration tests, invoke the CLI with credentials to a different account than the target account.

### Use Case

A fairly common setup for deploying CDK apps is providing the CLI with credentials to a role in centralized account (Account S) to perform the deployments to a target account (Account T).

This differs from the "standard" scenario where the CLI is executed with credentials to the target account. To make this setup work, the customer needs to setup trust relationships between both accounts, creating one variation of a **cross-account** auth setup.

In such a case, the CLI needs to take special care when invoking any AWS APIs because it must make sure its doing so with the appropriate assumed role. Running tests with this setup will automatically catch bugs that fail to do so.

> For example: https://github.com/aws/aws-cdk/issues/31845

### Proposed Solution

We already control CLI invocation inside our tests via the `TestFixture` (FLW: its probably ok to assume all tests use it). This means our fixture can assume a role in Account S, and invoke the CLI with its credentials, leaving Account T as is.

https://github.com/aws/aws-cdk/blob/33872f38ca4ef33e05d7f01ab36c192a30ab9137/packages/%40aws-cdk-testing/cli-integ/lib/with-cdk-app.ts#L525-L540

The only thing left to unpack here is where will the fixture get 2 accounts from? Currently, our framework only provides different regions in the same account.

https://github.com/aws/aws-cdk/blob/33872f38ca4ef33e05d7f01ab36c192a30ab9137/packages/%40aws-cdk-testing/cli-integ/lib/with-aws.ts#L38

So, we need to first implement the [test environment allocation service](https://github.com/aws/aws-cdk/issues/31938) to make this work.

### Other Information

Some peripheral considerations:

- We need to provide a way for tests to opt out of this behavior (there may be good reasons for it).
- Do we add this as a permutation of the test? or instead?

### Acknowledgements

- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change

### CDK version used

ALL

### Environment details (OS name and version, etc.)

ALL

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.