{"id":24042041,"url":"https://github.com/pulumi/pulumi-repl","last_synced_at":"2025-04-19T19:54:39.553Z","repository":{"id":57679157,"uuid":"365542467","full_name":"pulumi/pulumi-repl","owner":"pulumi","description":"Create cloud infrastructure and explore pulumi in an interactive NodeJS REPL","archived":false,"fork":false,"pushed_at":"2021-05-09T16:31:40.000Z","size":5467,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-17T14:32:54.218Z","etag":null,"topics":["aws","cloud","iac","kubernetes","pulumi"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pulumi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-08T15:01:44.000Z","updated_at":"2025-04-08T07:01:48.000Z","dependencies_parsed_at":"2022-08-28T07:42:53.649Z","dependency_job_id":null,"html_url":"https://github.com/pulumi/pulumi-repl","commit_stats":null,"previous_names":["evanboyle/pulumi-repl"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pulumi%2Fpulumi-repl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pulumi%2Fpulumi-repl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pulumi%2Fpulumi-repl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pulumi%2Fpulumi-repl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pulumi","download_url":"https://codeload.github.com/pulumi/pulumi-repl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249518123,"owners_count":21284909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","cloud","iac","kubernetes","pulumi"],"created_at":"2025-01-08T22:15:04.236Z","updated_at":"2025-04-19T19:54:39.522Z","avatar_url":"https://github.com/pulumi.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pulumi-repl\n\nCreate cloud infrastructure and explore pulumi in an interactive NodeJS REPL.\n\n[![NPM version](https://badge.fury.io/js/pulumi-repl.svg)](https://npmjs.com/package/pulumi-repl)\n\n\n1. Create and explore cloud infrastructure.\n2. Run `apply` and experiment with other pulumi functionality.\n3. Save your work as a full pulumi program when you're done with `eject`!\n4. Create ephemeral sessions that automatically delete all resources on `ctrl+c`.\n\nJust a few lines of code to get started:\n\n```sh\nyarn install pulumi-repl\n```\n\n```ts\nimport { PulumiRepl } from \"pulumi-repl\";\n\nconst repl = new PulumiRepl({\n    stack: \"dev\",\n    project: \"pulumi-repl\",\n    eject: true, // save my work at the end in ./eject\n    config: {\n        \"aws:region\": { value: \"us-west-2\" }\n    },\n});\n\nrepl.start().catch(err =\u003e console.error(err));\n```\n\n## Demos\n\n### Kubernetes\n\nCreate kubernetes resources interactively! At the end, all created resources are saved in stae by the pulumi engine.\n\n![](gifs/k8s.gif)\n\n### Eject\n\nWhen you're done with your REPL, you can eject a pulumi program generated from all the commands you entered. Here we create a static S3 website. At the end our program is ejected in `./eject`. When we run a preview on that program, we see that there's no diff!\n\n![](gifs/eject.gif)\n\n## Usage \u0026\u0026 Requirements\n\n### Prereqs:\n\n1. Pulumi CLI logged in and configured: https://www.pulumi.com/docs/get-started/\n2. Cloud credentials configured as per above guide (for your cloud of choice).\n\n### Basic\n\n```ts\nimport { PulumiRepl } from \"pulumi-repl\";\n\n// configure the REPL\nconst repl = new PulumiRepl({\n    stack: \"dev\", // you Pulumi stack name, where your infrastructure state gets stored\n    project: \"pulumi-repl\", // top level pulumi project\n    config: { // any config that might be required by your cloud provider\n        \"aws:region\": { value: \"us-west-2\" }\n    },\n});\n\n// start execution, ctrl+c to exit\nrepl.start().catch(err =\u003e console.error(err));\n```\n\n### Registering Stack Outputs in the REPL\n\nThe REPL has a builtin function `registerOutput(k, v)` which creates stack exports.\n\n```sh\n$ pulumi-repl\u003e registerOutput(\"websiteUrl\", siteBucket.websiteEndpoint);\n\n...\nOutputs:\n    websiteUrl: \"s3-website-bucket-82db68d.s3-website-us-west-2.amazonaws.com\"\n```\n\n### Eject\n`eject` will output a full pulumi program into the `./eject` directory including:\n- index.js (program)\n- pacakge.json\n- Pulumi.yaml (your project file)\n\n```ts\nconst repl = new PulumiRepl({\n    eject: true // save your work in ./eject at the end\n    stack: \"dev\",\n    project: \"pulumi-repl\",\n    config: {\n        \"aws:region\": { value: \"us-west-2\" }\n    },\n});\n\nTo run your program:\n```sh\n$ cd ./eject\n$ yarn install\n$ pulumi stack select # pick the stack you want to work with\n$ pulumi config set ... # set any cloud provider config values if needed\n$ pulumi preview # see your program in action\n```\n\n### Plugins and Context\n\nThe REPL comes preloaded with the following Pulumi provider plugins:\n\n- AWS\n- Azure (native)\n- GCP \n- Kubernetes\n\nYou can add additional provider plugins and SDKs as described below.\n\nThe REPL supports defining context values via `this.addContext(k, v)`, which we use to load the `random` resource provider SDK below. In addition, we access the Automation API stack object to install plugins.\n\n```ts\nimport { PulumiRepl } from \"pulumi-repl\";\n// import a custom pulumi provider SDK.\nimport * as random from \"@pulumi/random\";\n\nconst repl = new PulumiRepl({\n    stack: \"dev\",\n    project: \"pulumi-repl-custom\",\n});\n\n// make the random SDK accessible to the repl at runtime\nrepl.addContext(\"random\", random);\n\n// access the automation api stack to install provider plugins\nrepl.stack.then(s =\u003e {\n    // install the 'random' resource provider plugin\n    s.workspace.installPlugin(\"random\", \"v4.0.0\").then(()=\u003e{\n        repl.start().catch(err =\u003e console.error(err));\n    })\n});\n```\n\n### Ephemeral Stacks\n\nSpecify the `ephemeral: true` arg to run the repl in ephemeral mode. On `ctrl+c` all of your cloud resources will be cleaned up and destroyed.\n\n```ts\nimport { PulumiRepl } from \"pulumi-repl\";\n\nconst repl = new PulumiRepl({\n    stack: \"dev\",\n    project: \"pulumi-repl-custom\",\n    ephemeral: true // delete the resources created during this session with ctrl+c\n});\n```\n\n### Automation API Stack \u0026 Workspace\nIf you're an advanced Pulumi user, you may want to access the Automation API Stack. You can do this via `this.stack` (a promise). \n\nYou can access the underlying `LocalWorkspace` via `this.stack.then(s =\u003e s.workspace)`. \n\nAdvanced workspace configuration options are available including custom backends (azure, filestate, etc), and custom secrets providers via `ReplArgs.workspaceOpts`\n## How it works\n\nThis library uses the native NodeJS REPL library and the [Pulumi Automation API](https://www.pulumi.com/docs/guides/automation-api/) (OSS) which turns the Pulumi IaC engine into an embeddable SDK. \n\n### Caveats \u0026 Immutability\n\nWhen you execute commands in the REPL, you're still running pulumi code. Because Pulumi is declarative and desired state, resources can't be mutated after they are instantiated in the REPL. You'll have to exit the session and restart to \"make an edit\". Each REPL session will compute differences against the previous state. If you define a resource in one session and then forget it in the next one, it will be deleted. This is just like making edits and running a normal pulumi program, the only difference is that we get to create resources incrementally and explore their shape, outputs, etc.\n\nRead more about Pulumi's desired state architecture: https://www.pulumi.com/docs/intro/concepts/how-pulumi-works/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpulumi%2Fpulumi-repl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpulumi%2Fpulumi-repl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpulumi%2Fpulumi-repl/lists"}