fix terraform versioning usage

This commit is contained in:
jerger 2022-08-19 15:01:10 +02:00
parent 334f7ffaac
commit e90a46bb67
3 changed files with 13 additions and 11 deletions

View file

@ -22,18 +22,18 @@ Ensure that yout python3 version is at least Python 3.7!
```
sudo apt install python3-pip
pip3 install pip3 --upgrade --user
pip3 install pybuilder ddadevops deprecation --user
pip3 install pip3 --upgrade
pip3 install pybuilder ddadevops deprecation
export PATH=$PATH:~/.local/bin
# in case of using terraform
pip3 install dda-python-terraform --user
pip3 install dda-python-terraform packaging
# in case of using AwsMixin
pip3 install boto3 --user
pip3 install boto3
# in case of using AwsMfaMixin
pip3 install boto3 mfa --user
pip3 install boto3 mfa
```
# Example Build

View file

@ -10,4 +10,5 @@ pytest==7.1
pytest-cov==3.0
pytest-datafiles==2.0
dda-python-terraform==2.0.1
packaging==3.0
boto3==1.24

View file

@ -5,6 +5,7 @@ from pkg_resources import *
from dda_python_terraform import *
from .python_util import filter_none
from .devops_build import DevopsBuild, create_devops_build_config
from packaging import version
import sys
@ -20,7 +21,7 @@ def create_devops_terraform_build_config(stage,
terraform_build_commons_dir_name='terraform',
debug_print_terraform_command=False,
additional_tfvar_files=[],
terraform_version=0.15):
terraform_semantic_version="1.0.8"):
ret = create_devops_build_config(
stage, project_root_path, module, build_dir_name)
ret.update({'additional_vars': additional_vars,
@ -31,7 +32,7 @@ def create_devops_terraform_build_config(stage,
'terraform_build_commons_dir_name': terraform_build_commons_dir_name,
'debug_print_terraform_command': debug_print_terraform_command,
'additional_tfvar_files': additional_tfvar_files,
'terraform_version': terraform_version})
'terraform_semantic_version': terraform_semantic_version})
return ret
class DevopsTerraformBuild(DevopsBuild):
@ -47,7 +48,7 @@ class DevopsTerraformBuild(DevopsBuild):
self.terraform_build_commons_dir_name = config['terraform_build_commons_dir_name']
self.debug_print_terraform_command = config['debug_print_terraform_command']
self.additional_tfvar_files = config['additional_tfvar_files']
self.terraform_version = config['terraform_version']
self.terraform_semantic_version = config['terraform_semantic_version']
def terraform_build_commons_path(self):
mylist = [self.build_commons_path,
@ -98,7 +99,7 @@ class DevopsTerraformBuild(DevopsBuild):
self.rescue_local_state()
def init_client(self):
tf = Terraform(working_dir=self.build_path(), terraform_version=self.terraform_version)
tf = Terraform(working_dir=self.build_path(), terraform_semantic_version=self.terraform_semantic_version)
tf.init()
self.print_terraform_command(tf)
if self.use_workspace:
@ -148,7 +149,7 @@ class DevopsTerraformBuild(DevopsBuild):
auto_approve_flag = IsFlagged
else:
auto_approve_flag = None
if self.terraform_version >= 1.0:
if version.parse(self.terraform_semantic_version) >= version.parse("1.0.0"):
return_code, stdout, stderr = tf.apply(capture_output=False, raise_on_error=True,
auto_approve=auto_approve_flag,
var=self.project_vars(),
@ -181,7 +182,7 @@ class DevopsTerraformBuild(DevopsBuild):
auto_approve_flag = IsFlagged
else:
auto_approve_flag = None
if self.terraform_version >= 1.0:
if version.parse(self.terraform_semantic_version >= version.parse("1.0.0"):
return_code, stdout, stderr = tf.destroy(capture_output=False, raise_on_error=True,
auto_approve=auto_approve_flag,
var=self.project_vars(),