Skip to content

Commit

Permalink
add support for force-copy and refresh arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
ludoo committed Sep 7, 2019
1 parent 57e4cda commit 1dc335a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
18 changes: 12 additions & 6 deletions tests/test_tftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,28 @@


_ARGS_TESTS = (
({'auto_approve': True}, ['-auto-approve']),
({'auto_approve': False}, []),
({'backend': True}, []),
({'backend': None}, []),
({'backend': False}, ['-backend=false']),
({'color': True}, []),
({'input': True}, []),
({'json_format': False}, []),
({'lock': True}, []),
({'plugin_dir': ''}, []),
({'auto_approve': True}, ['-auto-approve']),
({'color': False}, ['-no-color']),
({'color': False, 'input': False}, ['-no-color', '-input=false']),
({'force_copy': True}, ['-force-copy']),
({'force_copy': None}, []),
({'force_copy': False}, []),
({'input': True}, []),
({'input': False}, ['-input=false']),
({'json_format': True}, ['-json']),
({'json_format': False}, []),
({'lock': True}, []),
({'lock': False}, ['-lock=false']),
({'plugin_dir': ''}, []),
({'plugin_dir': 'abc'}, ['-plugin-dir', 'abc']),
({'color': False, 'input': False}, ['-no-color', '-input=false'])
({'refresh': True}, []),
({'refresh': None}, []),
({'refresh': False}, ['-refresh=false']),
)
_AUTORUN_CALLS = [
['terraform', 'init', '-no-color', '-input=false'],
Expand Down
15 changes: 11 additions & 4 deletions tftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def parse_args(init_vars=None, tf_vars=None, **kw):
cmd_args.append('-backend=false')
if kw.get('color') is False:
cmd_args.append('-no-color')
if kw.get('force_copy'):
cmd_args.append('-force-copy')
if kw.get('input') is False:
cmd_args.append('-input=false')
if kw.get('json_format') is True:
Expand All @@ -71,6 +73,8 @@ def parse_args(init_vars=None, tf_vars=None, **kw):
cmd_args.append('-lock=false')
if kw.get('plugin_dir'):
cmd_args += ['-plugin-dir', kw['plugin_dir']]
if kw.get('refresh') is False:
cmd_args.append('-refresh=false')
if isinstance(init_vars, dict):
cmd_args += ['-backend-config=\'{}={}\''.format(k, v)
for k, v in init_vars.items()]
Expand Down Expand Up @@ -282,15 +286,18 @@ def teardown(self, tf_vars=None):
except TerraformTestError:
_LOGGER.exception('error in teardown destroy')

def init(self, input=False, color=False, plugin_dir=None, init_vars=None, backend=True):
def init(self, input=False, color=False, force_copy=False, plugin_dir=None,
init_vars=None, backend=True):
"""Run Terraform init command."""
cmd_args = parse_args(input=input, color=color, backend=backend,
plugin_dir=plugin_dir, init_vars=init_vars)
force_copy=force_copy, plugin_dir=plugin_dir,
init_vars=init_vars)
return self.execute_command('init', *cmd_args).out

def plan(self, input=False, color=False, tf_vars=None):
def plan(self, input=False, color=False, refresh=True, tf_vars=None):
"""Run Terraform plan command."""
cmd_args = parse_args(input=input, color=color, tf_vars=tf_vars)
cmd_args = parse_args(input=input, color=color,
refresh=refresh, tf_vars=tf_vars)
return self.execute_command('plan', *cmd_args).out

def apply(self, input=False, color=False, auto_approve=True, tf_vars=None):
Expand Down

0 comments on commit 1dc335a

Please sign in to comment.