diff --git a/actions/plan/src/plan.ts b/actions/plan/src/plan.ts index 495f2d2b..35e9cacc 100644 --- a/actions/plan/src/plan.ts +++ b/actions/plan/src/plan.ts @@ -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', { diff --git a/packages/pulumi/README.md b/packages/pulumi/README.md index a6ee59fb..1db55731 100644 --- a/packages/pulumi/README.md +++ b/packages/pulumi/README.md @@ -23,3 +23,15 @@ nx g @nx-extend/pulumi:init | name | type | default | description | |------|------|---------|-------------| + +### Config + +Set config variable: +```bash +nx config set --name="" --value="" +``` + +Set secret config variable: +```bash +nx config set --secret --name="" --value="" +``` diff --git a/packages/pulumi/executors.json b/packages/pulumi/executors.json index 221e9983..2dc479c7 100644 --- a/packages/pulumi/executors.json +++ b/packages/pulumi/executors.json @@ -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": { @@ -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" } } } diff --git a/packages/pulumi/src/executors/config/compat.ts b/packages/pulumi/src/executors/config/compat.ts new file mode 100644 index 00000000..786036ee --- /dev/null +++ b/packages/pulumi/src/executors/config/compat.ts @@ -0,0 +1,5 @@ +import { convertNxExecutor } from '@nx/devkit' + +import configExecutor from './config.impl' + +export default convertNxExecutor(configExecutor) diff --git a/packages/pulumi/src/executors/config/config.impl.ts b/packages/pulumi/src/executors/config/config.impl.ts new file mode 100644 index 00000000..68797cac --- /dev/null +++ b/packages/pulumi/src/executors/config/config.impl.ts @@ -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 } +} diff --git a/packages/pulumi/src/executors/config/schema.json b/packages/pulumi/src/executors/config/schema.json new file mode 100644 index 00000000..1c111b04 --- /dev/null +++ b/packages/pulumi/src/executors/config/schema.json @@ -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" + } + } +} diff --git a/packages/pulumi/src/executors/preview/preview.impl.ts b/packages/pulumi/src/executors/preview/preview.impl.ts index 874c3610..e6e9419e 100644 --- a/packages/pulumi/src/executors/preview/preview.impl.ts +++ b/packages/pulumi/src/executors/preview/preview.impl.ts @@ -7,6 +7,8 @@ import { which } from 'shelljs' export interface PreviewOptions { stack?: string root?: string + + expectNoChanges?: boolean } export default async function creatExecutor( @@ -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' diff --git a/packages/pulumi/src/executors/preview/schema.json b/packages/pulumi/src/executors/preview/schema.json index 100c5a9e..f1a7a2a4 100644 --- a/packages/pulumi/src/executors/preview/schema.json +++ b/packages/pulumi/src/executors/preview/schema.json @@ -13,6 +13,9 @@ "root": { "type": "string", "description": "The working directory to run Pulumi commands from, if specified." + }, + "expectNoChanges": { + "type": "boolean" } } }