use refresh instead of apply with options
This commit is contained in:
parent
d8af4dec3a
commit
dbcaae69ac
1 changed files with 26 additions and 5 deletions
|
@ -47,6 +47,29 @@ class WorkaroundTerraform(Terraform):
|
||||||
var_file, terraform_bin_path, is_env_vars_included)
|
var_file, terraform_bin_path, is_env_vars_included)
|
||||||
self.latest_cmd = ''
|
self.latest_cmd = ''
|
||||||
|
|
||||||
|
def refresh(
|
||||||
|
self,
|
||||||
|
dir_or_plan: Optional[str] = None,
|
||||||
|
input: bool = False,
|
||||||
|
no_color: Type[TerraformFlag] = IsFlagged,
|
||||||
|
**kwargs,
|
||||||
|
) -> CommandOutput:
|
||||||
|
"""Refer to https://terraform.io/docs/commands/refresh.html
|
||||||
|
|
||||||
|
no-color is flagged by default
|
||||||
|
:param no_color: disable color of stdout
|
||||||
|
:param input: disable prompt for a missing variable
|
||||||
|
:param dir_or_plan: folder relative to working folder
|
||||||
|
:param kwargs: same as kwags in method 'cmd'
|
||||||
|
:returns return_code, stdout, stderr
|
||||||
|
"""
|
||||||
|
default = kwargs.copy()
|
||||||
|
default["input"] = input
|
||||||
|
default["no_color"] = no_color
|
||||||
|
option_dict = self._generate_default_options(default)
|
||||||
|
args = self._generate_default_args(dir_or_plan)
|
||||||
|
return self.cmd("refresh", *args, **option_dict)
|
||||||
|
|
||||||
def generate_cmd_string(self, cmd, *args, **kwargs):
|
def generate_cmd_string(self, cmd, *args, **kwargs):
|
||||||
result = super().generate_cmd_string(cmd, *args, **kwargs)
|
result = super().generate_cmd_string(cmd, *args, **kwargs)
|
||||||
self.latest_cmd = ' '.join(result)
|
self.latest_cmd = ' '.join(result)
|
||||||
|
@ -174,11 +197,9 @@ class DevopsTerraformBuild(DevopsBuild):
|
||||||
|
|
||||||
def refresh(self, auto_approve=True):
|
def refresh(self, auto_approve=True):
|
||||||
tf = self.init_client()
|
tf = self.init_client()
|
||||||
return_code, stdout, stderr = tf.apply(capture_output=False, raise_on_error=True,
|
return_code, stdout, stderr = tf.refresh(
|
||||||
refresh_only=IsFlagged,
|
var=self.project_vars(),
|
||||||
skip_plan=auto_approve,
|
var_file=self.additional_tfvar_files)
|
||||||
var=self.project_vars(),
|
|
||||||
var_file=self.additional_tfvar_files)
|
|
||||||
self.write_output(tf)
|
self.write_output(tf)
|
||||||
self.post_build()
|
self.post_build()
|
||||||
self.print_terraform_command(tf)
|
self.print_terraform_command(tf)
|
||||||
|
|
Loading…
Reference in a new issue