@pulumi/command
Version:
[](https://github.com/pulumi/pulumi-command/actions) [](https://slack.pulumi.com) [;
exports.Command = void 0;
const pulumi = require("@pulumi/pulumi");
const utilities = require("../utilities");
/**
* A local command to be executed.
*
* This command can be inserted into the life cycles of other resources using the `dependsOn` or `parent` resource options. A command is considered to have failed when it finished with a non-zero exit code. This will fail the CRUD step of the `Command` resource.
*
* ## Example Usage
*
* ### Basic Example
*
* This example shows the simplest use case, simply running a command on `create` in the Pulumi lifecycle.
*
* ```typescript
* import { local } from "@pulumi/command";
*
* const random = new local.Command("random", {
* create: "openssl rand -hex 16",
* });
*
* export const output = random.stdout;
* ```
*
* ### Invoking a Lambda during Pulumi Deployment
*
* This example show using a local command to invoke an AWS Lambda once it's deployed. The Lambda invocation could also depend on other resources.
*
* ```typescript
* import * as aws from "@pulumi/aws";
* import { local } from "@pulumi/command";
* import { getStack } from "@pulumi/pulumi";
*
* const f = new aws.lambda.CallbackFunction("f", {
* publish: true,
* callback: async (ev: any) => {
* return `Stack ${ev.stackName} is deployed!`;
* }
* });
*
* const invoke = new local.Command("execf", {
* create: `aws lambda invoke --function-name "$FN" --payload '{"stackName": "${getStack()}"}' --cli-binary-format raw-in-base64-out out.txt >/dev/null && cat out.txt | tr -d '"' && rm out.txt`,
* environment: {
* FN: f.qualifiedArn,
* AWS_REGION: aws.config.region!,
* AWS_PAGER: "",
* },
* }, { dependsOn: f })
*
* export const output = invoke.stdout;
* ```
*
* ### Using Triggers
*
* This example defines several trigger values of various kinds. Changes to any of them will cause `cmd` to be re-run.
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as command from "@pulumi/command";
* import * as random from "@pulumi/random";
*
* const str = "foo";
* const fileAsset = new pulumi.asset.FileAsset("Pulumi.yaml");
* const rand = new random.RandomString("rand", {length: 5});
* const localFile = new command.local.Command("localFile", {
* create: "touch foo.txt",
* archivePaths: ["*.txt"],
* });
*
* const cmd = new command.local.Command("cmd", {
* create: "echo create > op.txt",
* delete: "echo delete >> op.txt",
* triggers: [
* str,
* rand.result,
* fileAsset,
* localFile.archive,
* ],
* });
* ```
*/
class Command extends pulumi.CustomResource {
/**
* Get an existing Command resource's state with the given name, ID, and optional extra
* properties used to qualify the lookup.
*
* @param name The _unique_ name of the resulting resource.
* @param id The _unique_ provider ID of the resource to lookup.
* @param opts Optional settings to control the behavior of the CustomResource.
*/
static get(name, id, opts) {
return new Command(name, undefined, Object.assign(Object.assign({}, opts), { id: id }));
}
/**
* Returns true if the given object is an instance of Command. This is designed to work even
* when multiple copies of the Pulumi SDK have been loaded into the same process.
*/
static isInstance(obj) {
if (obj === undefined || obj === null) {
return false;
}
return obj['__pulumiType'] === Command.__pulumiType;
}
/**
* Create a Command resource with the given unique name, arguments, and options.
*
* @param name The _unique_ name of the resource.
* @param args The arguments to use to populate this resource's properties.
* @param opts A bag of options that control this resource's behavior.
*/
constructor(name, args, opts) {
var _a;
let resourceInputs = {};
opts = opts || {};
if (!opts.id) {
resourceInputs["addPreviousOutputInEnv"] = (_a = (args ? args.addPreviousOutputInEnv : undefined)) !== null && _a !== void 0 ? _a : true;
resourceInputs["archivePaths"] = args ? args.archivePaths : undefined;
resourceInputs["assetPaths"] = args ? args.assetPaths : undefined;
resourceInputs["create"] = args ? args.create : undefined;
resourceInputs["delete"] = args ? args.delete : undefined;
resourceInputs["dir"] = args ? args.dir : undefined;
resourceInputs["environment"] = args ? args.environment : undefined;
resourceInputs["interpreter"] = args ? args.interpreter : undefined;
resourceInputs["logging"] = args ? args.logging : undefined;
resourceInputs["stdin"] = args ? args.stdin : undefined;
resourceInputs["triggers"] = args ? args.triggers : undefined;
resourceInputs["update"] = args ? args.update : undefined;
resourceInputs["archive"] = undefined /*out*/;
resourceInputs["assets"] = undefined /*out*/;
resourceInputs["stderr"] = undefined /*out*/;
resourceInputs["stdout"] = undefined /*out*/;
}
else {
resourceInputs["addPreviousOutputInEnv"] = undefined /*out*/;
resourceInputs["archive"] = undefined /*out*/;
resourceInputs["archivePaths"] = undefined /*out*/;
resourceInputs["assetPaths"] = undefined /*out*/;
resourceInputs["assets"] = undefined /*out*/;
resourceInputs["create"] = undefined /*out*/;
resourceInputs["delete"] = undefined /*out*/;
resourceInputs["dir"] = undefined /*out*/;
resourceInputs["environment"] = undefined /*out*/;
resourceInputs["interpreter"] = undefined /*out*/;
resourceInputs["logging"] = undefined /*out*/;
resourceInputs["stderr"] = undefined /*out*/;
resourceInputs["stdin"] = undefined /*out*/;
resourceInputs["stdout"] = undefined /*out*/;
resourceInputs["triggers"] = undefined /*out*/;
resourceInputs["update"] = undefined /*out*/;
}
opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts);
const replaceOnChanges = { replaceOnChanges: ["triggers[*]"] };
opts = pulumi.mergeOptions(opts, replaceOnChanges);
super(Command.__pulumiType, name, resourceInputs, opts);
}
}
exports.Command = Command;
/** @internal */
Command.__pulumiType = 'command:local:Command';
//# sourceMappingURL=command.js.map