UNPKG

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