Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing environment variable prevents automation API from working in container pulumi/pulumi #141

Open
kerruba-milkman opened this issue May 18, 2023 · 1 comment
Labels
kind/enhancement Improvements or new features

Comments

@kerruba-milkman
Copy link

What happened?

I'm trying to embed a typescript application that leverage the Automation API to execute a Local Program using the LocalProgramArgs.
I've set up the container with the required PULUMI_ACCESS_TOKEN env var and I've also provided the env-vars for AWS.
Here the command I'm using to launch the container with bash.

docker run -it \
    -e AWS_ACCESS_KEY_ID=<some-value> \
    -e AWS_SECRET_ACCESS_KEY=<some-value> \
    -e AWS_REGION=<some-value> \
    -e PULUMI_ACCESS_TOKEN=<pulumi-access-token-value> \
    -e PULUMI_BACKEND_URL='https://api.pulumi.com' \
    -w /app \
    -v $(pwd):/app \
    --entrypoint bash \
    pulumi/pulumi

Inside the container I'm able to navigate to the directory with the pulumi program and run the CLI commands (e.g. pulumi preview -s ).

When I try to run the program using the automation api, I use this command:

npx ts-node index.ts preview

Here the content of the file index.ts

import * as upath from 'upath';
import * as auto from '@pulumi/pulumi/automation';
import process = require('node:process');

const args = process.argv.slice(2);
let preview = false;
if (args.length > 0 && args[0]) {
  preview = args[0] === 'preview';
}

const run = async (options: TenantConfig) => {

  const wsArgs: auto.LocalProgramArgs = {
    stackName: 'mrc',
    workDir: upath.joinSafe(__dirname, '..', 'tenant-applications'),
  };

  const fullConfig = { ...baseConfig, ...options }; // create (or select if one already exists) a stack that uses our local program
  const stack = await auto.LocalWorkspace.createOrSelectStack(wsArgs);

  console.info('successfully initialized stack');
  console.info('setting up config');
  await stack.setAllConfig(fullConfig);
  console.info('config set');

  if (preview) {
    console.info('previewing stack...');
    await stack.preview({ onOutput: console.info });
  } else {
    console.info('updating stack...');
    const upRes = await stack.up({ onOutput: console.info });
    console.log(`update summary: \n${JSON.stringify(upRes.summary.resourceChanges, null, 4)}`);
  }
};

run(newConfig).catch((err) => console.error(err));

But I get this error:

CommandError: code: -2
 stdout:
 stderr: Command failed with exit code 255: pulumi stack select --stack mrc --non-interactive
Logging in using access token from PULUMI_ACCESS_TOKEN
error: failed to get the home path: getting current user: luser: unable to get current user
 err?: Error: Command failed with exit code 255: pulumi stack select --stack mrc --non-interactive
Logging in using access token from PULUMI_ACCESS_TOKEN
error: failed to get the home path: getting current user: luser: unable to get current user

    at Object.createCommandError (/app/tenant-automation/node_modules/@pulumi/automation/errors.ts:75:27)
    at Object.<anonymous> (/app/tenant-automation/node_modules/@pulumi/automation/cmd.ts:84:15)
    at Generator.throw (<anonymous>)
    at rejected (/app/tenant-automation/node_modules/@pulumi/pulumi/automation/cmd.js:19:65)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  commandResult: CommandResult {
    stdout: '',
    stderr: 'Command failed with exit code 255: pulumi stack select --stack mrc --non-interactive\n' +
      'Logging in using access token from PULUMI_ACCESS_TOKEN\n' +
      'error: failed to get the home path: getting current user: luser: unable to get current user',
    code: -2,
    err: Error: Command failed with exit code 255: pulumi stack select --stack mrc --non-interactive
    Logging in using access token from PULUMI_ACCESS_TOKEN
    error: failed to get the home path: getting current user: luser: unable to get current user
        at makeError (/app/tenant-automation/node_modules/execa/lib/error.js:60:11)
        at handlePromise (/app/tenant-automation/node_modules/execa/index.js:118:26)
        at processTicksAndRejections (node:internal/process/task_queues:96:5) {
      shortMessage: 'Command failed with exit code 255: pulumi stack select --stack mrc --non-interactive',
      command: 'pulumi stack select --stack mrc --non-interactive',
      escapedCommand: 'pulumi stack select --stack mrc --non-interactive',
      exitCode: 255,
      signal: undefined,
      signalDescription: undefined,
      stdout: '',
      stderr: 'Logging in using access token from PULUMI_ACCESS_TOKEN\n' +
        'error: failed to get the home path: getting current user: luser: unable to get current user',
      failed: true,
      timedOut: false,
      isCanceled: false,
      killed: false
    }
  }
}

Had support on the community slack channel, and turned out the problem was a missing env variable (PULUMI_HOME) not reported anywhere in the documentation for the docker container. You can check the conversation here https://pulumi-community.slack.com/archives/C019YSXN04B/p1684339917792559

Expected Behavior

Either this behavior is documented in the docker image README, or the problem should be fixed by not requiring the environment variable

Steps to reproduce

Check description above

Output of pulumi about

root@ca48d430c1e7:/app/tenant-automation# pulumi about
CLI
Version      3.67.1
Go Version   go1.20.4
Go Compiler  gc

Host
OS       debian
Version  11.7
Arch     x86_64

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@kerruba-milkman kerruba-milkman added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels May 18, 2023
@dixler dixler added kind/enhancement Improvements or new features and removed needs-triage Needs attention from the triage team kind/bug Some behavior is incorrect or out of spec labels May 18, 2023
@dixler
Copy link
Contributor

dixler commented May 18, 2023

Hi, sorry that you went through this. I'm going to transfer this to the pulumi-docker-containers repository.

@dixler dixler transferred this issue from pulumi/pulumi May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Improvements or new features
Projects
None yet
Development

No branches or pull requests

2 participants