Is there a way to get the Pulumi version in Typesc...
# general
f
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
Wouldn’t setting a specific version in
package.json
solve this for you?
r
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
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.
Copy code
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
}