https://pulumi.com logo
Title
m

many-apartment-92429

12/22/2021, 3:49 PM
Hi guys! I am new to Pulumi and would like to create a script that creates Github repos. The script should not be a part of our available stacks(e.g. it should not be executed as part of ‘pulumi up’, but simply by “yarn ts-node script.ts”). If I understood correctly, one can use LocalWorkspaces for that together with the Github module. So, my code looks like this:
import { LocalProgramArgs, LocalWorkspace } from "@pulumi/pulumi/automation";
import * as github from "@pulumi/github";
const repo2 = new github.Repository(
  "mytest",
  {
    description: "mytest",
    visibility: "internal",
  },
);
console.log("Created repo2 repository");
bit if fails with:
yarn ts-node scripts/repos/simple_script.ts
yarn run v1.22.17
$ /home/seo_infra/node_modules/.bin/ts-node scripts/repos/simple_script.ts

/home/seo_infra/node_modules/@pulumi/pulumi/runtime/settings.js:123
        throw new Error("Program run without the Pulumi engine available; re-run using the `pulumi` CLI");
              ^
Error: Program run without the Pulumi engine available; re-run using the `pulumi` CLI
    at requireTestModeEnabled (/home/seo_infra/node_modules/@pulumi/pulumi/runtime/settings.js:123:15)
    at Object.getMonitor (/home/seo_infra/node_modules/@pulumi/pulumi/runtime/settings.js:216:13)
    at Object.registerResource (/home/seo_infra/node_modules/@pulumi/pulumi/runtime/resource.js:213:32)
    at new Resource (/home/seo_infra/node_modules/@pulumi/pulumi/resource.js:217:24)
    at new CustomResource (/home/seo_infra/node_modules/@pulumi/pulumi/resource.js:309:9)
    at new Repository (/home/seo_infra/node_modules/@pulumi/repository.ts:305:9)
    at Object.<anonymous> (/home/seo_infra/scripts/repos/simple_script.ts:39:15)
    at Module._compile (node:internal/modules/cjs/loader:1095:14)
    at Module.m._compile (/home/seo_infra/node_modules/ts-node/src/index.ts:1310:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1147:10)
error Command failed with exit code 1.
info Visit <https://yarnpkg.com/en/docs/cli/run> for documentation about this command.
Do you have any hints why it fails and how to make it working? Googling a good half of the internet did not help… Adding a local stack with configuration also did not change anything:
const stack = await LocalWorkspace.createOrSelectStack(args, {
    projectSettings: {
      name: "infra",
      runtime: "nodejs",
      backend: {
        url: `s3://${BUCKET_NAME}`,
      },
    },
    secretsProvider,
    stackSettings: {
      [args.stackName]: {
        secretsProvider,
      },
    },
  });
The error is still the same. Thank you.
s

stocky-restaurant-98004

12/22/2021, 5:42 PM
You need to run the program with
pulumi up
, not as a regular node program.
The first line of imports should not be necessary. You might want to start with a empty directory, run
pulumi new ts
and then copy/paste your code minus the first line.
b

billowy-army-68599

12/22/2021, 9:13 PM
@many-apartment-92429 if you want to run pulumi programs outside the
pulumi up
workflow, you'll need to use the automation API: https://github.com/pulumi/automation-api-examples/tree/main/nodejs/inlineProgram-ts This can be packaged as part of a yarn workflow
m

many-apartment-92429

12/23/2021, 1:42 PM
@stocky-restaurant-98004 we do not want the Github-part to be a part of “pulumi up”. There is an automation API for this, but I cannot make it working with “@pulumi/github”. With “import { LocalProgramArgs, LocalWorkspace } from “@pulumi/pulumi/automation”;” or without, I still tge the same error.
@billowy-army-68599 Yesm I saw this one, but it does not work in our environment: awsume whatever Session token will expire at 2021-12-24 02:28:41 [whatever] Role credentials will expire 2021-12-23 15:43:48 yarn install yarn install v1.22.17 [1/4] 🔍 Resolving packages... success Already up-to-date. Done in 0.10s. yarn start yarn run v1.22.17 $ tsc && node ./bin/index.js successfully initialized stack installing plugins... plugins installed setting up config config set refreshing stack... CommandError: code: 255 stdout: stderr: error: getting secrets manager: passphrase must be set with PULUMI_CONFIG_PASSPHRASE or PULUMI_CONFIG_PASSPHRASE_FILE environment variables But it goes into a wrong direction. I simply would like to use @pulumi/github” to create a repo. Without any involvement of our actual Pulumi stacks, if possible. Do you have any idea how to achieve this?
s

stocky-restaurant-98004

12/24/2021, 3:22 PM
Do you want Pulumi to manage the lifecycle of the repository (create/update/delete), or are you just trying to automate the creation of repositories? If it's the latter, you don't need Pulumi at all - just use Octokit. https://github.com/octokit/octokit.js
👍 1