Skip to content
This repository was archived by the owner on Dec 2, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/terraform/src/executors/apply/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default async function runExecutor(
context: ExecutorContext,
) {
const cmdopt = ["-input=false", "-auto-approve", ...toCmdOptions(options)]
return runTfCommand(context, "apply", cmdopt)
return runTfCommand(context, "apply", cmdopt, options.allowedExitCodes)
}

function toCmdOptions(options: ApplyExecutorSchema): string[] {
Expand Down
1 change: 1 addition & 0 deletions packages/terraform/src/executors/apply/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export interface ApplyExecutorSchema {
lockTimeout?: string
noColor?: boolean
parallelism?: number
allowedExitCodes?: number[]
}
9 changes: 8 additions & 1 deletion packages/terraform/src/executors/apply/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
"title": "Apply executor",
"description": "",
"type": "object",
"properties": {},
"properties": {
"allowedExitCodes": {
"type": "array",
"items": {
"type": "number"
}
}
},
"required": []
}
2 changes: 1 addition & 1 deletion packages/terraform/src/executors/fmt/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default async function runExecutor(
context: ExecutorContext,
) {
const cmdopt = toCmdOptions(options)
return runTfCommand(context, "fmt", cmdopt)
return runTfCommand(context, "fmt", cmdopt, options.allowedExitCodes)
}

function toCmdOptions(options: FmtExecutorSchema): string[] {
Expand Down
1 change: 1 addition & 0 deletions packages/terraform/src/executors/fmt/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface FmtExecutorSchema {
diff?: boolean
check?: boolean
recursive?: boolean
allowedExitCodes?: number[]
}
9 changes: 8 additions & 1 deletion packages/terraform/src/executors/fmt/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
"title": "Fmt executor",
"description": "The terraform fmt executor is used to rewrite Terraform configuration files to a canonical format and style.",
"type": "object",
"properties": {},
"properties": {
"allowedExitCodes": {
"type": "array",
"items": {
"type": "number"
}
}
},
"required": []
}
2 changes: 1 addition & 1 deletion packages/terraform/src/executors/init/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default async function runExecutor(
context: ExecutorContext,
) {
const cmdopt = ["-input=false", ...toCmdOptions(options)]
return runTfCommand(context, "init", cmdopt)
return runTfCommand(context, "init", cmdopt, options.allowedExitCodes)
}

function toCmdOptions(options: InitExecutorSchema ): string[] {
Expand Down
1 change: 1 addition & 0 deletions packages/terraform/src/executors/init/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface InitExecutorSchema {
lock?: boolean
lockTimeout?: string
upgrade?: boolean
allowedExitCodes?: number[]
}


9 changes: 8 additions & 1 deletion packages/terraform/src/executors/init/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
"title": "Init executor",
"description": "",
"type": "object",
"properties": {},
"properties": {
"allowedExitCodes": {
"type": "array",
"items": {
"type": "number"
}
}
},
"required": []
}
2 changes: 1 addition & 1 deletion packages/terraform/src/executors/plan/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default async function runExecutor(
context: ExecutorContext,
) {
const cmdopt = ["-input=false", ...toCmdOptions(options)]
return runTfCommand(context, "plan", cmdopt)
return runTfCommand(context, "plan", cmdopt, options.allowedExitCodes)
}

function toCmdOptions(options: PlanExecutorSchema ): string[] {
Expand Down
1 change: 1 addition & 0 deletions packages/terraform/src/executors/plan/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export interface PlanExecutorSchema {
noColor?: boolean
out?: string
parallelism?: number
allowedExitCodes?: number[]
}
9 changes: 8 additions & 1 deletion packages/terraform/src/executors/plan/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
"title": "Plan executor",
"description": "The plan executor creates an execution plan, which lets you preview the changes that Terraform plans to make to your infrastructure.",
"type": "object",
"properties": {},
"properties": {
"allowedExitCodes": {
"type": "array",
"items": {
"type": "number"
}
}
},
"required": []
}
2 changes: 1 addition & 1 deletion packages/terraform/src/executors/validate/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default async function runExecutor(
context: ExecutorContext,
) {
const cmdopt = toCmdOptions(options)
return runTfCommand(context, "validate", cmdopt)
return runTfCommand(context, "validate", cmdopt, options.allowedExitCodes)
}

function toCmdOptions(options: ValidateExecutorSchema): string[] {
Expand Down
1 change: 1 addition & 0 deletions packages/terraform/src/executors/validate/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface ValidateExecutorSchema {
json?: boolean
noColor?: boolean
allowedExitCodes?: number[]
}
9 changes: 8 additions & 1 deletion packages/terraform/src/executors/validate/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
"title": "Validate executor",
"description": "Runs static checks analysis.",
"type": "object",
"properties": {},
"properties": {
"allowedExitCodes": {
"type": "array",
"items": {
"type": "number"
}
}
},
"required": []
}
5 changes: 4 additions & 1 deletion packages/terraform/src/utils/run-tf-command.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export function runTfCommand(
context: ExecutorContext,
command: 'init' | 'plan' | 'fmt' | 'validate' | 'apply',
params: string[],
allowedExitCodes: number[] = [0],
): { success: boolean } {
const cwd = context?.projectsConfigurations?.projects[context.projectName]?.sourceRoot || process.cwd()

Expand All @@ -17,6 +18,8 @@ export function runTfCommand(
return { success: true }
} catch (e) {
console.error(`Failed to execute command: ${execute}`, e)
return { success: false }
// we can access error code as the error object will contain entire object from:
// https://nodejs.org/api/child_process.html#child_processspawnsynccommand-args-options
return { success: allowedExitCodes.includes(e.status) }
}
}