add debug output

This commit is contained in:
jem 2020-03-10 08:28:06 +01:00
parent d604901ffd
commit 145091b954
4 changed files with 26 additions and 10 deletions

View file

@ -27,7 +27,7 @@ use_plugin("python.distutils")
default_task = "publish"
name = "ddadevops"
version = "0.4.1.dev6"
version = "0.4.1.dev8"
summary = "tools to support builds combining gopass, terraform, dda-pallet, aws & hetzner-cloud"
description = __doc__
authors = [Author("meissa GmbH", "buero@meissa-gmbh.de")]

View file

@ -25,6 +25,7 @@ class AwsBackendPropertiesMixin(DevopsTerraformBuild):
def init_client(self):
tf = Terraform(working_dir=self.build_path())
self.print_terraform_command('init --backend-config=' + self.backend_config())
tf.init(backend_config=self.backend_config())
if self.use_workspace:
try:
@ -35,16 +36,19 @@ class AwsBackendPropertiesMixin(DevopsTerraformBuild):
def plan(self):
tf = self.init_client()
self.print_terraform_command('plan --var-file=' + self.backend_config())
tf.plan(capture_output=False, var=self.project_vars(),
var_file=self.backend_config())
def apply(self, p_auto_approve=False):
tf = self.init_client()
self.print_terraform_command('apply --var-file=' + self.backend_config())
tf.apply(capture_output=False, auto_approve=p_auto_approve,
var=self.project_vars(), var_file=self.backend_config())
self.write_output(tf)
def destroy(self, p_auto_approve=False):
tf = self.init_client()
self.print_terraform_command('destroy --var-file=' + self.backend_config())
tf.destroy(capture_output=False, auto_approve=p_auto_approve,
var=self.project_vars(), var_file=self.backend_config())

View file

@ -42,11 +42,11 @@ class DdaPalletMixin(DevopsBuild):
output_file.write(
self.target_template.substitute({'ipv4': ipv4, 'node_name': node_name}))
def dda_write_domain(self, domain_file_name, substitues):
with open(self.build_path() + domain_file_name, "r") as input_file:
def dda_write_domain(self, substitues):
with open(self.build_path() + self.domain_file_name, "r") as input_file:
domain_input=input_file.read()
domain_template=Template(domain_input)
with open(self.build_path() + 'out_' + domain_file_name, "w") as output_file:
with open(self.build_path() + 'out_' + self.domain_file_name, "w") as output_file:
output_file.write(domain_template.substitute(substitues))
def dda_uberjar(self, configure_switch = None):

View file

@ -11,13 +11,14 @@ def create_devops_terraform_build_config(stage, project_root_path, build_commons
build_dir_name='target',
terraform_build_commons_dir_name='terraform',
output_json_name='output.json',
use_workspace=True):
use_workspace=True, print_terraform_command=False):
ret = create_devops_build_config(
stage, project_root_path, build_commons_path, module, build_dir_name)
ret.update({'additional_vars': additional_vars,
'terraform_build_commons_dir_name': terraform_build_commons_dir_name,
'output_json_name': output_json_name,
'use_workspace': use_workspace})
'use_workspace': use_workspace
'print_terraform_command': print_terraform_command})
return ret
@ -30,6 +31,7 @@ class DevopsTerraformBuild(DevopsBuild):
self.terraform_build_commons_dir_name = config['terraform_build_commons_dir_name']
self.output_json_name = config['output_json_name']
self.use_workspace = config['use_workspace']
self.print_terraform_command = config['print_terraform_command']
def terraform_build_commons_path(self):
mylist = [self.build_commons_path,
@ -54,6 +56,7 @@ class DevopsTerraformBuild(DevopsBuild):
def init_client(self):
tf = Terraform(working_dir=self.build_path())
self.print_terraform_command('init')
tf.init()
if self.use_workspace:
try:
@ -63,6 +66,7 @@ class DevopsTerraformBuild(DevopsBuild):
return tf
def write_output(self, tf):
self.print_terraform_command('output -json')
result = tf.output(json=IsFlagged)
with open(self.build_path() + self.output_json_name, "w") as output_file:
output_file.write(json.dumps(result))
@ -73,20 +77,28 @@ class DevopsTerraformBuild(DevopsBuild):
def plan(self):
tf = self.init_client()
self.print_terraform_command('plan')
tf.plan(capture_output=False, var=self.project_vars())
def apply(self, p_auto_approve=False):
tf = self.init_client()
self.print_terraform_command('apply')
tf.apply(capture_output=False, auto_approve=p_auto_approve,
var=self.project_vars())
self.write_output(tf)
def destroy(self, p_auto_approve=False):
tf = self.init_client()
self.print_terraform_command('destroy')
tf.destroy(capture_output=False, auto_approve=p_auto_approve,
var=self.project_vars())
def tf_import(self, tf_import_name, tf_import_resource,):
tf = self.init_client()
self.print_terraform_command('import')
tf.import_cmd(tf_import_name, tf_import_resource,
capture_output=False, var=self.project_vars())
def print_terraform_command(self, operation):
if self.print_terraform_command:
print('cd ' + self.build_path() + ' && terraform ' + operation + self.project_vars())