add debug output
This commit is contained in:
parent
d604901ffd
commit
145091b954
4 changed files with 26 additions and 10 deletions
2
build.py
2
build.py
|
@ -27,7 +27,7 @@ use_plugin("python.distutils")
|
||||||
default_task = "publish"
|
default_task = "publish"
|
||||||
|
|
||||||
name = "ddadevops"
|
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"
|
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")]
|
||||||
|
|
|
@ -25,6 +25,7 @@ class AwsBackendPropertiesMixin(DevopsTerraformBuild):
|
||||||
|
|
||||||
def init_client(self):
|
def init_client(self):
|
||||||
tf = Terraform(working_dir=self.build_path())
|
tf = Terraform(working_dir=self.build_path())
|
||||||
|
self.print_terraform_command('init --backend-config=' + self.backend_config())
|
||||||
tf.init(backend_config=self.backend_config())
|
tf.init(backend_config=self.backend_config())
|
||||||
if self.use_workspace:
|
if self.use_workspace:
|
||||||
try:
|
try:
|
||||||
|
@ -35,16 +36,19 @@ class AwsBackendPropertiesMixin(DevopsTerraformBuild):
|
||||||
|
|
||||||
def plan(self):
|
def plan(self):
|
||||||
tf = self.init_client()
|
tf = self.init_client()
|
||||||
|
self.print_terraform_command('plan --var-file=' + self.backend_config())
|
||||||
tf.plan(capture_output=False, var=self.project_vars(),
|
tf.plan(capture_output=False, var=self.project_vars(),
|
||||||
var_file=self.backend_config())
|
var_file=self.backend_config())
|
||||||
|
|
||||||
def apply(self, p_auto_approve=False):
|
def apply(self, p_auto_approve=False):
|
||||||
tf = self.init_client()
|
tf = self.init_client()
|
||||||
|
self.print_terraform_command('apply --var-file=' + self.backend_config())
|
||||||
tf.apply(capture_output=False, auto_approve=p_auto_approve,
|
tf.apply(capture_output=False, auto_approve=p_auto_approve,
|
||||||
var=self.project_vars(), var_file=self.backend_config())
|
var=self.project_vars(), var_file=self.backend_config())
|
||||||
self.write_output(tf)
|
self.write_output(tf)
|
||||||
|
|
||||||
def destroy(self, p_auto_approve=False):
|
def destroy(self, p_auto_approve=False):
|
||||||
tf = self.init_client()
|
tf = self.init_client()
|
||||||
|
self.print_terraform_command('destroy --var-file=' + self.backend_config())
|
||||||
tf.destroy(capture_output=False, auto_approve=p_auto_approve,
|
tf.destroy(capture_output=False, auto_approve=p_auto_approve,
|
||||||
var=self.project_vars(), var_file=self.backend_config())
|
var=self.project_vars(), var_file=self.backend_config())
|
||||||
|
|
|
@ -42,11 +42,11 @@ class DdaPalletMixin(DevopsBuild):
|
||||||
output_file.write(
|
output_file.write(
|
||||||
self.target_template.substitute({'ipv4': ipv4, 'node_name': node_name}))
|
self.target_template.substitute({'ipv4': ipv4, 'node_name': node_name}))
|
||||||
|
|
||||||
def dda_write_domain(self, domain_file_name, substitues):
|
def dda_write_domain(self, substitues):
|
||||||
with open(self.build_path() + domain_file_name, "r") as input_file:
|
with open(self.build_path() + self.domain_file_name, "r") as input_file:
|
||||||
domain_input=input_file.read()
|
domain_input=input_file.read()
|
||||||
domain_template=Template(domain_input)
|
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))
|
output_file.write(domain_template.substitute(substitues))
|
||||||
|
|
||||||
def dda_uberjar(self, configure_switch = None):
|
def dda_uberjar(self, configure_switch = None):
|
||||||
|
|
|
@ -11,13 +11,14 @@ def create_devops_terraform_build_config(stage, project_root_path, build_commons
|
||||||
build_dir_name='target',
|
build_dir_name='target',
|
||||||
terraform_build_commons_dir_name='terraform',
|
terraform_build_commons_dir_name='terraform',
|
||||||
output_json_name='output.json',
|
output_json_name='output.json',
|
||||||
use_workspace=True):
|
use_workspace=True, print_terraform_command=False):
|
||||||
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,
|
||||||
'terraform_build_commons_dir_name': terraform_build_commons_dir_name,
|
'terraform_build_commons_dir_name': terraform_build_commons_dir_name,
|
||||||
'output_json_name': output_json_name,
|
'output_json_name': output_json_name,
|
||||||
'use_workspace': use_workspace})
|
'use_workspace': use_workspace
|
||||||
|
'print_terraform_command': print_terraform_command})
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,6 +31,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.output_json_name = config['output_json_name']
|
self.output_json_name = config['output_json_name']
|
||||||
self.use_workspace = config['use_workspace']
|
self.use_workspace = config['use_workspace']
|
||||||
|
self.print_terraform_command = config['print_terraform_command']
|
||||||
|
|
||||||
def terraform_build_commons_path(self):
|
def terraform_build_commons_path(self):
|
||||||
mylist = [self.build_commons_path,
|
mylist = [self.build_commons_path,
|
||||||
|
@ -54,6 +56,7 @@ class DevopsTerraformBuild(DevopsBuild):
|
||||||
|
|
||||||
def init_client(self):
|
def init_client(self):
|
||||||
tf = Terraform(working_dir=self.build_path())
|
tf = Terraform(working_dir=self.build_path())
|
||||||
|
self.print_terraform_command('init')
|
||||||
tf.init()
|
tf.init()
|
||||||
if self.use_workspace:
|
if self.use_workspace:
|
||||||
try:
|
try:
|
||||||
|
@ -63,6 +66,7 @@ class DevopsTerraformBuild(DevopsBuild):
|
||||||
return tf
|
return tf
|
||||||
|
|
||||||
def write_output(self, tf):
|
def write_output(self, tf):
|
||||||
|
self.print_terraform_command('output -json')
|
||||||
result = tf.output(json=IsFlagged)
|
result = tf.output(json=IsFlagged)
|
||||||
with open(self.build_path() + self.output_json_name, "w") as output_file:
|
with open(self.build_path() + self.output_json_name, "w") as output_file:
|
||||||
output_file.write(json.dumps(result))
|
output_file.write(json.dumps(result))
|
||||||
|
@ -73,20 +77,28 @@ class DevopsTerraformBuild(DevopsBuild):
|
||||||
|
|
||||||
def plan(self):
|
def plan(self):
|
||||||
tf = self.init_client()
|
tf = self.init_client()
|
||||||
|
self.print_terraform_command('plan')
|
||||||
tf.plan(capture_output=False, var=self.project_vars())
|
tf.plan(capture_output=False, var=self.project_vars())
|
||||||
|
|
||||||
def apply(self, p_auto_approve=False):
|
def apply(self, p_auto_approve=False):
|
||||||
tf = self.init_client()
|
tf = self.init_client()
|
||||||
|
self.print_terraform_command('apply')
|
||||||
tf.apply(capture_output=False, auto_approve=p_auto_approve,
|
tf.apply(capture_output=False, auto_approve=p_auto_approve,
|
||||||
var=self.project_vars())
|
var=self.project_vars())
|
||||||
self.write_output(tf)
|
self.write_output(tf)
|
||||||
|
|
||||||
def destroy(self, p_auto_approve=False):
|
def destroy(self, p_auto_approve=False):
|
||||||
tf = self.init_client()
|
tf = self.init_client()
|
||||||
|
self.print_terraform_command('destroy')
|
||||||
tf.destroy(capture_output=False, auto_approve=p_auto_approve,
|
tf.destroy(capture_output=False, auto_approve=p_auto_approve,
|
||||||
var=self.project_vars())
|
var=self.project_vars())
|
||||||
|
|
||||||
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()
|
||||||
|
self.print_terraform_command('import')
|
||||||
tf.import_cmd(tf_import_name, tf_import_resource,
|
tf.import_cmd(tf_import_name, tf_import_resource,
|
||||||
capture_output=False, var=self.project_vars())
|
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())
|
||||||
|
|
Loading…
Reference in a new issue