UNPKG

@pulumi/command

Version:

[![Actions Status](https://github.com/pulumi/pulumi-command/workflows/master/badge.svg)](https://github.com/pulumi/pulumi-command/actions) [![Slack](http://www.pulumi.com/images/docs/badges/slack.svg)](https://slack.pulumi.com) [![NPM version](https://bad

433 lines (432 loc) 16.2 kB
import * as pulumi from "@pulumi/pulumi"; import * as enums from "../types/enums"; /** * 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, * ], * }); * ``` */ export declare 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: string, id: pulumi.Input<pulumi.ID>, opts?: pulumi.CustomResourceOptions): Command; /** * 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: any): obj is Command; /** * If the previous command's stdout and stderr (as generated by the prior create/update) is * injected into the environment of the next run as PULUMI_COMMAND_STDOUT and PULUMI_COMMAND_STDERR. * Defaults to true. */ readonly addPreviousOutputInEnv: pulumi.Output<boolean | undefined>; /** * An archive asset containing files found after running the command. */ readonly archive: pulumi.Output<pulumi.asset.Archive | undefined>; /** * A list of path globs to return as a single archive asset after the command completes. * * When specifying glob patterns the following rules apply: * - We only include files not directories for assets and archives. * - Path separators are `/` on all platforms - including Windows. * - Patterns starting with `!` are 'exclude' rules. * - Rules are evaluated in order, so exclude rules should be after inclusion rules. * - `*` matches anything except `/` * - `**` matches anything, _including_ `/` * - All returned paths are relative to the working directory (without leading `./`) e.g. `file.text` or `subfolder/file.txt`. * - For full details of the globbing syntax, see [github.com/gobwas/glob](https://github.com/gobwas/glob) * * #### Example * * Given the rules: * ```yaml * - "assets/**" * - "src/**.js" * - "!**secret.*" * ``` * * When evaluating against this folder: * * ```yaml * - assets/ * - logos/ * - logo.svg * - src/ * - index.js * - secret.js * ``` * * The following paths will be returned: * * ```yaml * - assets/logos/logo.svg * - src/index.js * ``` */ readonly archivePaths: pulumi.Output<string[] | undefined>; /** * A list of path globs to read after the command completes. * * When specifying glob patterns the following rules apply: * - We only include files not directories for assets and archives. * - Path separators are `/` on all platforms - including Windows. * - Patterns starting with `!` are 'exclude' rules. * - Rules are evaluated in order, so exclude rules should be after inclusion rules. * - `*` matches anything except `/` * - `**` matches anything, _including_ `/` * - All returned paths are relative to the working directory (without leading `./`) e.g. `file.text` or `subfolder/file.txt`. * - For full details of the globbing syntax, see [github.com/gobwas/glob](https://github.com/gobwas/glob) * * #### Example * * Given the rules: * ```yaml * - "assets/**" * - "src/**.js" * - "!**secret.*" * ``` * * When evaluating against this folder: * * ```yaml * - assets/ * - logos/ * - logo.svg * - src/ * - index.js * - secret.js * ``` * * The following paths will be returned: * * ```yaml * - assets/logos/logo.svg * - src/index.js * ``` */ readonly assetPaths: pulumi.Output<string[] | undefined>; /** * A map of assets found after running the command. * The key is the relative path from the command dir */ readonly assets: pulumi.Output<{ [key: string]: pulumi.asset.Asset | pulumi.asset.Archive; } | undefined>; /** * The command to run once on resource creation. * * If an `update` command isn't provided, then `create` will also be run when the resource's inputs are modified. * * Note that this command will not be executed if the resource has already been created and its inputs are unchanged. * * Use `local.runOutput` if you need to run a command on every execution of your program. */ readonly create: pulumi.Output<string | undefined>; /** * The command to run on resource delettion. * * The environment variables `PULUMI_COMMAND_STDOUT` and `PULUMI_COMMAND_STDERR` are set to the stdout and stderr properties of the Command resource from previous create or update steps. */ readonly delete: pulumi.Output<string | undefined>; /** * The directory from which to run the command from. If `dir` does not exist, then * `Command` will fail. */ readonly dir: pulumi.Output<string | undefined>; /** * Additional environment variables available to the command's process. */ readonly environment: pulumi.Output<{ [key: string]: string; } | undefined>; /** * The program and arguments to run the command. * On Linux and macOS, defaults to: `["/bin/sh", "-c"]`. On Windows, defaults to: `["cmd", "/C"]` */ readonly interpreter: pulumi.Output<string[] | undefined>; /** * If the command's stdout and stderr should be logged. This doesn't affect the capturing of * stdout and stderr as outputs. If there might be secrets in the output, you can disable logging here and mark the * outputs as secret via 'additionalSecretOutputs'. Defaults to logging both stdout and stderr. */ readonly logging: pulumi.Output<enums.local.Logging | undefined>; /** * The standard error of the command's process */ readonly stderr: pulumi.Output<string>; /** * Pass a string to the command's process as standard in */ readonly stdin: pulumi.Output<string | undefined>; /** * The standard output of the command's process */ readonly stdout: pulumi.Output<string>; /** * The resource will be updated (or replaced) if any of these values change. * * The trigger values can be of any type. * * If the `update` command was provided the resource will be updated, otherwise it will be replaced using the `create` command. * * Please see the resource documentation for examples. */ readonly triggers: pulumi.Output<any[] | undefined>; /** * The command to run when the resource is updated. * * If empty, the create command will be executed instead. * * Note that this command will not run if the resource's inputs are unchanged. * * Use `local.runOutput` if you need to run a command on every execution of your program. * * The environment variables `PULUMI_COMMAND_STDOUT` and `PULUMI_COMMAND_STDERR` are set to the `stdout` and `stderr` properties of the Command resource from previous create or update steps. */ readonly update: pulumi.Output<string | undefined>; /** * 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: string, args?: CommandArgs, opts?: pulumi.CustomResourceOptions); } /** * The set of arguments for constructing a Command resource. */ export interface CommandArgs { /** * If the previous command's stdout and stderr (as generated by the prior create/update) is * injected into the environment of the next run as PULUMI_COMMAND_STDOUT and PULUMI_COMMAND_STDERR. * Defaults to true. */ addPreviousOutputInEnv?: pulumi.Input<boolean>; /** * A list of path globs to return as a single archive asset after the command completes. * * When specifying glob patterns the following rules apply: * - We only include files not directories for assets and archives. * - Path separators are `/` on all platforms - including Windows. * - Patterns starting with `!` are 'exclude' rules. * - Rules are evaluated in order, so exclude rules should be after inclusion rules. * - `*` matches anything except `/` * - `**` matches anything, _including_ `/` * - All returned paths are relative to the working directory (without leading `./`) e.g. `file.text` or `subfolder/file.txt`. * - For full details of the globbing syntax, see [github.com/gobwas/glob](https://github.com/gobwas/glob) * * #### Example * * Given the rules: * ```yaml * - "assets/**" * - "src/**.js" * - "!**secret.*" * ``` * * When evaluating against this folder: * * ```yaml * - assets/ * - logos/ * - logo.svg * - src/ * - index.js * - secret.js * ``` * * The following paths will be returned: * * ```yaml * - assets/logos/logo.svg * - src/index.js * ``` */ archivePaths?: pulumi.Input<pulumi.Input<string>[]>; /** * A list of path globs to read after the command completes. * * When specifying glob patterns the following rules apply: * - We only include files not directories for assets and archives. * - Path separators are `/` on all platforms - including Windows. * - Patterns starting with `!` are 'exclude' rules. * - Rules are evaluated in order, so exclude rules should be after inclusion rules. * - `*` matches anything except `/` * - `**` matches anything, _including_ `/` * - All returned paths are relative to the working directory (without leading `./`) e.g. `file.text` or `subfolder/file.txt`. * - For full details of the globbing syntax, see [github.com/gobwas/glob](https://github.com/gobwas/glob) * * #### Example * * Given the rules: * ```yaml * - "assets/**" * - "src/**.js" * - "!**secret.*" * ``` * * When evaluating against this folder: * * ```yaml * - assets/ * - logos/ * - logo.svg * - src/ * - index.js * - secret.js * ``` * * The following paths will be returned: * * ```yaml * - assets/logos/logo.svg * - src/index.js * ``` */ assetPaths?: pulumi.Input<pulumi.Input<string>[]>; /** * The command to run once on resource creation. * * If an `update` command isn't provided, then `create` will also be run when the resource's inputs are modified. * * Note that this command will not be executed if the resource has already been created and its inputs are unchanged. * * Use `local.runOutput` if you need to run a command on every execution of your program. */ create?: pulumi.Input<string>; /** * The command to run on resource delettion. * * The environment variables `PULUMI_COMMAND_STDOUT` and `PULUMI_COMMAND_STDERR` are set to the stdout and stderr properties of the Command resource from previous create or update steps. */ delete?: pulumi.Input<string>; /** * The directory from which to run the command from. If `dir` does not exist, then * `Command` will fail. */ dir?: pulumi.Input<string>; /** * Additional environment variables available to the command's process. */ environment?: pulumi.Input<{ [key: string]: pulumi.Input<string>; }>; /** * The program and arguments to run the command. * On Linux and macOS, defaults to: `["/bin/sh", "-c"]`. On Windows, defaults to: `["cmd", "/C"]` */ interpreter?: pulumi.Input<pulumi.Input<string>[]>; /** * If the command's stdout and stderr should be logged. This doesn't affect the capturing of * stdout and stderr as outputs. If there might be secrets in the output, you can disable logging here and mark the * outputs as secret via 'additionalSecretOutputs'. Defaults to logging both stdout and stderr. */ logging?: pulumi.Input<enums.local.Logging>; /** * Pass a string to the command's process as standard in */ stdin?: pulumi.Input<string>; /** * The resource will be updated (or replaced) if any of these values change. * * The trigger values can be of any type. * * If the `update` command was provided the resource will be updated, otherwise it will be replaced using the `create` command. * * Please see the resource documentation for examples. */ triggers?: pulumi.Input<any[]>; /** * The command to run when the resource is updated. * * If empty, the create command will be executed instead. * * Note that this command will not run if the resource's inputs are unchanged. * * Use `local.runOutput` if you need to run a command on every execution of your program. * * The environment variables `PULUMI_COMMAND_STDOUT` and `PULUMI_COMMAND_STDERR` are set to the `stdout` and `stderr` properties of the Command resource from previous create or update steps. */ update?: pulumi.Input<string>; }