-
Notifications
You must be signed in to change notification settings - Fork 4k
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
fix(cli): can't bootstrap environment not in app #7510
Conversation
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.)
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
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.
provisional - can you also update the title... the double negatives got me for a second
@@ -56,7 +56,8 @@ async function parseCommandLineArguments() { | |||
.option('tags', { type: 'array', alias: 't', desc: 'Tags to add for the stack (KEY=VALUE)', nargs: 1, requiresArg: true, default: [] }) | |||
.option('execute', {type: 'boolean', desc: 'Whether to execute ChangeSet (--no-execute will NOT execute the ChangeSet)', default: true}) | |||
.option('trust', { type: 'array', desc: 'The (space-separated) list of AWS account IDs that should be trusted to perform deployments into this environment', default: [], hidden: true }) | |||
.option('cloudformation-execution-policies', { type: 'array', desc: 'The (space-separated) list of Managed Policy ARNs that should be attached to the role performing deployments into this environment. Required if --trust was passed', default: [], hidden: true }), | |||
.option('cloudformation-execution-policies', { type: 'array', desc: 'The (space-separated) list of Managed Policy ARNs that should be attached to the role performing deployments into this environment. Required if --trust was passed', default: [], hidden: true }) | |||
.option('force', { alias: 'f', type: 'boolean', desc: 'Always bootstrap even if it would downgrade template version', default: false }), |
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.
makes sense to protect against it, but what's the use case behind forcing a bootstrap and the implication of using a downgraded template version?
when would it be used?
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.
I don't want to prevent people from doing what they're trying to do, in case we get it wrong (for whatever reason).
Just feels like any protection should have an 'override' feature'.
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.
fair enough
* The `region` and `accountId` parameters are interpreted as in `resolveEnvironment()` (which is to | ||
* say, `undefined` doesn't do what you expect). |
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 comment needs updating
* `undefined` actually means `undefined`, and is NOT changed to default values! Only the magic values UNKNOWN_REGION | ||
* and UNKNOWN_ACCOUNT will be replaced with looked-up values! |
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.
ditto
public async resolveEnvironmentObject(env: cxapi.Environment) { | ||
return this.resolveEnvironment(env.account, env.region); |
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.
there was nothing using this?
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.
There was one place, but this was the method that resolveEnvironment
should have been all along.
if (!region) { | ||
throw new Error('AWS region must be configured either when you configure your CDK stack or through the environment'); | ||
} |
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.
was this dead code?
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.
Yep
const newVersion = bootstrapVersionFromTemplate(template); | ||
const currentBootstrapStack = await ToolkitInfo.lookup(resolvedEnvironment, sdk, toolkitStackName); | ||
if (currentBootstrapStack && newVersion < currentBootstrapStack.version && !options.force) { | ||
throw new Error(`Refusing to downgrade existing bootstrap stack from version '${currentBootstrapStack.version}' to version '${newVersion}'. Use --force to force.`); |
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.
throw new Error(`Refusing to downgrade existing bootstrap stack from version '${currentBootstrapStack.version}' to version '${newVersion}'. Use --force to force.`); | |
throw new Error(`Downgrade not allowed. The existing bootstrap stack version '${currentBootstrapStack.version}' is higher than version '${newVersion}'. Use --force to force.`); |
maybe it's just the word "refusing" i don't like
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.
I modeled this after tar
's "Cowardly refusing to create an empty archive" :).
I'll rephrase.
@@ -29,6 +29,7 @@ export class ToolkitInfo { | |||
sdk, environment, | |||
bucketName: requireOutput(BUCKET_NAME_OUTPUT), | |||
bucketEndpoint: requireOutput(BUCKET_DOMAIN_NAME_OUTPUT), | |||
version: parseInt(outputs[BOOTSTRAP_VERSION_OUTPUT] ?? '0', 10), |
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.
is the bootstrap version always going to be bumped up by numbers? (i.e. as opposed to 1.1.0
vs 1.2.0
would both parse to the same int)
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.
Yep
packages/aws-cdk/lib/cdk-toolkit.ts
Outdated
// Partition into globs and non-globs (this will mutate environmentSpecs). | ||
const globSpecs = partition(environmentSpecs, looksLikeGlob); | ||
if (globSpecs.length > 0 && !this.props.cloudExecutable.hasApp) { | ||
throw new Error(`Don't know how to bootstrap environment '${globSpecs}'. Run in app directory or specify an environment name like \'aws://123456789012/us-east-1\'.`); |
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.
throw new Error(`Don't know how to bootstrap environment '${globSpecs}'. Run in app directory or specify an environment name like \'aws://123456789012/us-east-1\'.`); | |
throw new Error(`Unable to bootstrap environment '${globSpecs}'. Run in app directory or specify an environment name like \'aws://123456789012/us-east-1\'.`); |
I don't think "don't know how to" adds as much as the guidance that follows after it.
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 master 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 master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Another commit split off from #6366 to make that other one more manageable to review :).
Commit Message
fix(cli): can't bootstrap environment not in app
It used to be that if we had an
--app
argument, we would always globarguments to
cdk bootstrap <ENV>
through the environments of stacksin 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 stackthere 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:
of
(account, region)
. Replace those by passing acxapi.Environment
instead (most of the changes in this PR).
copy/pasta between them. Refactored to make them share code.
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.)
End Commit Message
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license