@pulumi/command 0.0.1-alpha.100

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 (53) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +400 -0
  3. package/index.d.ts +7 -0
  4. package/index.js +26 -0
  5. package/index.js.map +1 -0
  6. package/local/command.d.ts +404 -0
  7. package/local/command.js +164 -0
  8. package/local/command.js.map +1 -0
  9. package/local/index.d.ts +7 -0
  10. package/local/index.js +41 -0
  11. package/local/index.js.map +1 -0
  12. package/local/run.d.ts +391 -0
  13. package/local/run.js +46 -0
  14. package/local/run.js.map +1 -0
  15. package/package.json +29 -0
  16. package/package.json.dev +28 -0
  17. package/provider.d.ts +21 -0
  18. package/provider.js +38 -0
  19. package/provider.js.map +1 -0
  20. package/remote/command.d.ts +206 -0
  21. package/remote/command.js +141 -0
  22. package/remote/command.js.map +1 -0
  23. package/remote/copyFile.d.ts +70 -0
  24. package/remote/copyFile.js +79 -0
  25. package/remote/copyFile.js.map +1 -0
  26. package/remote/copyToRemote.d.ts +125 -0
  27. package/remote/copyToRemote.js +134 -0
  28. package/remote/copyToRemote.js.map +1 -0
  29. package/remote/index.d.ts +10 -0
  30. package/remote/index.js +46 -0
  31. package/remote/index.js.map +1 -0
  32. package/scripts/install-pulumi-plugin.js +21 -0
  33. package/types/enums/index.d.ts +3 -0
  34. package/types/enums/index.js +11 -0
  35. package/types/enums/index.js.map +1 -0
  36. package/types/enums/local/index.d.ts +19 -0
  37. package/types/enums/local/index.js +24 -0
  38. package/types/enums/local/index.js.map +1 -0
  39. package/types/enums/remote/index.d.ts +19 -0
  40. package/types/enums/remote/index.js +24 -0
  41. package/types/enums/remote/index.js.map +1 -0
  42. package/types/index.d.ts +4 -0
  43. package/types/index.js +13 -0
  44. package/types/index.js.map +1 -0
  45. package/types/input.d.ts +98 -0
  46. package/types/input.js +27 -0
  47. package/types/input.js.map +1 -0
  48. package/types/output.d.ts +97 -0
  49. package/types/output.js +26 -0
  50. package/types/output.js.map +1 -0
  51. package/utilities.d.ts +8 -0
  52. package/utilities.js +101 -0
  53. package/utilities.js.map +1 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,400 @@
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 (preview)
10
+
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.
12
+
13
+ There are many scenarios where the Command package can be useful:
14
+
15
+ * Running a command locally after creating a resource, to register it with an external service
16
+ * Running a command locally before deleting a resource, to deregister it with an external service
17
+ * Running a command remotely on a remote host immediately after creating it
18
+ * Copying a file to a remote host after creating it (potentially as a script to be executed afterwards)
19
+ * As a simple alternative to some use cases for Dynamic Providers (especially in languages which do not yet support Dynamic Providers).
20
+
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.
22
+
23
+ You can use the Command package from a Pulumi program written in any Pulumi language: C#, Go, JavaScript/TypeScript, Python, and YAML.
24
+ You'll need to [install and configure the Pulumi CLI](https://pulumi.com/docs/get-started/install) if you haven't already.
25
+
26
+
27
+ > **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).
28
+
29
+ ## Examples
30
+
31
+ ### A simple local resource (random)
32
+
33
+ The simplest use case for `local.Command` is to just run a command on `create`, which can return some value which will be stored in the state file, and will be persistent for the life of the stack (or until the resource is destroyed or replaced). The example below uses this as an alternative to the `random` package to create some randomness which is stored in Pulumi state.
34
+
35
+ ```ts
36
+ import { local } from "@pulumi/command";
37
+
38
+ const random = new local.Command("random", {
39
+ create: "openssl rand -hex 16",
40
+ });
41
+
42
+ export const output = random.stdout;
43
+ ```
44
+
45
+ ```go
46
+ package main
47
+
48
+ import (
49
+ "github.com/pulumi/pulumi-command/sdk/go/command/local"
50
+ "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
51
+ )
52
+
53
+ func main() {
54
+ pulumi.Run(func(ctx *pulumi.Context) error {
55
+
56
+ random, err := local.NewCommand(ctx, "my-bucket", &local.CommandInput{
57
+ Create: pulumi.String("openssl rand -hex 16"),
58
+ })
59
+ if err != nil {
60
+ return err
61
+ }
62
+
63
+ ctx.Export("output", random.Stdout)
64
+ return nil
65
+ })
66
+ }
67
+ ```
68
+
69
+ ### Remote provisioning of an EC2 instance
70
+
71
+ This example creates and EC2 instance, and then uses `remote.Command` and `remote.CopyFile` to run commands and copy files to the remote instance (via SSH). Similar things are possible with Azure, Google Cloud and other cloud provider virtual machines. Support for Windows-based VMs is being tracked [here](https://github.com/pulumi/pulumi-command/issues/15).
72
+
73
+ Note that implicit and explicit (`dependsOn`) dependencies can be used to control the order that these `Command` and `CopyFile` resources are constructed relative to each other and to the cloud resources they depend on. This ensures that the `create` operations run after all dependencies are created, and the `delete` operations run before all dependencies are deleted.
74
+
75
+ Because the `Command` and `CopyFile` resources replace on changes to their connection, if the EC2 instance is replaced, the commands will all re-run on the new instance (and the `delete` operations will run on the old instance).
76
+
77
+ Note also that `deleteBeforeReplace` can be composed with `Command` resources to ensure that the `delete` operation on an "old" instance is run before the `create` operation of the new instance, in case a scarce resource is managed by the command. Similarly, other resource options can naturally be applied to `Command` resources, like `ignoreChanges`.
78
+
79
+ ```ts
80
+ import { interpolate, Config } from "@pulumi/pulumi";
81
+ import { local, remote, types } from "@pulumi/command";
82
+ import * as aws from "@pulumi/aws";
83
+ import * as fs from "fs";
84
+ import * as os from "os";
85
+ import * as path from "path";
86
+ import { size } from "./size";
87
+
88
+ const config = new Config();
89
+ const keyName = config.get("keyName") ?? new aws.ec2.KeyPair("key", { publicKey: config.require("publicKey") }).keyName;
90
+ const privateKeyBase64 = config.get("privateKeyBase64");
91
+ const privateKey = privateKeyBase64 ? Buffer.from(privateKeyBase64, 'base64').toString('ascii') : fs.readFileSync(path.join(os.homedir(), ".ssh", "id_rsa")).toString("utf8");
92
+
93
+ const secgrp = new aws.ec2.SecurityGroup("secgrp", {
94
+ description: "Foo",
95
+ ingress: [
96
+ { protocol: "tcp", fromPort: 22, toPort: 22, cidrBlocks: ["0.0.0.0/0"] },
97
+ { protocol: "tcp", fromPort: 80, toPort: 80, cidrBlocks: ["0.0.0.0/0"] },
98
+ ],
99
+ });
100
+
101
+ const ami = aws.ec2.getAmiOutput({
102
+ owners: ["amazon"],
103
+ mostRecent: true,
104
+ filters: [{
105
+ name: "name",
106
+ values: ["amzn2-ami-hvm-2.0.????????-x86_64-gp2"],
107
+ }],
108
+ });
109
+
110
+ const server = new aws.ec2.Instance("server", {
111
+ instanceType: size,
112
+ ami: ami.id,
113
+ keyName: keyName,
114
+ vpcSecurityGroupIds: [secgrp.id],
115
+ }, { replaceOnChanges: ["instanceType"] });
116
+
117
+ // Now set up a connection to the instance and run some provisioning operations on the instance.
118
+
119
+ const connection: types.input.remote.ConnectionInput = {
120
+ host: server.publicIp,
121
+ user: "ec2-user",
122
+ privateKey: privateKey,
123
+ };
124
+
125
+ const hostname = new remote.Command("hostname", {
126
+ connection,
127
+ create: "hostname",
128
+ });
129
+
130
+ new remote.Command("remotePrivateIP", {
131
+ connection,
132
+ create: interpolate`echo ${server.privateIp} > private_ip.txt`,
133
+ delete: `rm private_ip.txt`,
134
+ }, { deleteBeforeReplace: true });
135
+
136
+ new local.Command("localPrivateIP", {
137
+ create: interpolate`echo ${server.privateIp} > private_ip.txt`,
138
+ delete: `rm private_ip.txt`,
139
+ }, { deleteBeforeReplace: true });
140
+
141
+ const sizeFile = new remote.CopyFile("size", {
142
+ connection,
143
+ localPath: "./size.ts",
144
+ remotePath: "size.ts",
145
+ })
146
+
147
+ const catSize = new remote.Command("checkSize", {
148
+ connection,
149
+ create: "cat size.ts",
150
+ }, { dependsOn: sizeFile })
151
+
152
+ export const confirmSize = catSize.stdout;
153
+ export const publicIp = server.publicIp;
154
+ export const publicHostName = server.publicDns;
155
+ export const hostnameStdout = hostname.stdout;
156
+ ```
157
+
158
+ ### Invoking a Lambda during Pulumi deployment
159
+
160
+ There may be cases where it is useful to run some code within an AWS Lambda or other serverless function during the deployment. For example, this may allow running some code from within a VPC, or with a specific role, without needing to have persistent compute available (such as the EC2 example above).
161
+
162
+ Note that the Lambda function itself can be created within the same Pulumi program, and then invoked after creation.
163
+
164
+ The example below simply creates some random value within the Lambda, which is a very roundabout way of doing the same thing as the first "random" example above, but this pattern can be used for more complex scenarios where the Lambda does things a local script could not.
165
+
166
+ ```ts
167
+ import { local } from "@pulumi/command";
168
+ import * as aws from "@pulumi/aws";
169
+ import * as crypto from "crypto";
170
+
171
+ const f = new aws.lambda.CallbackFunction("f", {
172
+ publish: true,
173
+ callback: async (ev: any) => {
174
+ return crypto.randomBytes(ev.len/2).toString('hex');
175
+ }
176
+ });
177
+
178
+ const rand = new local.Command("execf", {
179
+ create: `aws lambda invoke --function-name "$FN" --payload '{"len": 10}' --cli-binary-format raw-in-base64-out out.txt >/dev/null && cat out.txt | tr -d '"' && rm out.txt`,
180
+ environment: {
181
+ FN: f.qualifiedArn,
182
+ AWS_REGION: aws.config.region!,
183
+ AWS_PAGER: "",
184
+ },
185
+ })
186
+
187
+ export const output = rand.stdout;
188
+ ```
189
+
190
+ ### Using `local.Command `with CURL to manage external REST API
191
+
192
+ 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.
193
+
194
+ This example also shows how `local.Command` can be used as an implementation detail inside a nicer abstraction, like the `GitHubLabel` component defined below.
195
+
196
+ ```ts
197
+ import * as pulumi from "@pulumi/pulumi";
198
+ import * as random from "@pulumi/random";
199
+ import { local } from "@pulumi/command";
200
+
201
+ interface LabelArgs {
202
+ owner: pulumi.Input<string>;
203
+ repo: pulumi.Input<string>;
204
+ name: pulumi.Input<string>;
205
+ githubToken: pulumi.Input<string>;
206
+ }
207
+
208
+ class GitHubLabel extends pulumi.ComponentResource {
209
+ public url: pulumi.Output<string>;
210
+
211
+ constructor(name: string, args: LabelArgs, opts?: pulumi.ComponentResourceOptions) {
212
+ super("example:github:Label", name, args, opts);
213
+
214
+ const label = new local.Command("label", {
215
+ create: "./create_label.sh",
216
+ delete: "./delete_label.sh",
217
+ environment: {
218
+ OWNER: args.owner,
219
+ REPO: args.repo,
220
+ NAME: args.name,
221
+ GITHUB_TOKEN: args.githubToken,
222
+ }
223
+ }, { parent: this });
224
+
225
+ const response = label.stdout.apply(JSON.parse);
226
+ this.url = response.apply((x: any) => x.url as string);
227
+ }
228
+ }
229
+
230
+ const config = new pulumi.Config();
231
+ const rand = new random.RandomString("s", { length: 10, special: false });
232
+
233
+ const label = new GitHubLabel("l", {
234
+ owner: "pulumi",
235
+ repo: "pulumi-command",
236
+ name: rand.result,
237
+ githubToken: config.requireSecret("githubToken"),
238
+ });
239
+
240
+ export const labelUrl = label.url;
241
+ ```
242
+
243
+ ```sh
244
+ # create_label.sh
245
+ curl \
246
+ -s \
247
+ -X POST \
248
+ -H "authorization: Bearer $GITHUB_TOKEN" \
249
+ -H "Accept: application/vnd.github.v3+json" \
250
+ https://api.github.com/repos/$OWNER/$REPO/labels \
251
+ -d "{\"name\":\"$NAME\"}"
252
+ ```
253
+
254
+ ```sh
255
+ # delete_label.sh
256
+ curl \
257
+ -s \
258
+ -X DELETE \
259
+ -H "authorization: Bearer $GITHUB_TOKEN" \
260
+ -H "Accept: application/vnd.github.v3+json" \
261
+ https://api.github.com/repos/$OWNER/$REPO/labels/$NAME
262
+ ```
263
+
264
+ ### Graceful cleanup of workloads in a Kubernetes cluster
265
+
266
+ 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.
267
+
268
+ ```yaml
269
+ resources:
270
+ cluster:
271
+ type: eks:Cluster
272
+
273
+ cleanupKubernetesNamespaces:
274
+ # We could also use `RemoteCommand` to run this from
275
+ # within a node in the cluster.
276
+ type: command:local:Command
277
+ properties:
278
+ # This will run before the cluster is destroyed.
279
+ # Everything else will need to depend on this resource
280
+ # to ensure this cleanup doesn't happen too early.
281
+ delete: |
282
+ kubectl --kubeconfig <(echo "$KUBECONFIG_DATA") delete namespace nginx
283
+ # Process substitution "<()" doesn't work in the default interpreter sh.
284
+ interpreter: ["/bin/bash", "-c"]
285
+ environment:
286
+ KUBECONFIG_DATA: "${cluster.kubeconfigJson}"
287
+ ```
288
+
289
+ ```ts
290
+ import * as pulumi from "@pulumi/pulumi";
291
+ import * as command from "@pulumi/command";
292
+ import * as eks from "@pulumi/eks";
293
+
294
+ const cluster = new eks.Cluster("cluster", {});
295
+
296
+ // We could also use `RemoteCommand` to run this from within a node in the cluster
297
+ const cleanupKubernetesNamespaces = new command.local.Command("cleanupKubernetesNamespaces", {
298
+ // This will run before the cluster is destroyed. Everything else will need to
299
+ // depend on this resource to ensure this cleanup doesn't happen too early.
300
+ "delete": "kubectl --kubeconfig <(echo \"$KUBECONFIG_DATA\") delete namespace nginx\n",
301
+ // Process substitution "<()" doesn't work in the default interpreter sh.
302
+ interpreter: [
303
+ "/bin/bash",
304
+ "-c",
305
+ ],
306
+ environment: {
307
+ KUBECONFIG_DATA: cluster.kubeconfigJson,
308
+ },
309
+ });
310
+ ```
311
+
312
+ ### Working with Assets and Paths
313
+
314
+ When a local command creates assets as part of its execution, these can be captured by specifying `assetPaths` or `archivePaths`.
315
+
316
+ ```typescript
317
+ const lambdaBuild = local.runOutput({
318
+ dir: "../my-function",
319
+ command: `yarn && yarn build`,
320
+ archivePaths: ["dist/**"],
321
+ });
322
+
323
+ new aws.lambda.Function("my-function", {
324
+ code: lambdaBuild.archive,
325
+ // ...
326
+ });
327
+ ```
328
+
329
+ When using the `assetPaths` and `archivePaths`, they take a list of 'globs'.
330
+ - We only include files not directories for assets and archives.
331
+ - Path separators are `/` on all platforms - including Windows.
332
+ - Patterns starting with `!` are 'exclude' rules.
333
+ - Rules are evaluated in order, so exclude rules should be after inclusion rules.
334
+ - `*` matches anything except `/`
335
+ - `**` matches anything, _including_ `/`
336
+ - All returned paths are relative to the working directory (without leading `./`) e.g. `file.text` or `subfolder/file.txt`.
337
+ - For full details of the globbing syntax, see [github.com/gobwas/glob](https://github.com/gobwas/glob)
338
+
339
+ #### Asset Paths Example
340
+
341
+ Given the rules:
342
+ ```yaml
343
+ - "assets/**"
344
+ - "src/**.js"
345
+ - "!**secret.*"
346
+ ```
347
+
348
+ When evaluating against this folder:
349
+
350
+ ```yaml
351
+ - assets/
352
+ - logos/
353
+ - logo.svg
354
+ - src/
355
+ - index.js
356
+ - secret.js
357
+ ```
358
+
359
+ The following paths will be returned:
360
+
361
+ ```yaml
362
+ - assets/logos/logo.svg
363
+ - src/index.js
364
+ ```
365
+
366
+ ## Building
367
+
368
+ ### Dependencies
369
+
370
+ - Go 1.17
371
+ - NodeJS 10.X.X or later
372
+ - Python 3.6 or later
373
+ - .NET Core 3.1
374
+
375
+ Please refer to [Contributing to Pulumi](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) for installation
376
+ guidance.
377
+
378
+ ### Building locally
379
+
380
+ Run the following commands to install Go modules, generate all SDKs, and build the provider:
381
+
382
+ ```
383
+ $ make ensure
384
+ $ make build
385
+ $ make install
386
+ ```
387
+
388
+ Add the `bin` folder to your `$PATH` or copy the `bin/pulumi-resource-command` file to another location in your `$PATH`.
389
+
390
+ ### Running an example
391
+
392
+ Navigate to the simple example and run Pulumi:
393
+
394
+ ```
395
+ $ cd examples/simple
396
+ $ yarn link @pulumi/command
397
+ $ yarn install
398
+ $ pulumi up
399
+ ```
400
+
package/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export { ProviderArgs } from "./provider";
2
+ export type Provider = import("./provider").Provider;
3
+ export declare const Provider: typeof import("./provider").Provider;
4
+ import * as local from "./local";
5
+ import * as remote from "./remote";
6
+ import * as types from "./types";
7
+ export { local, remote, types, };
package/index.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ // *** WARNING: this file was generated by pulumi-language-nodejs. ***
3
+ // *** Do not edit by hand unless you're certain you know what you are doing! ***
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.types = exports.remote = exports.local = exports.Provider = void 0;
6
+ const pulumi = require("@pulumi/pulumi");
7
+ const utilities = require("./utilities");
8
+ exports.Provider = null;
9
+ utilities.lazyLoad(exports, ["Provider"], () => require("./provider"));
10
+ // Export sub-modules:
11
+ const local = require("./local");
12
+ exports.local = local;
13
+ const remote = require("./remote");
14
+ exports.remote = remote;
15
+ const types = require("./types");
16
+ exports.types = types;
17
+ pulumi.runtime.registerResourcePackage("command", {
18
+ version: utilities.getVersion(),
19
+ constructProvider: (name, type, urn) => {
20
+ if (type !== "pulumi:providers:command") {
21
+ throw new Error(`unknown provider type ${type}`);
22
+ }
23
+ return new exports.Provider(name, undefined, { urn });
24
+ },
25
+ });
26
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";AAAA,sEAAsE;AACtE,iFAAiF;;;AAEjF,yCAAyC;AACzC,yCAAyC;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,iCAAiC;AAK7B,sBAAK;AAJT,mCAAmC;AAK/B,wBAAM;AAJV,iCAAiC;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"}