-force & -skip-plan no longer works in tf1.0

This commit is contained in:
jem 2021-10-15 13:57:27 +02:00
parent 30f9f19f60
commit 894a8764ee

View file

@ -19,7 +19,8 @@ def create_devops_terraform_build_config(stage,
build_commons_path=None, build_commons_path=None,
terraform_build_commons_dir_name='terraform', terraform_build_commons_dir_name='terraform',
debug_print_terraform_command=False, debug_print_terraform_command=False,
additional_tfvar_files=[]): additional_tfvar_files=[],
terraform_version=1.0):
ret = create_devops_build_config( ret = create_devops_build_config(
stage, project_root_path, module, build_dir_name) stage, project_root_path, module, build_dir_name)
ret.update({'additional_vars': additional_vars, ret.update({'additional_vars': additional_vars,
@ -29,7 +30,8 @@ def create_devops_terraform_build_config(stage,
'build_commons_path': build_commons_path, 'build_commons_path': build_commons_path,
'terraform_build_commons_dir_name': terraform_build_commons_dir_name, 'terraform_build_commons_dir_name': terraform_build_commons_dir_name,
'debug_print_terraform_command': debug_print_terraform_command, 'debug_print_terraform_command': debug_print_terraform_command,
'additional_tfvar_files': additional_tfvar_files}) 'additional_tfvar_files': additional_tfvar_files
'terraform_version': terraform_version})
return ret return ret
class DevopsTerraformBuild(DevopsBuild): class DevopsTerraformBuild(DevopsBuild):
@ -45,6 +47,7 @@ class DevopsTerraformBuild(DevopsBuild):
self.terraform_build_commons_dir_name = config['terraform_build_commons_dir_name'] self.terraform_build_commons_dir_name = config['terraform_build_commons_dir_name']
self.debug_print_terraform_command = config['debug_print_terraform_command'] self.debug_print_terraform_command = config['debug_print_terraform_command']
self.additional_tfvar_files = config['additional_tfvar_files'] self.additional_tfvar_files = config['additional_tfvar_files']
self.terraform_version = config['terraform_version']
def terraform_build_commons_path(self): def terraform_build_commons_path(self):
mylist = [self.build_commons_path, mylist = [self.build_commons_path,
@ -168,10 +171,16 @@ class DevopsTerraformBuild(DevopsBuild):
force = IsFlagged force = IsFlagged
else: else:
force = None force = None
return_code, stdout, stderr = tf.destroy(capture_output=False, raise_on_error=True, if self.terraform_version <= 1.0:
force=force, return_code, stdout, stderr = tf.destroy(capture_output=False, raise_on_error=True,
var=self.project_vars(), auto_approve=force,
var_file=self.additional_tfvar_files) var=self.project_vars(),
var_file=self.additional_tfvar_files)
else:
return_code, stdout, stderr = tf.destroy(capture_output=False, raise_on_error=True,
force=force,
var=self.project_vars(),
var_file=self.additional_tfvar_files)
self.post_build() self.post_build()
self.print_terraform_command(tf) self.print_terraform_command(tf)
if (return_code > 0): if (return_code > 0):