|
| 1 | +import { StackSelector } from '../types'; |
| 2 | + |
| 3 | +export type DeploymentMethod = DirectDeploymentMethod | ChangeSetDeploymentMethod; |
| 4 | + |
| 5 | +export interface DirectDeploymentMethod { |
| 6 | + /** |
| 7 | + * Use stack APIs to the deploy stack changes |
| 8 | + */ |
| 9 | + readonly method: 'direct'; |
| 10 | +} |
| 11 | + |
| 12 | +export interface ChangeSetDeploymentMethod { |
| 13 | + /** |
| 14 | + * Use change-set APIS to deploy a stack changes |
| 15 | + */ |
| 16 | + readonly method: 'change-set'; |
| 17 | + |
| 18 | + /** |
| 19 | + * Whether to execute the changeset or leave it in review. |
| 20 | + * |
| 21 | + * @default true |
| 22 | + */ |
| 23 | + readonly execute?: boolean; |
| 24 | + |
| 25 | + /** |
| 26 | + * Optional name to use for the CloudFormation change set. |
| 27 | + * If not provided, a name will be generated automatically. |
| 28 | + */ |
| 29 | + readonly changeSetName?: string; |
| 30 | +} |
| 31 | + |
| 32 | +/** |
| 33 | + * When to build assets |
| 34 | + */ |
| 35 | +export enum AssetBuildTime { |
| 36 | + /** |
| 37 | + * Build all assets before deploying the first stack |
| 38 | + * |
| 39 | + * This is intended for expensive Docker image builds; so that if the Docker image build |
| 40 | + * fails, no stacks are unnecessarily deployed (with the attendant wait time). |
| 41 | + */ |
| 42 | + ALL_BEFORE_DEPLOY = 'all-before-deploy', |
| 43 | + |
| 44 | + /** |
| 45 | + * Build assets just-in-time, before publishing |
| 46 | + */ |
| 47 | + JUST_IN_TIME = 'just-in-time', |
| 48 | +} |
| 49 | + |
| 50 | +export interface Tag { |
| 51 | + readonly Key: string; |
| 52 | + readonly Value: string; |
| 53 | +} |
| 54 | + |
| 55 | +export enum RequireApproval { |
| 56 | + NEVER = 'never', |
| 57 | + ANY_CHANGE = 'any-change', |
| 58 | + BROADENING = 'broadening', |
| 59 | +} |
| 60 | + |
| 61 | +export enum HotswapMode { |
| 62 | + /** |
| 63 | + * Will fall back to CloudFormation when a non-hotswappable change is detected |
| 64 | + */ |
| 65 | + FALL_BACK = 'fall-back', |
| 66 | + |
| 67 | + /** |
| 68 | + * Will not fall back to CloudFormation when a non-hotswappable change is detected |
| 69 | + */ |
| 70 | + HOTSWAP_ONLY = 'hotswap-only', |
| 71 | + |
| 72 | + /** |
| 73 | + * Will not attempt to hotswap anything and instead go straight to CloudFormation |
| 74 | + */ |
| 75 | + FULL_DEPLOYMENT = 'full-deployment', |
| 76 | +} |
| 77 | + |
| 78 | +export class StackParameters { |
| 79 | + /** |
| 80 | + * Use only existing parameters on the stack. |
| 81 | + */ |
| 82 | + public static onlyExisting() { |
| 83 | + return new StackParameters({}, true); |
| 84 | + }; |
| 85 | + |
| 86 | + /** |
| 87 | + * Use exactly these parameters and remove any other existing parameters from the stack. |
| 88 | + */ |
| 89 | + public static exactly(params: { [name: string]: string | undefined }) { |
| 90 | + return new StackParameters(params, false); |
| 91 | + }; |
| 92 | + |
| 93 | + /** |
| 94 | + * Define additional parameters for the stack, while keeping existing parameters for unspecified values. |
| 95 | + */ |
| 96 | + public static withExisting(params: { [name: string]: string | undefined }) { |
| 97 | + return new StackParameters(params, true); |
| 98 | + }; |
| 99 | + |
| 100 | + public readonly parameters: Map<string, string | undefined>; |
| 101 | + public readonly keepExistingParameters: boolean; |
| 102 | + |
| 103 | + private constructor(params: { [name: string]: string | undefined }, usePreviousParameters = true) { |
| 104 | + this.keepExistingParameters = usePreviousParameters; |
| 105 | + this.parameters = new Map(Object.entries(params)); |
| 106 | + } |
| 107 | +} |
| 108 | + |
| 109 | +export interface BaseDeployOptions { |
| 110 | + /** |
| 111 | + * Criteria for selecting stacks to deploy |
| 112 | + */ |
| 113 | + readonly stacks: StackSelector; |
| 114 | + |
| 115 | + /** |
| 116 | + * Name of the toolkit stack to use/deploy |
| 117 | + * |
| 118 | + * @default CDKToolkit |
| 119 | + */ |
| 120 | + readonly toolkitStackName?: string; |
| 121 | + |
| 122 | + /** |
| 123 | + * Role to pass to CloudFormation for deployment |
| 124 | + */ |
| 125 | + readonly roleArn?: string; |
| 126 | + |
| 127 | + /** |
| 128 | + * @TODO can this be part of `DeploymentMethod` |
| 129 | + * |
| 130 | + * Always deploy, even if templates are identical. |
| 131 | + * |
| 132 | + * @default false |
| 133 | + */ |
| 134 | + readonly force?: boolean; |
| 135 | + |
| 136 | + /** |
| 137 | + * Deployment method |
| 138 | + */ |
| 139 | + readonly deploymentMethod?: DeploymentMethod; |
| 140 | + |
| 141 | + /** |
| 142 | + * @TODO can this be part of `DeploymentMethod` |
| 143 | + * |
| 144 | + * Whether to perform a 'hotswap' deployment. |
| 145 | + * A 'hotswap' deployment will attempt to short-circuit CloudFormation |
| 146 | + * and update the affected resources like Lambda functions directly. |
| 147 | + * |
| 148 | + * @default - `HotswapMode.FALL_BACK` for regular deployments, `HotswapMode.HOTSWAP_ONLY` for 'watch' deployments |
| 149 | + */ |
| 150 | + readonly hotswap: HotswapMode; |
| 151 | + |
| 152 | + /** |
| 153 | + * Rollback failed deployments |
| 154 | + * |
| 155 | + * @default true |
| 156 | + */ |
| 157 | + readonly rollback?: boolean; |
| 158 | + |
| 159 | + /** |
| 160 | + * Reuse the assets with the given asset IDs |
| 161 | + */ |
| 162 | + readonly reuseAssets?: string[]; |
| 163 | + |
| 164 | + /** |
| 165 | + * Maximum number of simultaneous deployments (dependency permitting) to execute. |
| 166 | + * The default is '1', which executes all deployments serially. |
| 167 | + * |
| 168 | + * @default 1 |
| 169 | + */ |
| 170 | + readonly concurrency?: number; |
| 171 | +} |
| 172 | + |
| 173 | +export interface DeployOptions extends BaseDeployOptions { |
| 174 | + /** |
| 175 | + * ARNs of SNS topics that CloudFormation will notify with stack related events |
| 176 | + */ |
| 177 | + readonly notificationArns?: string[]; |
| 178 | + |
| 179 | + /** |
| 180 | + * What kind of security changes require approval |
| 181 | + * |
| 182 | + * @default RequireApproval.Broadening |
| 183 | + */ |
| 184 | + readonly requireApproval?: RequireApproval; |
| 185 | + |
| 186 | + /** |
| 187 | + * Tags to pass to CloudFormation for deployment |
| 188 | + */ |
| 189 | + readonly tags?: Tag[]; |
| 190 | + |
| 191 | + /** |
| 192 | + * Stack parameters for CloudFormation used at deploy time |
| 193 | + * @default StackParameters.onlyExisting() |
| 194 | + */ |
| 195 | + readonly parameters?: StackParameters; |
| 196 | + |
| 197 | + /** |
| 198 | + * Path to file where stack outputs will be written after a successful deploy as JSON |
| 199 | + * @default - Outputs are not written to any file |
| 200 | + */ |
| 201 | + readonly outputsFile?: string; |
| 202 | + |
| 203 | + /** |
| 204 | + * Whether to show logs from all CloudWatch log groups in the template |
| 205 | + * locally in the users terminal |
| 206 | + * |
| 207 | + * @default - false |
| 208 | + */ |
| 209 | + readonly traceLogs?: boolean; |
| 210 | + |
| 211 | + /** |
| 212 | + * Build/publish assets for a single stack in parallel |
| 213 | + * |
| 214 | + * Independent of whether stacks are being done in parallel or no. |
| 215 | + * |
| 216 | + * @default true |
| 217 | + */ |
| 218 | + readonly assetParallelism?: boolean; |
| 219 | + |
| 220 | + /** |
| 221 | + * When to build assets |
| 222 | + * |
| 223 | + * The default is the Docker-friendly default. |
| 224 | + * |
| 225 | + * @default AssetBuildTime.ALL_BEFORE_DEPLOY |
| 226 | + */ |
| 227 | + readonly assetBuildTime?: AssetBuildTime; |
| 228 | +} |
0 commit comments