Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): can't bootstrap environment not in app
It used to be that if we had an `--app` argument, we would always glob arguments to `cdk bootstrap <ENV>` through the environments of stacks in the app. This makes it super hard/annoying to run `cdk bootstrap aws://1234/us-somewhere` in a CI/CD project; you have to add a stack there first and compile before you're allowed to do that, which is kinda silly. Change behavior to only glob environment from the environments in the app if it looks like the user is supplying a glob (if it contains `*`). If the user is supplying a concrete environment name, just use it directly. Also in this commit: - refactor: lots of places where we were passing around a pair of `(account, region)`. Replace those by passing a `cxapi.Environment` instead (most of the changes in this PR). - refactor: the old and new bootstrapping experience had a lot of copy/pasta between them. Refactored to make them share code. - (prerelease) feat: add a version check to the bootstrapping operation, so that users won't accidentally downgrade a bootstrap stack to an older version (This happened to 2 devs already, and is an easy mistake to make. Protect against it.)
- Loading branch information
Showing
29 changed files
with
508 additions
and
338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
packages/aws-cdk/lib/api/bootstrap/bootstrap-environment.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import * as cxapi from '@aws-cdk/cx-api'; | ||
import * as path from 'path'; | ||
import { loadStructuredFile } from '../../serialize'; | ||
import { SdkProvider } from '../aws-auth'; | ||
import { DeployStackResult } from '../deploy-stack'; | ||
import { BootstrapEnvironmentOptions } from './bootstrap-props'; | ||
import { deployBootstrapStack } from './deploy-bootstrap'; | ||
import { legacyBootstrapTemplate } from './legacy-template'; | ||
|
||
// tslint:disable:max-line-length | ||
|
||
/** | ||
* Deploy legacy bootstrap stack | ||
* | ||
* @experimental | ||
*/ | ||
export async function bootstrapEnvironment(environment: cxapi.Environment, sdkProvider: SdkProvider, options: BootstrapEnvironmentOptions): Promise<DeployStackResult> { | ||
const params = options.parameters ?? {}; | ||
|
||
if (params.trustedAccounts?.length) { | ||
throw new Error('--trust can only be passed for the new bootstrap experience.'); | ||
} | ||
if (params.cloudFormationExecutionPolicies?.length) { | ||
throw new Error('--cloudformation-execution-policies can only be passed for the new bootstrap experience.'); | ||
} | ||
|
||
return deployBootstrapStack( | ||
legacyBootstrapTemplate(params), | ||
{}, | ||
environment, | ||
sdkProvider, | ||
options); | ||
} | ||
|
||
/** | ||
* Deploy CI/CD-ready bootstrap stack from template | ||
* | ||
* @experimental | ||
*/ | ||
export async function bootstrapEnvironment2( | ||
environment: cxapi.Environment, | ||
sdkProvider: SdkProvider, | ||
options: BootstrapEnvironmentOptions): Promise<DeployStackResult> { | ||
|
||
const params = options.parameters ?? {}; | ||
|
||
if (params.trustedAccounts?.length && !params.cloudFormationExecutionPolicies?.length) { | ||
throw new Error('--cloudformation-execution-policies are required if --trust has been passed!'); | ||
} | ||
|
||
const bootstrapTemplatePath = path.join(__dirname, 'bootstrap-template.yaml'); | ||
const bootstrapTemplate = await loadStructuredFile(bootstrapTemplatePath); | ||
|
||
return deployBootstrapStack( | ||
bootstrapTemplate, | ||
{ | ||
FileAssetsBucketName: params.bucketName, | ||
FileAssetsBucketKmsKeyId: params.kmsKeyId, | ||
TrustedAccounts: params.trustedAccounts?.join(','), | ||
CloudFormationExecutionPolicies: params.cloudFormationExecutionPolicies?.join(','), | ||
}, | ||
environment, | ||
sdkProvider, | ||
options); | ||
} |
55 changes: 0 additions & 55 deletions
55
packages/aws-cdk/lib/api/bootstrap/bootstrap-environment2.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.