diff --git a/packages/terraform/executors.json b/packages/terraform/executors.json index 86d7d3c2..5b39dcab 100644 --- a/packages/terraform/executors.json +++ b/packages/terraform/executors.json @@ -1,5 +1,10 @@ { "executors": { + "fmt": { + "implementation": "./src/executors/fmt/fmt.impl", + "schema": "./src/executors/fmt/schema.json", + "description": "fmt executor" + }, "plan": { "implementation": "./src/executors/plan/plan.impl", "schema": "./src/executors/plan/schema.json", @@ -17,6 +22,11 @@ } }, "builders": { + "fmt": { + "implementation": "./src/executors/fmt/fmt.impl", + "schema": "./src/executors/fmt/schema.json", + "description": "fmt executor" + }, "plan": { "implementation": "./src/executors/plan/plan.impl", "schema": "./src/executors/plan/schema.json", diff --git a/packages/terraform/src/executors/fmt/compat.ts b/packages/terraform/src/executors/fmt/compat.ts new file mode 100644 index 00000000..5d41bb65 --- /dev/null +++ b/packages/terraform/src/executors/fmt/compat.ts @@ -0,0 +1,5 @@ +import { convertNxExecutor } from '@nx/devkit' + +import fmtExecutor from './fmt.impl' + +export default convertNxExecutor(fmtExecutor) diff --git a/packages/terraform/src/executors/fmt/fmt.impl.ts b/packages/terraform/src/executors/fmt/fmt.impl.ts new file mode 100644 index 00000000..e9129664 --- /dev/null +++ b/packages/terraform/src/executors/fmt/fmt.impl.ts @@ -0,0 +1,3 @@ +import { createExecutor } from '../../utils/create-executor' + +export default createExecutor('fmt') diff --git a/packages/terraform/src/executors/fmt/schema.json b/packages/terraform/src/executors/fmt/schema.json new file mode 100644 index 00000000..703518d9 --- /dev/null +++ b/packages/terraform/src/executors/fmt/schema.json @@ -0,0 +1,16 @@ +{ + "version": 2, + "outputCapture": "direct-nodejs", + "$schema": "http://json-schema.org/schema", + "type": "object", + "title": "Format executor", + "description": "Format", + "properties": { + "write": { + "type": "boolean", + "title": "Write to file", + "description": "Write to file", + "default": false + } + } +} diff --git a/packages/terraform/src/utils/create-executor.ts b/packages/terraform/src/utils/create-executor.ts index bbc7d23a..b2d56203 100644 --- a/packages/terraform/src/utils/create-executor.ts +++ b/packages/terraform/src/utils/create-executor.ts @@ -22,7 +22,7 @@ export function createExecutor(command: string) { } const { sourceRoot } = context.workspace.projects[context.projectName] - const { backendConfig = [], planFile, ciMode, autoApproval } = options + const { backendConfig = [], planFile, ciMode, autoApproval, formatWrite } = options let env = {} if (ciMode) { @@ -41,7 +41,10 @@ export function createExecutor(command: string) { ), command === 'plan' && planFile && `-out ${planFile}`, command === 'apply' && autoApproval && '-auto-approve', - command === 'apply' && planFile + command === 'apply' && planFile, + command === 'fmt' && '--recursive', + command === 'fmt' && !formatWrite && '--check --list', + command === 'fmt' && formatWrite && '--write --diff' ]), { cwd: sourceRoot,