Skip to content

Commit

Permalink
Feat/pass env vars to pulumi up executor (#101)
Browse files Browse the repository at this point in the history
* Pass custom envvars to up executor

* changeset

* pin pnpm to v6, upgrade node + pnpm in future
  • Loading branch information
PatrickMilroy authored Aug 17, 2023
1 parent 13b90f0 commit 0bdd538
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/violet-suns-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@wanews/nx-pulumi': minor
---

Allow passing in Environment Variables by `--envVars=` arguement
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:

- name: Install pnpm
run: |
npm i -g pnpm
npm i -g pnpm@6
pnpm set verify-store-integrity false
- name: pnpm install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

- name: Install pnpm
run: |
npm i -g pnpm
npm i -g pnpm@6
pnpm set verify-store-integrity false
- name: pnpm install
run: |
Expand Down
8 changes: 8 additions & 0 deletions libs/pulumi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ nx up my-app-infrastructure --stack dev

Will create the stack name by prefixing the pulumi project name. ie `--env=prod` is the same as `--stack=<projectname>.prod`.

#### Environment Variables

`--envVars="KEY=value`

Passes through a comma-seperated list of environment variables to the pulumi command

For example, if you need to build docker images built by pulumi to target a specific architechure CPU architechure (eg `linux/amd64`), you can the add arguement `--envVars="DOCKER_DEFAULT_PLATFORM=linux/amd64"`

## Running deploy

@wanews/nx-pulumi will add a `deploy` target to the selected project. This will start pulumi with a `--cwd` of the infrastructure project automatically
Expand Down
11 changes: 11 additions & 0 deletions libs/pulumi/src/executors/up/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ export default async function runUpExecutor(
}
}

const envObject: {
[key: string]: string
} = {}

options.envVars?.forEach((envVar) => {
const [key, value] = envVar.split('=')
envObject[key] = value
})

const pulumiArgs = [
'up',
'--cwd',
Expand All @@ -83,8 +92,10 @@ export default async function runUpExecutor(
]

console.log(`> pulumi ${pulumiArgs.join(' ')}`)
console.log(`${options.envVars}`)
const pulumi = execa('pulumi', pulumiArgs, {
stdio: [process.stdin, process.stdout, process.stderr],
env: envObject,
})
try {
const res = await pulumi
Expand Down
1 change: 1 addition & 0 deletions libs/pulumi/src/executors/up/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export interface UpExecutorSchema {
environment?: string
stack?: string
refresh?: boolean
envVars?: string[]
}
16 changes: 9 additions & 7 deletions libs/pulumi/src/executors/up/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
"environment": {
"description": "",
"type": "string",
"aliases": [
"env"
]
"aliases": ["env"]
},
"stack": {
"description": "Pulumi stack name",
Expand All @@ -35,10 +33,7 @@
"type": "string"
}
},
"required": [
"project",
"target"
]
"required": ["project", "target"]
}
},
"configurationStackFormat": {
Expand All @@ -58,6 +53,13 @@
},
"refresh": {
"type": "boolean"
},
"envVars": {
"description": "Array of Environment Variables",
"type": "array",
"items": {
"type": "string"
}
}
}
}

0 comments on commit 0bdd538

Please sign in to comment.