-
Notifications
You must be signed in to change notification settings - Fork 12
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
feat(toolkit-lib): bootstrap action #63
base: main
Are you sure you want to change the base?
Changes from all commits
dba2c09
6e3e58a
29973ef
73d8aee
f2769f5
e972af1
91b9ae8
35a789b
f8d8f4e
8ff4156
4e14148
52c9154
e48ae89
71e8b71
9e43a8f
b7f757f
7ab7957
997540a
2fcf944
e454a86
792f145
f6497a2
f0dd065
28ecc6a
536d2f7
64880df
103f7cd
fa8e75b
9450502
dbcb73e
849f7f9
bacd260
1a7588a
1b3100d
89acec0
d86a8b7
d2fd48b
70e7082
4e941da
95df4bf
5021e60
a77119a
7fab3ae
6024708
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,210 @@ | ||||||||||||||
import { Tag } from '../../api/aws-cdk'; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Options for Bootstrap | ||||||||||||||
*/ | ||||||||||||||
export interface BootstrapOptions { | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Bootstrap environment parameters for CloudFormation used when deploying the bootstrap stack | ||||||||||||||
* @default BootstrapEnvironmentParameters.onlyExisting() | ||||||||||||||
*/ | ||||||||||||||
readonly parameters?: BootstrapEnvironmentParameters; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* The template source of the bootstrap stack | ||||||||||||||
* | ||||||||||||||
* @default BootstrapSource.default() | ||||||||||||||
*/ | ||||||||||||||
readonly source?: BootstrapSource; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Whether to execute the changeset or only create it and leave it in review | ||||||||||||||
* @default true | ||||||||||||||
*/ | ||||||||||||||
readonly execute?: boolean; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Tags for cdktoolkit stack | ||||||||||||||
* | ||||||||||||||
* @default [] | ||||||||||||||
*/ | ||||||||||||||
readonly tags?: Tag[]; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Whether the stacks created by the bootstrap process should be protected from termination | ||||||||||||||
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-protect-stacks.html | ||||||||||||||
* @default true | ||||||||||||||
*/ | ||||||||||||||
readonly terminationProtection?: boolean; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Use previous values for unspecified parameters | ||||||||||||||
* | ||||||||||||||
* If not set, all parameters must be specified for every deployment | ||||||||||||||
* | ||||||||||||||
* @default true | ||||||||||||||
*/ | ||||||||||||||
usePreviousParameters?: boolean; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Parameter values for the bootstrapping template | ||||||||||||||
*/ | ||||||||||||||
export interface BootstrapParameterValues { | ||||||||||||||
/** | ||||||||||||||
* The name to be given to the CDK Bootstrap bucket | ||||||||||||||
* By default, a name is generated by CloudFormation | ||||||||||||||
* | ||||||||||||||
* @default - No value, optional argument | ||||||||||||||
*/ | ||||||||||||||
readonly bucketName?: string; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* The ID of an existing KMS key to be used for encrypting items in the bucket | ||||||||||||||
* By default, the default KMS key is used | ||||||||||||||
* | ||||||||||||||
* @default - No value, optional argument | ||||||||||||||
*/ | ||||||||||||||
readonly kmsKeyId?: string; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Whether or not to create a new customer master key (CMK) | ||||||||||||||
* | ||||||||||||||
* Only applies to modern bootstrapping | ||||||||||||||
* Legacy bootstrapping will never create a CMK, only use the default S3 key | ||||||||||||||
* | ||||||||||||||
* @default false | ||||||||||||||
*/ | ||||||||||||||
readonly createCustomerMasterKey?: boolean; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* The list of AWS account IDs that are trusted to deploy into the environment being bootstrapped | ||||||||||||||
* | ||||||||||||||
* @default [] | ||||||||||||||
*/ | ||||||||||||||
readonly trustedAccounts?: string[]; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* The list of AWS account IDs that are trusted to look up values in the environment being bootstrapped | ||||||||||||||
* | ||||||||||||||
* @default [] | ||||||||||||||
*/ | ||||||||||||||
readonly trustedAccountsForLookup?: string[]; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* The list of AWS account IDs that should not be trusted by the bootstrapped environment | ||||||||||||||
* If these accounts are already trusted, they will be removed on bootstrapping | ||||||||||||||
* | ||||||||||||||
* @default [] | ||||||||||||||
*/ | ||||||||||||||
readonly untrustedAccounts?: string[]; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* The ARNs of the IAM managed policies that should be attached to the role performing CloudFormation deployments | ||||||||||||||
* In most cases, this will be the AdministratorAccess policy | ||||||||||||||
* At least one policy is required if `trustedAccounts` were passed | ||||||||||||||
* | ||||||||||||||
* @default [] | ||||||||||||||
*/ | ||||||||||||||
readonly cloudFormationExecutionPolicies?: string[]; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Identifier to distinguish multiple bootstrapped environments | ||||||||||||||
* The default qualifier is an arbitrary but unique string | ||||||||||||||
* | ||||||||||||||
* @default - 'hnb659fds' | ||||||||||||||
*/ | ||||||||||||||
readonly qualifier?: string; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Whether or not to enable S3 Staging Bucket Public Access Block Configuration | ||||||||||||||
* | ||||||||||||||
* @default true | ||||||||||||||
*/ | ||||||||||||||
readonly publicAccessBlockConfiguration?: boolean; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Flag for using the default permissions boundary for bootstrapping | ||||||||||||||
* | ||||||||||||||
* @default - No value, optional argument | ||||||||||||||
*/ | ||||||||||||||
readonly examplePermissionsBoundary?: boolean; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Name for the customer's custom permissions boundary for bootstrapping | ||||||||||||||
* | ||||||||||||||
* @default - No value, optional argument | ||||||||||||||
*/ | ||||||||||||||
readonly customPermissionsBoundary?: string; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Parameters for the bootstrapping template with flexible configuration options | ||||||||||||||
*/ | ||||||||||||||
export class BootstrapEnvironmentParameters { | ||||||||||||||
/** | ||||||||||||||
* Use only existing parameters on the stack. | ||||||||||||||
*/ | ||||||||||||||
public static onlyExisting() { | ||||||||||||||
return new BootstrapEnvironmentParameters({}, true); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Use exactly these parameters and remove any other existing parameters from the stack. | ||||||||||||||
*/ | ||||||||||||||
public static exactly(params: BootstrapParameterValues) { | ||||||||||||||
return new BootstrapEnvironmentParameters(params, false); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Define additional parameters for the stack, while keeping existing parameters for unspecified values. | ||||||||||||||
*/ | ||||||||||||||
public static withExisting(params: BootstrapParameterValues) { | ||||||||||||||
return new BootstrapEnvironmentParameters(params, true); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* The parameters as a Map for easy access and manipulation | ||||||||||||||
*/ | ||||||||||||||
public readonly parameters?: BootstrapParameterValues; | ||||||||||||||
public readonly keepExistingParameters: boolean; | ||||||||||||||
|
||||||||||||||
private constructor(params?: BootstrapParameterValues, usePreviousParameters = true) { | ||||||||||||||
this.keepExistingParameters = usePreviousParameters; | ||||||||||||||
this.parameters = params; | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Source configuration for bootstrap operations | ||||||||||||||
*/ | ||||||||||||||
export class BootstrapSource { | ||||||||||||||
/** | ||||||||||||||
* Use the default bootstrap template | ||||||||||||||
*/ | ||||||||||||||
static default(): BootstrapSource { | ||||||||||||||
return new BootstrapSource('default'); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Use a custom bootstrap template | ||||||||||||||
*/ | ||||||||||||||
static customTemplate(templateFile: string): BootstrapSource { | ||||||||||||||
return new BootstrapSource('custom', templateFile); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
private readonly source: 'default' | 'custom'; | ||||||||||||||
private readonly templateFile?: string; | ||||||||||||||
Comment on lines
+197
to
+198
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why make it public? That would allow the user to get the source and templateFile without going through the render function. i.e. code in bootstrap that looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the code in Bootstrap would be just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This causes some Typescript errors:
There are two valid options for
But removing
Given our static methods, this is not possible, but TypeScript doesn't know that. |
||||||||||||||
private constructor(source: 'default' | 'custom', templateFile?: string) { | ||||||||||||||
this.source = source; | ||||||||||||||
this.templateFile = templateFile; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
public render() { | ||||||||||||||
return { | ||||||||||||||
source: this.source, | ||||||||||||||
...(this.templateFile ? { templateFile: this.templateFile } : {}), | ||||||||||||||
} as { source: 'default' } | { source: 'custom'; templateFile: string }; | ||||||||||||||
} | ||||||||||||||
Comment on lines
+204
to
+209
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you make the props public, I think you don't need the render helper
Suggested change
|
||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as cxapi from '@aws-cdk/cx-api'; | ||
import { ToolkitError } from '../../../api/errors'; | ||
|
||
/** | ||
* Given a set of "<account>/<region>" strings, construct environments for them | ||
*/ | ||
export function environmentsFromDescriptors(envSpecs: string[]): cxapi.Environment[] { | ||
const ret = new Array<cxapi.Environment>(); | ||
|
||
for (const spec of envSpecs) { | ||
const parts = spec.replace(/^aws:\/\//, '').split('/'); | ||
if (parts.length !== 2) { | ||
throw new ToolkitError(`Expected environment name in format 'aws://<account>/<region>', got: ${spec}`); | ||
} | ||
|
||
ret.push({ | ||
name: spec, | ||
account: parts[0], | ||
region: parts[1], | ||
}); | ||
} | ||
|
||
return ret; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './helpers'; |
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.
Actually this is what I meant to roll into
BootstrappingParameters
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.
Changed it to model how we handle this in
deploy