From d7cef7400552109474f2203b38058a5b52d26a93 Mon Sep 17 00:00:00 2001 From: Sebastian Korfmann Date: Mon, 24 Aug 2020 19:56:18 +0200 Subject: [PATCH 1/2] Terraform in automation mode This skips all interactive inputs and fails immediately if there's data missing See https://learn.hashicorp.com/tutorials/terraform/automate-terraform#terraform-init-input-false-2 Fixes #250 --- packages/cdktf-cli/bin/cmds/ui/models/terraform.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/cdktf-cli/bin/cmds/ui/models/terraform.ts b/packages/cdktf-cli/bin/cmds/ui/models/terraform.ts index 792a1b4762..b2c500cc37 100644 --- a/packages/cdktf-cli/bin/cmds/ui/models/terraform.ts +++ b/packages/cdktf-cli/bin/cmds/ui/models/terraform.ts @@ -84,12 +84,12 @@ export class Terraform { public async init(): Promise { await this.setUserAgent() - await exec(terraformBinaryName, ['init'], { cwd: this.workdir, env: process.env }) + await exec(terraformBinaryName, ['init', '-input', 'false'], { cwd: this.workdir, env: process.env }) } public async plan(destroy = false): Promise { const planFile = path.join(this.workdir, 'plan') - const options = ['plan', '-out', planFile, ...this.stateFileOption] + const options = ['plan', '-input', 'false', '-out', planFile, ...this.stateFileOption] if (destroy) { options.push('-destroy') } @@ -102,12 +102,12 @@ export class Terraform { public async deploy(planFile: string, stdout: (chunk: Buffer) => any): Promise { const relativePlanFile = path.relative(this.workdir, planFile); await this.setUserAgent() - await exec(terraformBinaryName, ['apply', '-auto-approve', ...this.stateFileOption, relativePlanFile], { cwd: this.workdir, env: process.env }, stdout); + await exec(terraformBinaryName, ['apply', '-auto-approve', '-input', 'false', ...this.stateFileOption, relativePlanFile], { cwd: this.workdir, env: process.env }, stdout); } public async destroy(stdout: (chunk: Buffer) => any): Promise { await this.setUserAgent() - await exec(terraformBinaryName, ['destroy', '-auto-approve', ...this.stateFileOption], { cwd: this.workdir, env: process.env }, stdout); + await exec(terraformBinaryName, ['destroy', '-auto-approve', '-input', 'false', ...this.stateFileOption], { cwd: this.workdir, env: process.env }, stdout); } public async version(): Promise { From 9f0946ab1cada7c77f453159c8e1d710d1ebb0d9 Mon Sep 17 00:00:00 2001 From: Sebastian Korfmann Date: Mon, 24 Aug 2020 20:19:10 +0200 Subject: [PATCH 2/2] Compact to one argument --- packages/cdktf-cli/bin/cmds/ui/models/terraform.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/cdktf-cli/bin/cmds/ui/models/terraform.ts b/packages/cdktf-cli/bin/cmds/ui/models/terraform.ts index b2c500cc37..2349aeb811 100644 --- a/packages/cdktf-cli/bin/cmds/ui/models/terraform.ts +++ b/packages/cdktf-cli/bin/cmds/ui/models/terraform.ts @@ -84,12 +84,12 @@ export class Terraform { public async init(): Promise { await this.setUserAgent() - await exec(terraformBinaryName, ['init', '-input', 'false'], { cwd: this.workdir, env: process.env }) + await exec(terraformBinaryName, ['init', '-input=false'], { cwd: this.workdir, env: process.env }) } public async plan(destroy = false): Promise { const planFile = path.join(this.workdir, 'plan') - const options = ['plan', '-input', 'false', '-out', planFile, ...this.stateFileOption] + const options = ['plan', '-input=false', '-out', planFile, ...this.stateFileOption] if (destroy) { options.push('-destroy') } @@ -102,12 +102,12 @@ export class Terraform { public async deploy(planFile: string, stdout: (chunk: Buffer) => any): Promise { const relativePlanFile = path.relative(this.workdir, planFile); await this.setUserAgent() - await exec(terraformBinaryName, ['apply', '-auto-approve', '-input', 'false', ...this.stateFileOption, relativePlanFile], { cwd: this.workdir, env: process.env }, stdout); + await exec(terraformBinaryName, ['apply', '-auto-approve', '-input=false', ...this.stateFileOption, relativePlanFile], { cwd: this.workdir, env: process.env }, stdout); } public async destroy(stdout: (chunk: Buffer) => any): Promise { await this.setUserAgent() - await exec(terraformBinaryName, ['destroy', '-auto-approve', '-input', 'false', ...this.stateFileOption], { cwd: this.workdir, env: process.env }, stdout); + await exec(terraformBinaryName, ['destroy', '-auto-approve', '-input=false', ...this.stateFileOption], { cwd: this.workdir, env: process.env }, stdout); } public async version(): Promise {