https://pulumi.com logo
Title
f

full-dress-10026

05/13/2021, 7:19 PM
Is there a way to get the Pulumi version in Typescript?
Interested in this to ensure that my pulumi program is only ran with a particular version.
I don't think that property is exported though.
It's in the docs though 🤔
c

cool-egg-852

05/13/2021, 7:32 PM
Wouldn’t setting a specific version in
package.json
solve this for you?
r

red-match-15116

05/13/2021, 7:36 PM
You can get this with automation api. It’s a property on LocalWorkspace https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/pulumi/automation/#LocalWorkspace-pulumiVersion
f

full-dress-10026

05/13/2021, 7:36 PM
For me but not if other devs are also running pulumi up.
I'd like to, for example, ensure that any dev running pulumi up has exactly v3.2.1.
This is similar to Terraform version constraints: https://www.terraform.io/docs/language/expressions/version-constraints.html
I can do this myself but it'd be cool to have it built in.
export function ensureVersionMatches(desiredVersion: string) {
    const result = proc.spawnSync("pulumi", ["version"], {
        stdio: ["pipe", "pipe", "inherit"]
    });
    if (result.status != 0) {
        throw new pulumi.RunError(`Pulumi version check exited with non-zero status ${result.status}.`)
    }
    const versionString = String(result.stdout)
    if (versionString != desiredVersion) {
        throw new pulumi.RunError(`Pulumi current version ${versionString} does not match desired version ${desiredVersion}`)
    }
    return versionString
}