[terraform] Disable input prompts during terraform init/plan/apply (#38842)

Per Hashicorp's [guidelines][1] for automated use of terraform CLI, this PR
adds the `-input=false` option to all the commands executed in the
module. If input is required, this causes a hard failure that will
become a module failure.

[1]: https://www.terraform.io/guides/running-terraform-in-automation.html
pull/39117/head
Ryan Brown 6 years ago committed by GitHub
parent eebfa66c2b
commit f428108845
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -133,7 +133,7 @@ import traceback
from ansible.module_utils.basic import AnsibleModule
DESTROY_ARGS = ('destroy', '-no-color', '-force')
APPLY_ARGS = ('apply', '-no-color', '-auto-approve=true')
APPLY_ARGS = ('apply', '-no-color', '-input=false', '-auto-approve=true')
module = None
@ -159,7 +159,7 @@ def _state_args(state_file):
def init_plugins(bin_path, project_path):
command = [bin_path, 'init']
command = [bin_path, 'init', '-input=false']
rc, out, err = module.run_command(command, cwd=project_path)
if rc != 0:
module.fail_json(msg="Failed to initialize Terraform modules:\r\n{0}".format(err))
@ -169,7 +169,7 @@ def build_plan(bin_path, project_path, variables_args, state_file, plan_path=Non
if plan_path is None:
f, plan_path = tempfile.mkstemp(suffix='.tfplan')
command = [bin_path, 'plan', '-no-color', '-detailed-exitcode', '-out', plan_path]
command = [bin_path, 'plan', '-input=false', '-no-color', '-detailed-exitcode', '-out', plan_path]
command.extend(_state_args(state_file))
rc, out, err = module.run_command(command + variables_args, cwd=project_path)

Loading…
Cancel
Save