@pulumi/command 0.0.4-alpha.1646714993 → 0.1.0-alpha.1779516124

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +101 -16
  2. package/index.d.ts +4 -1
  3. package/index.d.ts.map +1 -0
  4. package/index.js +21 -13
  5. package/index.js.map +1 -1
  6. package/local/command.d.ts +346 -18
  7. package/local/command.d.ts.map +1 -0
  8. package/local/command.js +148 -40
  9. package/local/command.js.map +1 -1
  10. package/local/index.d.ts +8 -1
  11. package/local/index.d.ts.map +1 -0
  12. package/local/index.js +24 -8
  13. package/local/index.js.map +1 -1
  14. package/local/run.d.ts +392 -0
  15. package/local/run.d.ts.map +1 -0
  16. package/local/run.js +69 -0
  17. package/local/run.js.map +1 -0
  18. package/package.json +8 -5
  19. package/package.json.dev +7 -4
  20. package/provider.d.ts +1 -0
  21. package/provider.d.ts.map +1 -0
  22. package/provider.js +39 -18
  23. package/provider.js.map +1 -1
  24. package/remote/command.d.ts +156 -16
  25. package/remote/command.d.ts.map +1 -0
  26. package/remote/command.js +125 -39
  27. package/remote/command.js.map +1 -1
  28. package/remote/copyFile.d.ts +7 -2
  29. package/remote/copyFile.d.ts.map +1 -0
  30. package/remote/copyFile.js +65 -37
  31. package/remote/copyFile.js.map +1 -1
  32. package/remote/copyToRemote.d.ts +126 -0
  33. package/remote/copyToRemote.d.ts.map +1 -0
  34. package/remote/copyToRemote.js +157 -0
  35. package/remote/copyToRemote.js.map +1 -0
  36. package/remote/index.d.ts +11 -2
  37. package/remote/index.d.ts.map +1 -0
  38. package/remote/index.js +28 -11
  39. package/remote/index.js.map +1 -1
  40. package/types/enums/index.d.ts +4 -0
  41. package/types/enums/index.d.ts.map +1 -0
  42. package/types/enums/index.js +34 -0
  43. package/types/enums/index.js.map +1 -0
  44. package/types/enums/local/index.d.ts +20 -0
  45. package/types/enums/local/index.d.ts.map +1 -0
  46. package/types/enums/local/index.js +24 -0
  47. package/types/enums/local/index.js.map +1 -0
  48. package/types/enums/remote/index.d.ts +20 -0
  49. package/types/enums/remote/index.d.ts.map +1 -0
  50. package/types/enums/remote/index.js +24 -0
  51. package/types/enums/remote/index.js.map +1 -0
  52. package/types/index.d.ts +3 -1
  53. package/types/index.d.ts.map +1 -0
  54. package/types/index.js +29 -4
  55. package/types/index.js.map +1 -1
  56. package/types/input.d.ts +80 -5
  57. package/types/input.d.ts.map +1 -0
  58. package/types/input.js +47 -3
  59. package/types/input.js.map +1 -1
  60. package/types/output.d.ts +76 -1
  61. package/types/output.d.ts.map +1 -0
  62. package/types/output.js +46 -3
  63. package/types/output.js.map +1 -1
  64. package/utilities.d.ts +1 -0
  65. package/utilities.d.ts.map +1 -0
  66. package/utilities.js +64 -2
  67. package/utilities.js.map +1 -1
  68. package/package.json.bak +0 -25
