Skip to content

Commit

Permalink
feat(pulumi): Added import executor (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs committed May 15, 2024
2 parents 8ce59d8 + 09064e5 commit 46103ff
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/pulumi/executors.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"implementation": "./src/executors/refresh/refresh.impl",
"schema": "./src/executors/refresh/schema.json",
"description": "refresh executor"
},
"import": {
"implementation": "./src/executors/import/import.impl",
"schema": "./src/executors/import/schema.json",
"description": "import executor"
}
},
"builders": {
Expand All @@ -31,6 +36,11 @@
"implementation": "./src/executors/refresh/refresh.impl",
"schema": "./src/executors/refresh/schema.json",
"description": "refresh executor"
},
"import": {
"implementation": "./src/executors/import/import.impl",
"schema": "./src/executors/import/schema.json",
"description": "import executor"
}
}
}
5 changes: 5 additions & 0 deletions packages/pulumi/src/executors/import/compat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { convertNxExecutor } from '@nx/devkit'

import importExecutor from './import.impl'

export default convertNxExecutor(importExecutor)
40 changes: 40 additions & 0 deletions packages/pulumi/src/executors/import/import.impl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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
target: string
name: string
id: string
parent?: string
}

export default async function creatExecutor(
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 import',
options.target,
options.name,
options.id,
options.parent && `--parent 'parent=${options.parent}'`,
options.stack && `--stack=${options.stack}`
]), {
cwd: join(workspaceRoot, options.root ?? sourceRoot),
stdio: 'inherit'
})

return { success: true }
}
39 changes: 39 additions & 0 deletions packages/pulumi/src/executors/import/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"version": 2,
"outputCapture": "direct-nodejs",
"$schema": "http://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."
},
"target": {
"type": "string",
"$default": {
"$source": "argv",
"index": 0
}
},
"name": {
"type": "string",
"$default": {
"$source": "argv",
"index": 1
}
},
"id": {
"type": "string",
"$default": {
"$source": "argv",
"index": 2
}
}
}
}
4 changes: 4 additions & 0 deletions packages/pulumi/src/generators/init/init.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export default async function (tree: Tree, rawOptions: InitOptions) {
refresh: {
executor: '@nx-extend/pulumi:refresh',
options: {}
},
import: {
executor: '@nx-extend/pulumi:import',
options: {}
}
},
tags: options.parsedTags
Expand Down

0 comments on commit 46103ff

Please sign in to comment.