2022-10-19 23:35:46 +00:00
|
|
|
|
// Copyright 2016-2022, Pulumi Corporation.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
|
|
import { EngineEvent } from "./events";
|
|
|
|
|
import { LocalWorkspace } from "./localWorkspace";
|
2023-04-28 22:27:10 +00:00
|
|
|
|
import { DestroyResult, OutputMap, PreviewResult, RefreshResult, Stack, UpdateSummary, UpResult } from "./stack";
|
2022-10-19 23:35:46 +00:00
|
|
|
|
import { Deployment } from "./workspace";
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-10 17:22:24 +00:00
|
|
|
|
* {@link RemoteStack} is an isolated, independently configurable instance of a
|
|
|
|
|
* Pulumi program that is operated on remotely.
|
2022-10-19 23:35:46 +00:00
|
|
|
|
*/
|
|
|
|
|
export class RemoteStack {
|
2024-07-10 17:22:24 +00:00
|
|
|
|
/**
|
|
|
|
|
* @internal
|
|
|
|
|
*/
|
2022-10-19 23:35:46 +00:00
|
|
|
|
static create(stack: Stack): RemoteStack {
|
|
|
|
|
return new RemoteStack(stack);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private constructor(private readonly stack: Stack) {
|
|
|
|
|
const ws = stack.workspace;
|
|
|
|
|
if (!(ws instanceof LocalWorkspace)) {
|
|
|
|
|
throw new Error("expected workspace to be an instance of LocalWorkspace");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The name identifying the Stack.
|
|
|
|
|
*/
|
|
|
|
|
get name(): string {
|
|
|
|
|
return this.stack.name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-10 17:22:24 +00:00
|
|
|
|
* Creates or updates the resources in a stack by executing the program in
|
|
|
|
|
* the Workspace. This operation runs remotely.
|
2022-10-19 23:35:46 +00:00
|
|
|
|
*
|
2024-07-10 17:22:24 +00:00
|
|
|
|
* @param opts
|
|
|
|
|
* Options to customize the behavior of the update.
|
|
|
|
|
*
|
|
|
|
|
* @see https://www.pulumi.com/docs/cli/commands/pulumi_up/
|
2022-10-19 23:35:46 +00:00
|
|
|
|
*/
|
|
|
|
|
up(opts?: RemoteUpOptions): Promise<UpResult> {
|
|
|
|
|
return this.stack.up(opts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-10 17:22:24 +00:00
|
|
|
|
* Performs a dry-run update to a stack, returning pending changes. This
|
|
|
|
|
* operation runs remotely.
|
|
|
|
|
*
|
|
|
|
|
* @param opts
|
|
|
|
|
* Options to customize the behavior of the preview.
|
2022-10-19 23:35:46 +00:00
|
|
|
|
*
|
2024-07-10 17:22:24 +00:00
|
|
|
|
* @see https://www.pulumi.com/docs/cli/commands/pulumi_preview/
|
2022-10-19 23:35:46 +00:00
|
|
|
|
*/
|
|
|
|
|
preview(opts?: RemotePreviewOptions): Promise<PreviewResult> {
|
|
|
|
|
return this.stack.preview(opts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-10 17:22:24 +00:00
|
|
|
|
* Compares the current stack’s resource state with the state known to exist
|
|
|
|
|
* in the actual cloud provider. Any such changes are adopted into the
|
|
|
|
|
* current stack. This operation runs remotely.
|
2022-10-19 23:35:46 +00:00
|
|
|
|
*
|
2024-07-10 17:22:24 +00:00
|
|
|
|
* @param opts
|
|
|
|
|
* Options to customize the behavior of the refresh.
|
2022-10-19 23:35:46 +00:00
|
|
|
|
*/
|
|
|
|
|
refresh(opts?: RemoteRefreshOptions): Promise<RefreshResult> {
|
|
|
|
|
return this.stack.refresh(opts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-10 17:22:24 +00:00
|
|
|
|
* Deletes all resources in a stack, leaving all history and configuration
|
|
|
|
|
* intact. This operation runs remotely.
|
2022-10-19 23:35:46 +00:00
|
|
|
|
*
|
2024-07-10 17:22:24 +00:00
|
|
|
|
* @param opts
|
|
|
|
|
* Options to customize the behavior of the destroy.
|
2022-10-19 23:35:46 +00:00
|
|
|
|
*/
|
|
|
|
|
destroy(opts?: RemoteDestroyOptions): Promise<DestroyResult> {
|
|
|
|
|
return this.stack.destroy(opts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-10 17:22:24 +00:00
|
|
|
|
* Gets the current set of stack outputs from the last {@link Stack.up}.
|
2022-10-19 23:35:46 +00:00
|
|
|
|
*/
|
|
|
|
|
outputs(): Promise<OutputMap> {
|
|
|
|
|
return this.stack.outputs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-10 17:22:24 +00:00
|
|
|
|
* Returns a list summarizing all previous and current results from Stack
|
|
|
|
|
* lifecycle operations (up/preview/refresh/destroy).
|
2022-10-19 23:35:46 +00:00
|
|
|
|
*/
|
|
|
|
|
history(pageSize?: number, page?: number): Promise<UpdateSummary[]> {
|
|
|
|
|
// TODO: Find a way to allow showSecrets as an option that doesn't require loading the project.
|
|
|
|
|
return this.stack.history(pageSize, page, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-10 17:22:24 +00:00
|
|
|
|
* Stops a stack's currently running update. It returns an error if no
|
|
|
|
|
* update is currently running. Note that this operation is _very
|
|
|
|
|
* dangerous_, and may leave the stack in an inconsistent state if a
|
|
|
|
|
* resource operation was pending when the update was canceled. This command
|
|
|
|
|
* is not supported for DIY backends.
|
2022-10-19 23:35:46 +00:00
|
|
|
|
*/
|
|
|
|
|
cancel(): Promise<void> {
|
|
|
|
|
return this.stack.cancel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-10 17:22:24 +00:00
|
|
|
|
* Exports the deployment state of the stack. This can be combined with
|
|
|
|
|
* {@link Stack.importStack} to edit a stack's state (such as recovery from
|
|
|
|
|
* failed deployments).
|
2022-10-19 23:35:46 +00:00
|
|
|
|
*/
|
|
|
|
|
exportStack(): Promise<Deployment> {
|
|
|
|
|
return this.stack.exportStack();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-10 17:22:24 +00:00
|
|
|
|
* Imports the specified deployment state into a pre-existing stack. This
|
|
|
|
|
* can be combined with {@link Stack.exportStack} to edit a stack's state
|
|
|
|
|
* (such as recovery from failed deployments).
|
2022-10-19 23:35:46 +00:00
|
|
|
|
*
|
2024-07-10 17:22:24 +00:00
|
|
|
|
* @param state
|
|
|
|
|
* The stack state to import.
|
2022-10-19 23:35:46 +00:00
|
|
|
|
*/
|
|
|
|
|
importStack(state: Deployment): Promise<void> {
|
|
|
|
|
return this.stack.importStack(state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-10 17:22:24 +00:00
|
|
|
|
* Options controlling the behavior of a {@link RemoteStack.up} operation.
|
2022-10-19 23:35:46 +00:00
|
|
|
|
*/
|
|
|
|
|
export interface RemoteUpOptions {
|
|
|
|
|
onOutput?: (out: string) => void;
|
|
|
|
|
onEvent?: (event: EngineEvent) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-10 17:22:24 +00:00
|
|
|
|
* Options controlling the behavior of a {@link RemoteStack.preview} operation.
|
2022-10-19 23:35:46 +00:00
|
|
|
|
*/
|
|
|
|
|
export interface RemotePreviewOptions {
|
|
|
|
|
onOutput?: (out: string) => void;
|
|
|
|
|
onEvent?: (event: EngineEvent) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-10 17:22:24 +00:00
|
|
|
|
* Options controlling the behavior of a {@link RemoteStack.refresh} operation.
|
2022-10-19 23:35:46 +00:00
|
|
|
|
*/
|
|
|
|
|
export interface RemoteRefreshOptions {
|
|
|
|
|
onOutput?: (out: string) => void;
|
|
|
|
|
onEvent?: (event: EngineEvent) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-10 17:22:24 +00:00
|
|
|
|
* Options controlling the behavior of a {@link RemoteStack.destroy} operation.
|
2022-10-19 23:35:46 +00:00
|
|
|
|
*/
|
|
|
|
|
export interface RemoteDestroyOptions {
|
|
|
|
|
onOutput?: (out: string) => void;
|
|
|
|
|
onEvent?: (event: EngineEvent) => void;
|
|
|
|
|
}
|