UNPKG

9.2 kBTypeScriptView Raw
1import * as cxapi from '@aws-cdk/cx-api';
2import { type DescribeChangeSetCommandOutput, type Parameter, type ResourceIdentifierSummary, type ResourceToImport, type Stack, type Tag } from '@aws-sdk/client-cloudformation';
3import type { ICloudFormationClient, SdkProvider } from '../aws-auth';
4import type { Deployments } from './deployments';
5import { StackStatus } from '../util/cloudformation/stack-status';
6import { TemplateBodyParameter } from '../util/template-body-parameter';
7export type ResourcesToImport = ResourceToImport[];
8export type ResourceIdentifierSummaries = ResourceIdentifierSummary[];
9export type ResourceIdentifierProperties = Record<string, string>;
10export type Template = {
11 Parameters?: Record<string, TemplateParameter>;
12 [key: string]: any;
13};
14interface TemplateParameter {
15 Type: string;
16 Default?: any;
17 Description?: string;
18 [key: string]: any;
19}
20/**
21 * Represents an (existing) Stack in CloudFormation
22 *
23 * Bundle and cache some information that we need during deployment (so we don't have to make
24 * repeated calls to CloudFormation).
25 */
26export declare class CloudFormationStack {
27 private readonly cfn;
28 readonly stackName: string;
29 private readonly stack?;
30 private readonly retrieveProcessedTemplate;
31 static lookup(cfn: ICloudFormationClient, stackName: string, retrieveProcessedTemplate?: boolean): Promise<CloudFormationStack>;
32 /**
33 * Return a copy of the given stack that does not exist
34 *
35 * It's a little silly that it needs arguments to do that, but there we go.
36 */
37 static doesNotExist(cfn: ICloudFormationClient, stackName: string): CloudFormationStack;
38 /**
39 * From static information (for testing)
40 */
41 static fromStaticInformation(cfn: ICloudFormationClient, stackName: string, stack: Stack): CloudFormationStack;
42 private _template;
43 protected constructor(cfn: ICloudFormationClient, stackName: string, stack?: Stack | undefined, retrieveProcessedTemplate?: boolean);
44 /**
45 * Retrieve the stack's deployed template
46 *
47 * Cached, so will only be retrieved once. Will return an empty
48 * structure if the stack does not exist.
49 */
50 template(): Promise<Template>;
51 /**
52 * Whether the stack exists
53 */
54 get exists(): boolean;
55 /**
56 * The stack's ID
57 *
58 * Throws if the stack doesn't exist.
59 */
60 get stackId(): string;
61 /**
62 * The stack's current outputs
63 *
64 * Empty object if the stack doesn't exist
65 */
66 get outputs(): Record<string, string>;
67 /**
68 * The stack's status
69 *
70 * Special status NOT_FOUND if the stack does not exist.
71 */
72 get stackStatus(): StackStatus;
73 /**
74 * The stack's current tags
75 *
76 * Empty list if the stack does not exist
77 */
78 get tags(): Tag[];
79 /**
80 * SNS Topic ARNs that will receive stack events.
81 *
82 * Empty list if the stack does not exist
83 */
84 get notificationArns(): string[];
85 /**
86 * Return the names of all current parameters to the stack
87 *
88 * Empty list if the stack does not exist.
89 */
90 get parameterNames(): string[];
91 /**
92 * Return the names and values of all current parameters to the stack
93 *
94 * Empty object if the stack does not exist.
95 */
96 get parameters(): Record<string, string>;
97 /**
98 * Return the termination protection of the stack
99 */
100 get terminationProtection(): boolean | undefined;
101 private assertExists;
102}
103/**
104 * Waits for a ChangeSet to be available for triggering a StackUpdate.
105 *
106 * Will return a changeset that is either ready to be executed or has no changes.
107 * Will throw in other cases.
108 *
109 * @param cfn a CloudFormation client
110 * @param stackName the name of the Stack that the ChangeSet belongs to
111 * @param changeSetName the name of the ChangeSet
112 * @param fetchAll if true, fetches all pages of the ChangeSet before returning.
113 *
114 * @returns the CloudFormation description of the ChangeSet
115 */
116export declare function waitForChangeSet(cfn: ICloudFormationClient, stackName: string, changeSetName: string, { fetchAll }: {
117 fetchAll: boolean;
118}): Promise<DescribeChangeSetCommandOutput>;
119export type PrepareChangeSetOptions = {
120 stack: cxapi.CloudFormationStackArtifact;
121 deployments: Deployments;
122 uuid: string;
123 willExecute: boolean;
124 sdkProvider: SdkProvider;
125 stream: NodeJS.WritableStream;
126 parameters: {
127 [name: string]: string | undefined;
128 };
129 resourcesToImport?: ResourcesToImport;
130};
131export type CreateChangeSetOptions = {
132 cfn: ICloudFormationClient;
133 changeSetName: string;
134 willExecute: boolean;
135 exists: boolean;
136 uuid: string;
137 stack: cxapi.CloudFormationStackArtifact;
138 bodyParameter: TemplateBodyParameter;
139 parameters: {
140 [name: string]: string | undefined;
141 };
142 resourcesToImport?: ResourceToImport[];
143 role?: string;
144};
145/**
146 * Create a changeset for a diff operation
147 */
148export declare function createDiffChangeSet(options: PrepareChangeSetOptions): Promise<DescribeChangeSetCommandOutput | undefined>;
149/**
150 * Uploads the assets that look like templates for this CloudFormation stack
151 *
152 * This is necessary for any CloudFormation call that needs the template, it may need
153 * to be uploaded to an S3 bucket first. We have to follow the instructions in the
154 * asset manifest, because technically that is the only place that knows about
155 * bucket and assumed roles and such.
156 */
157export declare function uploadStackTemplateAssets(stack: cxapi.CloudFormationStackArtifact, deployments: Deployments): Promise<void>;
158export declare function cleanupOldChangeset(changeSetName: string, stackName: string, cfn: ICloudFormationClient): Promise<void>;
159/**
160 * Return true if the given change set has no changes
161 *
162 * This must be determined from the status, not the 'Changes' array on the
163 * object; the latter can be empty because no resources were changed, but if
164 * there are changes to Outputs, the change set can still be executed.
165 */
166export declare function changeSetHasNoChanges(description: DescribeChangeSetCommandOutput): boolean;
167/**
168 * Waits for a CloudFormation stack to stabilize in a complete/available state
169 * after a delete operation is issued.
170 *
171 * Fails if the stack is in a FAILED state. Will not fail if the stack was
172 * already deleted.
173 *
174 * @param cfn a CloudFormation client
175 * @param stackName the name of the stack to wait for after a delete
176 *
177 * @returns the CloudFormation description of the stabilized stack after the delete attempt
178 */
179export declare function waitForStackDelete(cfn: ICloudFormationClient, stackName: string): Promise<CloudFormationStack | undefined>;
180/**
181 * Waits for a CloudFormation stack to stabilize in a complete/available state
182 * after an update/create operation is issued.
183 *
184 * Fails if the stack is in a FAILED state, ROLLBACK state, or DELETED state.
185 *
186 * @param cfn a CloudFormation client
187 * @param stackName the name of the stack to wait for after an update
188 *
189 * @returns the CloudFormation description of the stabilized stack after the update attempt
190 */
191export declare function waitForStackDeploy(cfn: ICloudFormationClient, stackName: string): Promise<CloudFormationStack | undefined>;
192/**
193 * Wait for a stack to become stable (no longer _IN_PROGRESS), returning it
194 */
195export declare function stabilizeStack(cfn: ICloudFormationClient, stackName: string): Promise<CloudFormationStack | undefined>;
196/**
197 * The set of (formal) parameters that have been declared in a template
198 */
199export declare class TemplateParameters {
200 private readonly params;
201 static fromTemplate(template: Template): TemplateParameters;
202 constructor(params: Record<string, TemplateParameter>);
203 /**
204 * Calculate stack parameters to pass from the given desired parameter values
205 *
206 * Will throw if parameters without a Default value or a Previous value are not
207 * supplied.
208 */
209 supplyAll(updates: Record<string, string | undefined>): ParameterValues;
210 /**
211 * From the template, the given desired values and the current values, calculate the changes to the stack parameters
212 *
213 * Will take into account parameters already set on the template (will emit
214 * 'UsePreviousValue: true' for those unless the value is changed), and will
215 * throw if parameters without a Default value or a Previous value are not
216 * supplied.
217 */
218 updateExisting(updates: Record<string, string | undefined>, previousValues: Record<string, string>): ParameterValues;
219}
220/**
221 * The set of parameters we're going to pass to a Stack
222 */
223export declare class ParameterValues {
224 private readonly formalParams;
225 readonly values: Record<string, string>;
226 readonly apiParameters: Parameter[];
227 constructor(formalParams: Record<string, TemplateParameter>, updates: Record<string, string | undefined>, previousValues?: Record<string, string>);
228 /**
229 * Whether this set of parameter updates will change the actual stack values
230 */
231 hasChanges(currentValues: Record<string, string>): ParameterChanges;
232}
233export type ParameterChanges = boolean | 'ssm';
234export {};