Skip to content

Commit

Permalink
feat(terraform): add support for validate and test terraform commands (
Browse files Browse the repository at this point in the history
…#241)

This PR adds new support for `terraform validate` and `terraform test`
executors and fixes issue #240
  • Loading branch information
TriPSs authored Mar 11, 2024
2 parents 1fb2544 + 87d15c5 commit 6fd4e8d
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/terraform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ nx run <terraform-project-name>:providers
nx run <terraform-project-name>:plan
nx run <terraform-project-name>:apply
nx run <terraform-project-name>:destroy
nx run <terraform-project-name>:validate
nx run <terraform-project-name>:test
```

#### Available options:
Expand Down
20 changes: 20 additions & 0 deletions packages/terraform/executors.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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"
}
}
}
5 changes: 5 additions & 0 deletions packages/terraform/src/executors/test/compat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { convertNxExecutor } from '@nx/devkit'

import testExecutor from './test.impl'

export default convertNxExecutor(testExecutor)
9 changes: 9 additions & 0 deletions packages/terraform/src/executors/test/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": 2,
"outputCapture": "direct-nodejs",
"$schema": "http://json-schema.org/schema",
"type": "object",
"title": "Test executor",
"description": "Test",
"properties": {}
}
3 changes: 3 additions & 0 deletions packages/terraform/src/executors/test/test.impl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createExecutor } from '../../utils/create-executor'

export default createExecutor('test')
5 changes: 5 additions & 0 deletions packages/terraform/src/executors/validate/compat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { convertNxExecutor } from '@nx/devkit'

import validateExecutor from './validate.impl'

export default convertNxExecutor(validateExecutor)
10 changes: 10 additions & 0 deletions packages/terraform/src/executors/validate/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": 2,
"outputCapture": "direct-nodejs",
"$schema": "http://json-schema.org/schema",
"type": "object",
"title": "Validate executor",
"description": "Validate",
"properties": {}
}
}
3 changes: 3 additions & 0 deletions packages/terraform/src/executors/validate/validate.impl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createExecutor } from '../../utils/create-executor'

export default createExecutor('validate')
12 changes: 12 additions & 0 deletions packages/terraform/src/generators/init/init.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions packages/terraform/src/utils/create-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6fd4e8d

Please sign in to comment.