Skip to content

Commit

Permalink
feat(pulumi): Added config executor
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs committed May 16, 2024
1 parent 59a9f9f commit 970507f
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/pulumi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,15 @@ nx g @nx-extend/pulumi:init

| name | type | default | description |
|------|------|---------|-------------|

### Config

Set config variable:
```bash
nx config <project-name> set --name="<name>" --value="<value>"
```

Set secret config variable:
```bash
nx config <project-name> set --secret --name="<name>" --value="<value>"
```
10 changes: 10 additions & 0 deletions packages/pulumi/executors.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
"implementation": "./src/executors/import/import.impl",
"schema": "./src/executors/import/schema.json",
"description": "import executor"
},
"config": {
"implementation": "./src/executors/config/config.impl",
"schema": "./src/executors/config/schema.json",
"description": "config executor"
}
},
"builders": {
Expand All @@ -41,6 +46,11 @@
"implementation": "./src/executors/import/import.impl",
"schema": "./src/executors/import/schema.json",
"description": "import executor"
},
"config": {
"implementation": "./src/executors/config/config.impl",
"schema": "./src/executors/config/schema.json",
"description": "config executor"
}
}
}
5 changes: 5 additions & 0 deletions packages/pulumi/src/executors/config/compat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { convertNxExecutor } from '@nx/devkit'

import configExecutor from './config.impl'

export default convertNxExecutor(configExecutor)
41 changes: 41 additions & 0 deletions packages/pulumi/src/executors/config/config.impl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { ExecutorContext, workspaceRoot } from '@nx/devkit'
import { buildCommand } from '@nx-extend/core'
import { execSync } from 'child_process'
import { join } from 'path'
import { which } from 'shelljs'

export interface PreviewOptions {
stack?: string
root?: string
parent?: string

action: string
secret?: boolean
name?: string
value?: string
}

export default async function configExecutor(
options: PreviewOptions,
context: ExecutorContext
): Promise<{ success: boolean }> {
if (!which('pulumi')) {
throw new Error('pulumi is not installed!')
}

const { sourceRoot } = context.workspace.projects[context.projectName]

execSync(buildCommand([
'PULUMI_EXPERIMENTAL=true',
'pulumi config',
options.action,
options.secret && `--secret`,
options.name && options.value && `"${options.name}" "${options.value}"`,
options.stack && `--stack=${options.stack}`
]), {
cwd: join(workspaceRoot, options.root ?? sourceRoot),
stdio: 'inherit'
})

return { success: true }
}
34 changes: 34 additions & 0 deletions packages/pulumi/src/executors/config/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"version": 2,
"outputCapture": "direct-nodejs",
"$schema": "https://json-schema.org/schema",
"type": "object",
"title": "Preview executor",
"description": "Preview",
"properties": {
"stack": {
"type": "string",
"description": "The target stack to use, if specified."
},
"root": {
"type": "string",
"description": "The working directory to run Pulumi commands from, if specified."
},
"action": {
"type": "string",
"$default": {
"$source": "argv",
"index": 0
}
},
"secret": {
"type": "boolean"
},
"name": {
"type": "string"
},
"value": {
"type": "string"
}
}
}

0 comments on commit 970507f

Please sign in to comment.