|
| 1 | +import { StackSelector } from '../api/cloud-assembly/stack-selector'; |
| 2 | + |
| 3 | +export interface CloudFormationDiffOptions { |
| 4 | + /** |
| 5 | + * Whether to run the diff against the template after the CloudFormation Transforms inside it have been executed |
| 6 | + * (as opposed to the original template, the default, which contains the unprocessed Transforms). |
| 7 | + * |
| 8 | + * @default false |
| 9 | + */ |
| 10 | + readonly compareAgainstProcessedTemplate?: boolean; |
| 11 | +} |
| 12 | + |
| 13 | +export interface ChangeSetDiffOptions extends CloudFormationDiffOptions { |
| 14 | + /** |
| 15 | + * Enable falling back to template-based diff in case creating the changeset is not possible or results in an error. |
| 16 | + * |
| 17 | + * Should be used for stacks containing nested stacks or when change set permissions aren't available. |
| 18 | + * |
| 19 | + * @default true |
| 20 | + */ |
| 21 | + readonly fallbackToTemplate?: boolean; |
| 22 | + |
| 23 | + /** |
| 24 | + * Additional parameters for CloudFormation when creating a diff change set |
| 25 | + * |
| 26 | + * @default {} |
| 27 | + */ |
| 28 | + readonly parameters?: { [name: string]: string | undefined }; |
| 29 | +} |
| 30 | + |
| 31 | +export class DiffMethod { |
| 32 | + /** |
| 33 | + * Use a changeset to compute the diff. |
| 34 | + * |
| 35 | + * This will create, analyze, and subsequently delete a changeset against the CloudFormation stack. |
| 36 | + */ |
| 37 | + public static ChangeSet(options: ChangeSetDiffOptions = {}) { |
| 38 | + return new class extends DiffMethod { |
| 39 | + public override readonly options: ChangeSetDiffOptions; |
| 40 | + public constructor(opts: ChangeSetDiffOptions) { |
| 41 | + super('change-set', opts); |
| 42 | + this.options = opts; |
| 43 | + } |
| 44 | + }(options); |
| 45 | + } |
| 46 | + |
| 47 | + public static TemplateOnly(options: CloudFormationDiffOptions = {}) { |
| 48 | + return new class extends DiffMethod { |
| 49 | + public override readonly options: CloudFormationDiffOptions; |
| 50 | + public constructor(opts: CloudFormationDiffOptions) { |
| 51 | + super('template-only', opts); |
| 52 | + this.options = opts; |
| 53 | + } |
| 54 | + }(options); |
| 55 | + } |
| 56 | + |
| 57 | + public static LocalFile(path: string) { |
| 58 | + return new class extends DiffMethod { |
| 59 | + public override readonly options: { path: string }; |
| 60 | + public constructor(opts: { path: string }) { |
| 61 | + super('local-file', opts); |
| 62 | + this.options = opts; |
| 63 | + } |
| 64 | + }({ path }); |
| 65 | + }; |
| 66 | + |
| 67 | + private constructor( |
| 68 | + public readonly method: 'change-set' | 'template-only' | 'local-file', |
| 69 | + public readonly options: ChangeSetDiffOptions | CloudFormationDiffOptions | { path: string }, |
| 70 | + ) {} |
| 71 | +} |
| 72 | + |
| 73 | +export interface DiffOptions { |
| 74 | + /** |
| 75 | + * Select the stacks |
| 76 | + */ |
| 77 | + readonly stacks: StackSelector; |
| 78 | + |
| 79 | + /** |
| 80 | + * The mode to create a stack diff. |
| 81 | + * |
| 82 | + * Use changeset diff for the highest fidelity, including analyze resource replacements. |
| 83 | + * In this mode, diff will use the deploy role instead of the lookup role. |
| 84 | + * |
| 85 | + * Use template-only diff for a faster, less accurate diff that doesn't require |
| 86 | + * permissions to create a change-set. |
| 87 | + * |
| 88 | + * Use local-template diff for a fast, local-only diff that doesn't require |
| 89 | + * any permissions or internet access. |
| 90 | + * |
| 91 | + * @default DiffMode.ChangeSet |
| 92 | + */ |
| 93 | + readonly method: DiffMethod; |
| 94 | + |
| 95 | + /** |
| 96 | + * Strict diff mode |
| 97 | + * When enabled, this will not filter out AWS::CDK::Metadata resources, mangled non-ASCII characters, or the CheckBootstrapVersionRule. |
| 98 | + * |
| 99 | + * @default false |
| 100 | + */ |
| 101 | + readonly strict?: boolean; |
| 102 | + |
| 103 | + /** |
| 104 | + * How many lines of context to show in the diff |
| 105 | + * |
| 106 | + * @default 3 |
| 107 | + */ |
| 108 | + readonly contextLines?: number; |
| 109 | + |
| 110 | + /** |
| 111 | + * Only include broadened security changes in the diff |
| 112 | + * |
| 113 | + * @default false |
| 114 | + */ |
| 115 | + readonly securityOnly?: boolean; |
| 116 | +} |
0 commit comments