Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pulumi): Added import executor #269

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading