add additional-var-files-feature
This commit is contained in:
parent
f119d1ee88
commit
b9f3b84acf
3 changed files with 19 additions and 40 deletions
2
build.py
2
build.py
|
@ -28,7 +28,7 @@ use_plugin("python.distutils")
|
||||||
default_task = "publish"
|
default_task = "publish"
|
||||||
|
|
||||||
name = "ddadevops"
|
name = "ddadevops"
|
||||||
version = "0.4.3.dev0"
|
version = "0.4.3.dev2"
|
||||||
summary = "tools to support builds combining gopass, terraform, dda-pallet, aws & hetzner-cloud"
|
summary = "tools to support builds combining gopass, terraform, dda-pallet, aws & hetzner-cloud"
|
||||||
description = __doc__
|
description = __doc__
|
||||||
authors = [Author("meissa GmbH", "buero@meissa-gmbh.de")]
|
authors = [Author("meissa GmbH", "buero@meissa-gmbh.de")]
|
||||||
|
|
|
@ -14,9 +14,8 @@ class AwsBackendPropertiesMixin(DevopsTerraformBuild):
|
||||||
super().__init__(project, config)
|
super().__init__(project, config)
|
||||||
aws_mixin_config = config['AwsBackendPropertiesMixin']
|
aws_mixin_config = config['AwsBackendPropertiesMixin']
|
||||||
self.account_name = aws_mixin_config['account_name']
|
self.account_name = aws_mixin_config['account_name']
|
||||||
|
self.backend_config = "backend." + self.account_name + "." + self.stage + ".properties"
|
||||||
def backend_config(self):
|
self.additional_tfvar_files.append(self.backend_config)
|
||||||
return "backend." + self.account_name + "." + self.stage + ".properties"
|
|
||||||
|
|
||||||
def project_vars(self):
|
def project_vars(self):
|
||||||
ret = super().project_vars()
|
ret = super().project_vars()
|
||||||
|
@ -33,7 +32,7 @@ class AwsBackendPropertiesMixin(DevopsTerraformBuild):
|
||||||
|
|
||||||
def init_client(self):
|
def init_client(self):
|
||||||
tf = WorkaroundTerraform(working_dir=self.build_path())
|
tf = WorkaroundTerraform(working_dir=self.build_path())
|
||||||
tf.init(backend_config=self.backend_config())
|
tf.init(backend_config=self.backend_config)
|
||||||
self.print_terraform_command(tf)
|
self.print_terraform_command(tf)
|
||||||
if self.use_workspace:
|
if self.use_workspace:
|
||||||
try:
|
try:
|
||||||
|
@ -43,31 +42,3 @@ class AwsBackendPropertiesMixin(DevopsTerraformBuild):
|
||||||
tf.workspace('new', self.stage)
|
tf.workspace('new', self.stage)
|
||||||
self.print_terraform_command(tf)
|
self.print_terraform_command(tf)
|
||||||
return tf
|
return tf
|
||||||
|
|
||||||
def plan(self):
|
|
||||||
tf = self.init_client()
|
|
||||||
tf.plan(capture_output=False, raise_on_error=True,
|
|
||||||
var=self.project_vars(),
|
|
||||||
var_file=self.backend_config())
|
|
||||||
self.print_terraform_command(tf)
|
|
||||||
|
|
||||||
def apply(self, auto_approve=False):
|
|
||||||
tf = self.init_client()
|
|
||||||
tf.apply(capture_output=False, raise_on_error=True,
|
|
||||||
skip_plan=auto_approve,
|
|
||||||
var=self.project_vars(),
|
|
||||||
var_file=self.backend_config())
|
|
||||||
self.print_terraform_command(tf)
|
|
||||||
self.write_output(tf)
|
|
||||||
|
|
||||||
def destroy(self, auto_approve=False):
|
|
||||||
tf = self.init_client()
|
|
||||||
if auto_approve:
|
|
||||||
force = IsFlagged
|
|
||||||
else:
|
|
||||||
force = None
|
|
||||||
tf.destroy(capture_output=False, raise_on_error=True,
|
|
||||||
force=force,
|
|
||||||
var=self.project_vars(),
|
|
||||||
var_file=self.backend_config())
|
|
||||||
self.print_terraform_command(tf)
|
|
||||||
|
|
|
@ -14,7 +14,8 @@ def create_devops_terraform_build_config(stage, project_root_path, build_commons
|
||||||
use_workspace=True,
|
use_workspace=True,
|
||||||
use_package_common_files=True,
|
use_package_common_files=True,
|
||||||
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=[]):
|
||||||
ret = create_devops_build_config(
|
ret = create_devops_build_config(
|
||||||
stage, project_root_path, build_commons_path, module, build_dir_name)
|
stage, project_root_path, build_commons_path, module, build_dir_name)
|
||||||
ret.update({'additional_vars': additional_vars,
|
ret.update({'additional_vars': additional_vars,
|
||||||
|
@ -22,7 +23,8 @@ def create_devops_terraform_build_config(stage, project_root_path, build_commons
|
||||||
'use_workspace': use_workspace,
|
'use_workspace': use_workspace,
|
||||||
'use_package_common_files': use_package_common_files,
|
'use_package_common_files': use_package_common_files,
|
||||||
'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})
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
@ -80,6 +82,7 @@ class DevopsTerraformBuild(DevopsBuild):
|
||||||
self.use_package_common_files = config['use_package_common_files']
|
self.use_package_common_files = config['use_package_common_files']
|
||||||
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']
|
||||||
|
|
||||||
def terraform_build_commons_path(self):
|
def terraform_build_commons_path(self):
|
||||||
mylist = [self.build_commons_path,
|
mylist = [self.build_commons_path,
|
||||||
|
@ -116,7 +119,7 @@ class DevopsTerraformBuild(DevopsBuild):
|
||||||
self.copy_build_resources_from_dir()
|
self.copy_build_resources_from_dir()
|
||||||
run('cp *.tf ' + self.build_path(), shell=True)
|
run('cp *.tf ' + self.build_path(), shell=True)
|
||||||
run('cp *.properties ' + self.build_path(), shell=True)
|
run('cp *.properties ' + self.build_path(), shell=True)
|
||||||
run('cp *.tfars ' + self.build_path(), shell=True)
|
run('cp *.tfvars ' + self.build_path(), shell=True)
|
||||||
|
|
||||||
def init_client(self):
|
def init_client(self):
|
||||||
tf = WorkaroundTerraform(working_dir=self.build_path())
|
tf = WorkaroundTerraform(working_dir=self.build_path())
|
||||||
|
@ -144,14 +147,16 @@ class DevopsTerraformBuild(DevopsBuild):
|
||||||
def plan(self):
|
def plan(self):
|
||||||
tf = self.init_client()
|
tf = self.init_client()
|
||||||
tf.plan(capture_output=False, raise_on_error=True,
|
tf.plan(capture_output=False, raise_on_error=True,
|
||||||
var=self.project_vars())
|
var=self.project_vars(),
|
||||||
|
var_file=self.additional_tfvar_files)
|
||||||
self.print_terraform_command(tf)
|
self.print_terraform_command(tf)
|
||||||
|
|
||||||
def apply(self, auto_approve=False):
|
def apply(self, auto_approve=False):
|
||||||
tf = self.init_client()
|
tf = self.init_client()
|
||||||
tf.apply(capture_output=False, raise_on_error=True,
|
tf.apply(capture_output=False, raise_on_error=True,
|
||||||
skip_plan=auto_approve,
|
skip_plan=auto_approve,
|
||||||
var=self.project_vars())
|
var=self.project_vars(),
|
||||||
|
var_file=self.additional_tfvar_files)
|
||||||
self.print_terraform_command(tf)
|
self.print_terraform_command(tf)
|
||||||
self.write_output(tf)
|
self.write_output(tf)
|
||||||
|
|
||||||
|
@ -163,13 +168,16 @@ class DevopsTerraformBuild(DevopsBuild):
|
||||||
force = None
|
force = None
|
||||||
tf.destroy(capture_output=False, raise_on_error=True,
|
tf.destroy(capture_output=False, raise_on_error=True,
|
||||||
force=force,
|
force=force,
|
||||||
var=self.project_vars())
|
var=self.project_vars(),
|
||||||
|
var_file=self.additional_tfvar_files)
|
||||||
self.print_terraform_command(tf)
|
self.print_terraform_command(tf)
|
||||||
|
|
||||||
def tf_import(self, tf_import_name, tf_import_resource,):
|
def tf_import(self, tf_import_name, tf_import_resource,):
|
||||||
tf = self.init_client()
|
tf = self.init_client()
|
||||||
tf.import_cmd(tf_import_name, tf_import_resource,
|
tf.import_cmd(tf_import_name, tf_import_resource,
|
||||||
capture_output=False, raise_on_error=True, var=self.project_vars())
|
capture_output=False, raise_on_error=True,
|
||||||
|
var=self.project_vars(),
|
||||||
|
var_file=self.additional_tfvar_files)
|
||||||
self.print_terraform_command(tf)
|
self.print_terraform_command(tf)
|
||||||
|
|
||||||
def print_terraform_command(self, tf):
|
def print_terraform_command(self, tf):
|
||||||
|
|
Loading…
Reference in a new issue