Skip to content

Commit

Permalink
- Added type check for backendConfig (#287)
Browse files Browse the repository at this point in the history
- Parse backendConfig if its type is string
- Added "reconfigure" parameter for the "init" command
  • Loading branch information
TriPSs authored Jun 20, 2024
2 parents ca0dcf9 + cff918e commit 824ea02
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions packages/terraform/src/utils/create-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface ExecutorOptions {
lock: boolean
varFile: string
varString: string
reconfigure: boolean

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

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

let env = {}
if (ciMode) {
Expand All @@ -38,11 +51,16 @@ export function createExecutor(command: string) {
}
}

let jsonBackendConfig = backendConfig
if (typeof jsonBackendConfig === 'string') {
jsonBackendConfig = JSON.parse(jsonBackendConfig)
}

execSync(
buildCommand([
'terraform',
command,
...backendConfig.map(
...jsonBackendConfig.map(
(config) => `-backend-config="${config.key}=${config.name}"`
),
command === 'plan' && planFile && `-out ${planFile}`,
Expand All @@ -56,9 +74,10 @@ export function createExecutor(command: string) {
command === 'fmt' && !formatWrite && '--check --list',
command === 'init' && upgrade && '-upgrade',
command === 'init' && migrateState && '-migrate-state',
command === 'init' && reconfigure && '-reconfigure',
command === 'providers' && lock && 'lock',
command === 'test' && varFile && `--var-file ${varFile}`,
command === 'test' && varString && `--var ${varString}`,
command === 'test' && varString && `--var ${varString}`
]),
{
cwd: sourceRoot,
Expand Down

0 comments on commit 824ea02

Please sign in to comment.