-
-
Save dixler/2ea418da0dab0b561f4e9e670e8c983f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
LocalProgramArgs, | |
LocalWorkspace, | |
LocalWorkspaceOptions, | |
} from '@pulumi/pulumi/automation'; | |
import { sys } from 'typescript'; | |
import { Commands } from './src/config'; | |
import * as pulumiCli from './src/libs/pulumi-cli'; | |
const core = console | |
const pulumiVersion = '^3'; | |
const main = async () => { | |
const config = { | |
stackName: "dev", | |
workDir: "/home/kdixler/Documents/issues/8710.pulumi", | |
command: sys.args[1], | |
options: { | |
}, | |
} | |
await pulumiCli.downloadCli(pulumiVersion); | |
core.debug(`Logging into to Pulumi`); | |
await pulumiCli.run('login'); | |
core.debug(`Working directory resolved at ${config.workDir}`); | |
const stackArgs: LocalProgramArgs = { | |
stackName: config.stackName, | |
workDir: config.workDir, | |
}; | |
const stackOpts: LocalWorkspaceOptions = {}; | |
const stack = await LocalWorkspace.createOrSelectStack(stackArgs, stackOpts) | |
const onOutput = (msg: string) => { | |
core.debug(msg); | |
core.info(msg); | |
}; | |
core.debug(`pulumi ${config.command} on ${config.stackName}`); | |
const actions: Record<Commands, () => Promise<string>> = { | |
up: () => stack.up({ onOutput, ...config.options }).then((r) => r.stdout), | |
update: () => | |
stack.up({ onOutput, ...config.options }).then((r) => r.stdout), | |
refresh: () => | |
stack.refresh({ onOutput, ...config.options }).then((r) => r.stdout), | |
destroy: () => | |
stack.destroy({ onOutput, ...config.options }).then((r) => r.stdout), | |
preview: async () => { | |
const { stdout, stderr } = await stack.preview(config.options); | |
onOutput(stdout); | |
onOutput(stderr); | |
return stdout; | |
}, | |
}; | |
actions[config.command]() | |
} | |
main() |
Author
dixler
commented
Jan 25, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment