Skip to content

Commit

Permalink
feat: Added init options -upgrade and -migrate-state to init target. (#…
Browse files Browse the repository at this point in the history
…198)

Just corrected `schema.json` file for the format executor and enhanced
the init executor to be able to pass the `-upgrade` and `-migrate-state`
options.
  • Loading branch information
TriPSs authored Dec 15, 2023
2 parents 5f6da97 + dabe05a commit 614d429
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/terraform/src/executors/fmt/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"title": "Format executor",
"description": "Format",
"properties": {
"write": {
"formatWrite": {
"type": "boolean",
"title": "Write to file",
"description": "Write to file",
Expand Down
19 changes: 16 additions & 3 deletions packages/terraform/src/executors/init/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@
"outputCapture": "direct-nodejs",
"$schema": "http://json-schema.org/schema",
"type": "object",
"title": "Plan executor",
"description": "Plan",
"properties": {}
"title": "Init executor",
"description": "Init",
"properties": {
"upgrade": {
"type": "boolean",
"title": "Install the latest module and provider versions.",
"description": "Install the latest module and provider versions allowed within configured constraints, overriding the default behavior of selecting exactly the version recorded in the dependency lockfile.",
"default": false
},
"migrate-state": {
"type": "boolean",
"title": "Reconfigure a backend, and attempt to migrate any existing state.",
"description": "Reconfigure a backend, and attempt to migrate any existing state.",
"default": false
}
}
}
7 changes: 5 additions & 2 deletions packages/terraform/src/generators/init/init.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export default async function (
initialize: {
executor: '@nx-extend/terraform:init',
options: {
ciMode: true
ciMode: true,
upgrade: false,
migrateState: false
}
},
providers: {
Expand All @@ -61,7 +63,8 @@ export default async function (
fmt: {
executor: '@nx-extend/terraform:fmt',
options: {
ciMode: true
ciMode: true,
formatWrite: false
}
},
apply: {
Expand Down
8 changes: 6 additions & 2 deletions packages/terraform/src/utils/create-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export interface ExecutorOptions {
autoApproval: boolean
planFile: string
ciMode: boolean
formatWrite: boolean
upgrade: boolean
migrateState: boolean

[key: string]: string | unknown
}
Expand All @@ -22,7 +25,7 @@ export function createExecutor(command: string) {
}

const { sourceRoot } = context.workspace.projects[context.projectName]
const { backendConfig = [], planFile, ciMode, autoApproval, formatWrite } = options
const { backendConfig = [], planFile, ciMode, autoApproval, formatWrite, upgrade, migrateState } = options

let env = {}
if (ciMode) {
Expand All @@ -45,7 +48,8 @@ export function createExecutor(command: string) {
command === 'apply' && planFile,
command === 'fmt' && '--recursive',
command === 'fmt' && !formatWrite && '--check --list',
command === 'fmt' && formatWrite && '--write --diff'
command === 'init' && upgrade && '-upgrade',
command === 'init' && migrateState && '-migrate-state',
]),
{
cwd: sourceRoot,
Expand Down

0 comments on commit 614d429

Please sign in to comment.