<#C0602S4P4T1|> I might be missing something that ...
# esc
m
#C0602S4P4T1 I might be missing something that already exists since I am still learning ESC. However, If esc had a method to set a current environment it would be a lot more flexible when it comes to using dynamic environments. If I could run something like
esc setenv org/project/environment
that would make it easier when it comes to running commands, troubleshooting, and dynamic development. For example, something like
esc run org/project/environment -- bash -lc -- "ts-node ./esc.ts"
where
esc.ts
is
Copy code
#!/usr/bin/env ts-node

/**
 * Runs the esc command with the ESC environment variable as the stack name.
 * Usage: yarn esc
 * Requires: ESC environment variable to be set.
 */

import { spawn } from 'child_process';

const escEnv = process.env.ESC;
if (!escEnv) {
  console.error('Error: ESC environment variable is not set.');
  process.exit(1);
}

const args = [
  'run',
  escEnv,
  '--',
  'bash',
  '-lc',
  'yarn develop:ssh',
];

const child = spawn('esc', args, {
  stdio: 'inherit',
  env: process.env,
});

child.on('exit', code => process.exit(code ?? 1));
could be simplified to
esc run yarn develop:ssh
f
Does
esc run org/project/environment -- yarn develop:ssh
work?
m
It does pass the env along but yarn was not using it in it's process unless I used bash -lc or manually added them once in yarn. but I think what I realized is esc provides environments and manages itself, it doesn't and shouldn't manage the environment beyond the process it spawns. However this lead me to learning about the automation-api so I am actually trying that now. I'm just not clear on how to make the automation api populate the pulumi.config object in code. I got to
Copy code
if (escEnv && stackName) {
    const envRef = project && env ? `${project}/${env}` : escEnv;
    const stackArgs: automation.InlineProgramArgs = {
      stackName,
      projectName,
      program: async () => {}, // No-op, just managing config
    };
    const stack = await automation.LocalWorkspace.createOrSelectStack(stackArgs);
    const currentEnvs = await stack.listEnvironments();
    if (!currentEnvs.includes(envRef)) {
      await stack.addEnvironments(envRef);
      console.log(`Added ESC environment '${envRef}' to stack '${stackName}'.`);
    }
  }
but I am not seeing it populate I am getting this in the console:
[acrStack] Pulumi config at stack start: {}
I assume that the problem is that LocalWorkspace is wrong but I havent found the right method or functions yet.
Copy code
Run yarn ts-node index.ts --stack acr-infra
Added ESC environment 'marketforge/scouten' to stack 'setup-acr-infra'.
[index.ts] ENV_ESC: ajwtech/marketforge/scouten
[index.ts] GITHUB_JOB: setup-acr-infra
[acrStack] Pulumi config at stack start: {}
ConfigMissingError: Missing required configuration variable 'project:location'
	please set a value using the command `pulumi config set project:location <value>`
    at Config.requireImpl (/__w/MarketForge/MarketForge/azure-deploy/node_modules/@pulumi/config.ts:301:19)
    at Config.require (/__w/MarketForge/MarketForge/azure-deploy/node_modules/@pulumi/config.ts:313:21)
    at Object.<anonymous> (/__w/MarketForge/MarketForge/azure-deploy/infrastructure/resourceGroup.ts:5:25)
    at Module._compile (node:internal/modules/cjs/loader:1730:14)
    at Module.m._compile (/__w/MarketForge/MarketForge/azure-deploy/node_modules/ts-node/src/index.ts:1618:23)
    at node:internal/modules/cjs/loader:1895:10
    at Object.require.extensions.<computed> [as .ts] (/__w/MarketForge/MarketForge/azure-deploy/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1465:32)
    at Function._load (node:internal/modules/cjs/loader:1282:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14) {
  __pulumiRunError: true,
  key: 'project:location',
  secret: false
}
Error: Process completed with exit code