Skip to content

Commit

Permalink
feat(terraform): add nx executors for terraform format command (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs authored Sep 11, 2023
2 parents 3b850f8 + 132a329 commit 3e1f76c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/terraform/executors.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions packages/terraform/src/executors/fmt/compat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { convertNxExecutor } from '@nx/devkit'

import fmtExecutor from './fmt.impl'

export default convertNxExecutor(fmtExecutor)
3 changes: 3 additions & 0 deletions packages/terraform/src/executors/fmt/fmt.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('fmt')
16 changes: 16 additions & 0 deletions packages/terraform/src/executors/fmt/schema.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
7 changes: 5 additions & 2 deletions packages/terraform/src/utils/create-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down

0 comments on commit 3e1f76c

Please sign in to comment.