package/README.md CHANGED
@@ -1,4 +1,12 @@
1
- # Pulumi Command Provider (preview)
1
+ [![Actions Status](https://github.com/pulumi/pulumi-command/workflows/master/badge.svg)](https://github.com/pulumi/pulumi-command/actions)
2
+ [![Slack](http://www.pulumi.com/images/docs/badges/slack.svg)](https://slack.pulumi.com)
3
+ [![NPM version](https://badge.fury.io/js/%40pulumi%2Fcommand.svg)](https://www.npmjs.com/package/@pulumi/command)
4
+ [![Python version](https://badge.fury.io/py/pulumi-command.svg)](https://pypi.org/project/pulumi-command)
5
+ [![NuGet version](https://badge.fury.io/nu/pulumi.command.svg)](https://badge.fury.io/nu/pulumi.command)
6
+ [![PkgGoDev](https://pkg.go.dev/badge/github.com/pulumi/pulumi-command/sdk/go)](https://pkg.go.dev/github.com/pulumi/pulumi-command/sdk/go)
7
+ [![License](https://img.shields.io/npm/l/%40pulumi%2Fpulumi.svg)](https://github.com/pulumi/pulumi-command/blob/master/LICENSE)
8
+
9
+ # Pulumi Command Provider
2
10
 
3
11
  The Pulumi Command Provider enables you to execute commands and scripts either locally or remotely as part of the Pulumi resource model. Resources in the command package support running scripts on `create` and `destroy` operations, supporting stateful local and remote command execution.
4
12
 
@@ -12,12 +20,10 @@ There are many scenarios where the Command package can be useful:
12
20
 
13
21
  Some users may have experience with Terraform "provisioners", and the Command package offers support for similar scenarios. However, the Command package is provided as independent resources which can be combined with other resources in many interesting ways. This has many strengths, but also some differences, such as the fact that a Command resource failing does not cause a resource it is operating on to fail.
14
22
 
15
- You can use the Command package from a Pulumi program written in any Pulumi language: C#, Go, JavaScript/TypeScript, and Python.
23
+ You can use the Command package from a Pulumi program written in any Pulumi language: C#, Go, JavaScript/TypeScript, Python, and YAML.
16
24
  You'll need to [install and configure the Pulumi CLI](https://pulumi.com/docs/get-started/install) if you haven't already.
17
25
 
18
26
 
19
- > **NOTE**: The Command package is in preview. The API design may change ahead of general availability based on [user feedback](https://github.com/pulumi/pulumi-command/issues).
20
-
21
27
  ## Examples
22
28
 
23
29
  ### A simple local resource (random)
@@ -45,7 +51,7 @@ import (
45
51
  func main() {
46
52
  pulumi.Run(func(ctx *pulumi.Context) error {
47
53
 
48
- random, err := local.NewCommand(ctx, "my-bucket", &local.CommandArgs{
54
+ random, err := local.NewCommand(ctx, "my-bucket", &local.CommandInput{
49
55
  Create: pulumi.String("openssl rand -hex 16"),
50
56
  })
51
57
  if err != nil {
@@ -108,7 +114,7 @@ const server = new aws.ec2.Instance("server", {
108
114
 
109
115
  // Now set up a connection to the instance and run some provisioning operations on the instance.
110
116
 
111
- const connection: types.input.remote.ConnectionArgs = {
117
+ const connection: types.input.remote.ConnectionInput = {
112
118
  host: server.publicIp,
113
119
  user: "ec2-user",
114
120
  privateKey: privateKey,
@@ -181,7 +187,7 @@ export const output = rand.stdout;
181
187
 
182
188
  ### Using `local.Command `with CURL to manage external REST API
183
189
 
184
- This example uses `local.Command` to create a simple resource provider for managing GitHub labels, by invoking `curl` commands on `create` and `delete` commands against the GitHub REST API. A similar approach could be applied to build other simple providers against any REST API directly from within Pulumi programs in any language. This approach is somewhat limited by the fact that `local.Command` does not yet support `diff`/`update`/`read`. Support for those may be [added in the future](https://github.com/pulumi/pulumi-command/issues/20).
190
+ This example uses `local.Command` to create a simple resource provider for managing GitHub labels, by invoking `curl` commands on `create` and `delete` commands against the GitHub REST API. A similar approach could be applied to build other simple providers against any REST API directly from within Pulumi programs in any language. This approach is somewhat limited by the fact that `local.Command` does not yet support `diff`/`read`. Support for [Read](https://github.com/pulumi/pulumi-command/issues/432) and [Diff](https://github.com/pulumi/pulumi-command/issues/433) may be added in the future.
185
191
 
186
192
  This example also shows how `local.Command` can be used as an implementation detail inside a nicer abstraction, like the `GitHubLabel` component defined below.
187
193
 
@@ -255,32 +261,111 @@ curl \
255
261
 
256
262
  ### Graceful cleanup of workloads in a Kubernetes cluster
257
263
 
258
- There are cases where it's important to run some cleanup operation before destroying a resource, in case destroying the resource does not properly handle orderly cleanup. For example, destroying an EKS Cluster will not ensure that all Kubernetes object finalizers are run, which may lead to leaking external resources managed by those Kubernetes resources. This example shows how we can use a `delete`-only `Command` to ensure some cleanup is run within a cluster before destroying it.
264
+ There are cases where it's important to run some cleanup operation before destroying a resource such as when destroying the resource does not properly handle orderly cleanup. For example, destroying an EKS Cluster will not ensure that all Kubernetes object finalizers are run, which may lead to leaking external resources managed by those Kubernetes resources. This example shows how we can use a `delete`-only `Command` to ensure some cleanup is run within a cluster before destroying it.
265
+
266
+ ```yaml
267
+ resources:
268
+ cluster:
269
+ type: eks:Cluster
270
+
271
+ cleanupKubernetesNamespaces:
272
+ # We could also use `RemoteCommand` to run this from
273
+ # within a node in the cluster.
274
+ type: command:local:Command
275
+ properties:
276
+ # This will run before the cluster is destroyed.
277
+ # Everything else will need to depend on this resource
278
+ # to ensure this cleanup doesn't happen too early.
279
+ delete: |
280
+ kubectl --kubeconfig <(echo "$KUBECONFIG_DATA") delete namespace nginx
281
+ # Process substitution "<()" doesn't work in the default interpreter sh.
282
+ interpreter: ["/bin/bash", "-c"]
283
+ environment:
284
+ KUBECONFIG_DATA: "${cluster.kubeconfigJson}"
285
+ ```
259
286
 
260
287
  ```ts
261
- import { local } from "@pulumi/command";
288
+ import * as pulumi from "@pulumi/pulumi";
289
+ import * as command from "@pulumi/command";
262
290
  import * as eks from "@pulumi/eks";
263
- import * as random from "@pulumi/random";
264
- import { interpolate } from "@pulumi/pulumi";
265
291
 
266
292
  const cluster = new eks.Cluster("cluster", {});
267
293
 
268
294
  // We could also use `RemoteCommand` to run this from within a node in the cluster
269
- const cleanupKubernetesNamespaces = new local.Command("cleanupKubernetesNamespaces", {
295
+ const cleanupKubernetesNamespaces = new command.local.Command("cleanupKubernetesNamespaces", {
270
296
  // This will run before the cluster is destroyed. Everything else will need to
271
297
  // depend on this resource to ensure this cleanup doesn't happen too early.
272
- delete: "kubectl delete --all namespaces",
298
+ "delete": "kubectl --kubeconfig <(echo \"$KUBECONFIG_DATA\") delete namespace nginx\n",
299
+ // Process substitution "<()" doesn't work in the default interpreter sh.
300
+ interpreter: [
301
+ "/bin/bash",
302
+ "-c",
303
+ ],
273
304
  environment: {
274
- KUBECONFIG: cluster.kubeconfig,
305
+ KUBECONFIG_DATA: cluster.kubeconfigJson,
275
306
  },
276
307
  });
277
308
  ```
278
309
 
310
+ ### Working with Assets and Paths
311
+
312
+ When a local command creates assets as part of its execution, these can be captured by specifying `assetPaths` or `archivePaths`.
313
+
314
+ ```typescript
315
+ const lambdaBuild = local.runOutput({
316
+ dir: "../my-function",
317
+ command: `yarn && yarn build`,
318
+ archivePaths: ["dist/**"],
319
+ });
320
+
321
+ new aws.lambda.Function("my-function", {
322
+ code: lambdaBuild.archive,
323
+ // ...
324
+ });
325
+ ```
326
+
327
+ When using the `assetPaths` and `archivePaths`, they take a list of 'globs'.
328
+ - We only include files not directories for assets and archives.
329
+ - Path separators are `/` on all platforms - including Windows.
330
+ - Patterns starting with `!` are 'exclude' rules.
331
+ - Rules are evaluated in order, so exclude rules should be after inclusion rules.
332
+ - `*` matches anything except `/`
333
+ - `**` matches anything, _including_ `/`
334
+ - All returned paths are relative to the working directory (without leading `./`) e.g. `file.text` or `subfolder/file.txt`.
335
+ - For full details of the globbing syntax, see [github.com/gobwas/glob](https://github.com/gobwas/glob)
336
+
337
+ #### Asset Paths Example
338
+
339
+ Given the rules:
340
+ ```yaml
341
+ - "assets/**"
342
+ - "src/**.js"
343
+ - "!**secret.*"
344
+ ```
345
+
346
+ When evaluating against this folder:
347
+
348
+ ```yaml
349
+ - assets/
350
+ - logos/
351
+ - logo.svg
352
+ - src/
353
+ - index.js
354
+ - secret.js
355
+ ```
356
+
357
+ The following paths will be returned:
358
+
359
+ ```yaml
360
+ - assets/logos/logo.svg
361
+ - src/index.js
362
+ ```
363
+
279
364
  ## Building
280
365
 
281
366
  ### Dependencies
282
367
 
283
- - Go 1.16
368
+ - Go 1.17
284
369
  - NodeJS 10.X.X or later
285
370
  - Python 3.6 or later
286
371
  - .NET Core 3.1
@@ -298,7 +383,7 @@ $ make build
298
383
  $ make install
299
384
  ```
300
385
 
301
- Add the `bin` folder to your `$PATH` or copy the `bin/pulumi-resource-aws-native` file to another location in your `$PATH`.
386
+ Add the `bin` folder to your `$PATH` or copy the `bin/pulumi-resource-command` file to another location in your `$PATH`.
302
387
 
303
388
  ### Running an example
304
389
 
package/index.d.ts CHANGED
@@ -1,5 +1,8 @@
1
- export * from "./provider";
1
+ export { ProviderArgs } from "./provider";
2
+ export type Provider = import("./provider").Provider;
3
+ export declare const Provider: typeof import("./provider").Provider;
2
4
  import * as local from "./local";
3
5
  import * as remote from "./remote";
4
6
  import * as types from "./types";
5
7
  export { local, remote, types, };
8
+ //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,MAAM,MAAM,QAAQ,GAAG,OAAO,YAAY,EAAE,QAAQ,CAAC;AACrD,eAAO,MAAM,QAAQ,EAAE,cAAc,YAAY,EAAE,QAAsB,CAAC;AAK1E,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,OAAO,EACH,KAAK,EACL,MAAM,EACN,KAAK,GACR,CAAC"}
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // *** WARNING: this file was generated by pulumigen. ***
2
+ // *** WARNING: this file was generated by pulumi-language-nodejs. ***
3
3
  // *** Do not edit by hand unless you're certain you know what you are doing! ***
4
4
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
5
  if (k2 === undefined) k2 = k;
@@ -12,30 +12,38 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
12
12
  if (k2 === undefined) k2 = k;
13
13
  o[k2] = m[k];
14
14
  }));
15
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
17
+ }) : function(o, v) {
18
+ o["default"] = v;
19
+ });
20
+ var __importStar = (this && this.__importStar) || function (mod) {
21
+ if (mod && mod.__esModule) return mod;
22
+ var result = {};
23
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
+ __setModuleDefault(result, mod);
25
+ return result;
17
26
  };
18
27
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.types = exports.remote = exports.local = void 0;
20
- const pulumi = require("@pulumi/pulumi");
21
- const utilities = require("./utilities");
22
- // Export members:
23
- __exportStar(require("./provider"), exports);
28
+ exports.types = exports.remote = exports.local = exports.Provider = void 0;
29
+ const pulumi = __importStar(require("@pulumi/pulumi"));
30
+ const utilities = __importStar(require("./utilities"));
31
+ exports.Provider = null;
32
+ utilities.lazyLoad(exports, ["Provider"], () => require("./provider"));
24
33
  // Export sub-modules:
25
- const local = require("./local");
34
+ const local = __importStar(require("./local"));
26
35
  exports.local = local;
27
- const remote = require("./remote");
36
+ const remote = __importStar(require("./remote"));
28
37
  exports.remote = remote;
29
- const types = require("./types");
38
+ const types = __importStar(require("./types"));
30
39
  exports.types = types;
31
- const provider_1 = require("./provider");
32
40
  pulumi.runtime.registerResourcePackage("command", {
33
41
  version: utilities.getVersion(),
34
42
  constructProvider: (name, type, urn) => {
35
43
  if (type !== "pulumi:providers:command") {
36
44
  throw new Error(`unknown provider type ${type}`);
37
45
  }
38
- return new provider_1.Provider(name, undefined, { urn });
46
+ return new exports.Provider(name, undefined, { urn });
39
47
  },
40
48
  });
41
49
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";AAAA,yDAAyD;AACzD,iFAAiF;;;;;;;;;;;;;;;;;AAEjF,yCAAyC;AACzC,yCAAyC;AAEzC,kBAAkB;AAClB,6CAA2B;AAE3B,sBAAsB;AACtB,iCAAiC;AAK7B,sBAAK;AAJT,mCAAmC;AAK/B,wBAAM;AAJV,iCAAiC;AAK7B,sBAAK;AAGT,yCAAsC;AAEtC,MAAM,CAAC,OAAO,CAAC,uBAAuB,CAAC,SAAS,EAAE;IAC9C,OAAO,EAAE,SAAS,CAAC,UAAU,EAAE;IAC/B,iBAAiB,EAAE,CAAC,IAAY,EAAE,IAAY,EAAE,GAAW,EAA2B,EAAE;QACpF,IAAI,IAAI,KAAK,0BAA0B,EAAE;YACrC,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAC;SACpD;QACD,OAAO,IAAI,mBAAQ,CAAC,IAAI,EAAO,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IACvD,CAAC;CACJ,CAAC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";AAAA,sEAAsE;AACtE,iFAAiF;;;;;;;;;;;;;;;;;;;;;;;;;;AAEjF,uDAAyC;AACzC,uDAAyC;AAK5B,QAAA,QAAQ,GAAyC,IAAW,CAAC;AAC1E,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;AAGvE,sBAAsB;AACtB,+CAAiC;AAK7B,sBAAK;AAJT,iDAAmC;AAK/B,wBAAM;AAJV,+CAAiC;AAK7B,sBAAK;AAET,MAAM,CAAC,OAAO,CAAC,uBAAuB,CAAC,SAAS,EAAE;IAC9C,OAAO,EAAE,SAAS,CAAC,UAAU,EAAE;IAC/B,iBAAiB,EAAE,CAAC,IAAY,EAAE,IAAY,EAAE,GAAW,EAA2B,EAAE;QACpF,IAAI,IAAI,KAAK,0BAA0B,EAAE;YACrC,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAC;SACpD;QACD,OAAO,IAAI,gBAAQ,CAAC,IAAI,EAAO,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IACvD,CAAC;CACJ,CAAC,CAAC"}