From 87d15c5b840588e9e87cc65ed4272e62a1ad86dc Mon Sep 17 00:00:00 2001 From: John Mc Kenna <61982860+johnmckenna@users.noreply.github.com> Date: Mon, 11 Mar 2024 14:01:34 +0000 Subject: [PATCH] feat(terraform): add support for validate and test terraform commands --- packages/terraform/README.md | 2 ++ packages/terraform/executors.json | 20 +++++++++++++++++++ .../terraform/src/executors/test/compat.ts | 5 +++++ .../terraform/src/executors/test/schema.json | 9 +++++++++ .../terraform/src/executors/test/test.impl.ts | 3 +++ .../src/executors/validate/compat.ts | 5 +++++ .../src/executors/validate/schema.json | 10 ++++++++++ .../src/executors/validate/validate.impl.ts | 3 +++ .../src/generators/init/init.impl.ts | 12 +++++++++++ .../terraform/src/utils/create-executor.ts | 2 ++ 10 files changed, 71 insertions(+) create mode 100644 packages/terraform/src/executors/test/compat.ts create mode 100644 packages/terraform/src/executors/test/schema.json create mode 100644 packages/terraform/src/executors/test/test.impl.ts create mode 100644 packages/terraform/src/executors/validate/compat.ts create mode 100644 packages/terraform/src/executors/validate/schema.json create mode 100644 packages/terraform/src/executors/validate/validate.impl.ts diff --git a/packages/terraform/README.md b/packages/terraform/README.md index 43618381..c0f1c642 100644 --- a/packages/terraform/README.md +++ b/packages/terraform/README.md @@ -40,6 +40,8 @@ nx run :providers nx run :plan nx run :apply nx run :destroy +nx run :validate +nx run :test ``` #### Available options: diff --git a/packages/terraform/executors.json b/packages/terraform/executors.json index 49dbccdb..05af9b46 100644 --- a/packages/terraform/executors.json +++ b/packages/terraform/executors.json @@ -29,6 +29,16 @@ "implementation": "./src/executors/providers/providers.impl", "schema": "./src/executors/providers/schema.json", "description": "providers executor" + }, + "validate": { + "implementation": "./src/executors/validate/validate.impl", + "schema": "./src/executors/validate/schema.json", + "description": "validate executor" + }, + "test": { + "implementation": "./src/executors/test/test.impl", + "schema": "./src/executors/test/schema.json", + "description": "test executor" } }, "builders": { @@ -61,6 +71,16 @@ "implementation": "./src/executors/providers/providers.impl", "schema": "./src/executors/providers/schema.json", "description": "providers executor" + }, + "validate": { + "implementation": "./src/executors/validate/validate.impl", + "schema": "./src/executors/validate/schema.json", + "description": "validate executor" + }, + "test": { + "implementation": "./src/executors/test/test.impl", + "schema": "./src/executors/test/schema.json", + "description": "test executor" } } } diff --git a/packages/terraform/src/executors/test/compat.ts b/packages/terraform/src/executors/test/compat.ts new file mode 100644 index 00000000..c2477c6e --- /dev/null +++ b/packages/terraform/src/executors/test/compat.ts @@ -0,0 +1,5 @@ +import { convertNxExecutor } from '@nx/devkit' + +import testExecutor from './test.impl' + +export default convertNxExecutor(testExecutor) diff --git a/packages/terraform/src/executors/test/schema.json b/packages/terraform/src/executors/test/schema.json new file mode 100644 index 00000000..22a9d561 --- /dev/null +++ b/packages/terraform/src/executors/test/schema.json @@ -0,0 +1,9 @@ +{ + "version": 2, + "outputCapture": "direct-nodejs", + "$schema": "http://json-schema.org/schema", + "type": "object", + "title": "Test executor", + "description": "Test", + "properties": {} +} diff --git a/packages/terraform/src/executors/test/test.impl.ts b/packages/terraform/src/executors/test/test.impl.ts new file mode 100644 index 00000000..4f588ceb --- /dev/null +++ b/packages/terraform/src/executors/test/test.impl.ts @@ -0,0 +1,3 @@ +import { createExecutor } from '../../utils/create-executor' + +export default createExecutor('test') diff --git a/packages/terraform/src/executors/validate/compat.ts b/packages/terraform/src/executors/validate/compat.ts new file mode 100644 index 00000000..1d78955c --- /dev/null +++ b/packages/terraform/src/executors/validate/compat.ts @@ -0,0 +1,5 @@ +import { convertNxExecutor } from '@nx/devkit' + +import validateExecutor from './validate.impl' + +export default convertNxExecutor(validateExecutor) diff --git a/packages/terraform/src/executors/validate/schema.json b/packages/terraform/src/executors/validate/schema.json new file mode 100644 index 00000000..24ccfb9d --- /dev/null +++ b/packages/terraform/src/executors/validate/schema.json @@ -0,0 +1,10 @@ +{ + "version": 2, + "outputCapture": "direct-nodejs", + "$schema": "http://json-schema.org/schema", + "type": "object", + "title": "Validate executor", + "description": "Validate", + "properties": {} + } +} diff --git a/packages/terraform/src/executors/validate/validate.impl.ts b/packages/terraform/src/executors/validate/validate.impl.ts new file mode 100644 index 00000000..82774965 --- /dev/null +++ b/packages/terraform/src/executors/validate/validate.impl.ts @@ -0,0 +1,3 @@ +import { createExecutor } from '../../utils/create-executor' + +export default createExecutor('validate') diff --git a/packages/terraform/src/generators/init/init.impl.ts b/packages/terraform/src/generators/init/init.impl.ts index 9f5e34b4..b98283d0 100644 --- a/packages/terraform/src/generators/init/init.impl.ts +++ b/packages/terraform/src/generators/init/init.impl.ts @@ -82,6 +82,18 @@ export default async function ( ciMode: true, autoApproval: false } + }, + validate: { + executor: '@nx-extend/terraform:validate', + options: { + ciMode: true + } + }, + test: { + executor: '@nx-extend/terraform:test', + options: { + ciMode: true + } } }, tags: options.parsedTags diff --git a/packages/terraform/src/utils/create-executor.ts b/packages/terraform/src/utils/create-executor.ts index 1319af1c..d0349aae 100644 --- a/packages/terraform/src/utils/create-executor.ts +++ b/packages/terraform/src/utils/create-executor.ts @@ -54,6 +54,8 @@ export function createExecutor(command: string) { command === 'init' && upgrade && '-upgrade', command === 'init' && migrateState && '-migrate-state', command === 'providers' && lock && 'lock', + command === 'validate', + command === 'test' && varFile && `--var-file ${varFile}`, ]), { cwd: sourceRoot,