Skip to content

Commit

Permalink
Pulumi updates (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs committed May 16, 2024
2 parents 030c532 + dcca572 commit a75b7dd
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 1 deletion.
1 change: 1 addition & 0 deletions actions/plan/src/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ async function run() {
core.endGroup()
}

core.startGroup('Plan created')
core.info('\n')
core.info(`Created following plan: \n${JSON.stringify(matrixInclude, null, 2)}`)
core.setOutput('matrix', {
Expand Down
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)
43 changes: 43 additions & 0 deletions packages/pulumi/src/executors/config/config.impl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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
path?: 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.path && `--path`,
options.name && options.value && `"${options.name}" "${options.value}"`,
options.stack && `--stack=${options.stack}`
]), {
cwd: join(workspaceRoot, options.root ?? sourceRoot),
stdio: 'inherit'
})

return { success: true }
}
37 changes: 37 additions & 0 deletions packages/pulumi/src/executors/config/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"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
}
},
"path": {
"type": "boolean"
},
"secret": {
"type": "boolean"
},
"name": {
"type": "string"
},
"value": {
"type": "string"
}
}
}
5 changes: 4 additions & 1 deletion packages/pulumi/src/executors/preview/preview.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { which } from 'shelljs'
export interface PreviewOptions {
stack?: string
root?: string

expectNoChanges?: boolean
}

export default async function creatExecutor(
Expand All @@ -22,7 +24,8 @@ export default async function creatExecutor(
execSync(buildCommand([
'PULUMI_EXPERIMENTAL=true',
'pulumi preview --diff --suppress-progress',
options.stack && `--stack=${options.stack}`
options.stack && `--stack=${options.stack}`,
options.expectNoChanges && '--expect-no-changes'
]), {
cwd: join(workspaceRoot, options.root ?? sourceRoot),
stdio: 'inherit'
Expand Down
3 changes: 3 additions & 0 deletions packages/pulumi/src/executors/preview/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"root": {
"type": "string",
"description": "The working directory to run Pulumi commands from, if specified."
},
"expectNoChanges": {
"type": "boolean"
}
}
}

0 comments on commit a75b7dd

Please sign in to comment.