From 7e1c797e43bca78c8a31a30efefb82a33683364f Mon Sep 17 00:00:00 2001 From: Malcolm Date: Thu, 28 Mar 2024 12:57:25 -0400 Subject: [PATCH 1/2] PRO-466 ADD Infracost debugging --- .../workflow_step_infracost_setup.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/terrat_runner/workflow_step_infracost_setup.py b/terrat_runner/workflow_step_infracost_setup.py index 1ff6b4de..433d1e9c 100644 --- a/terrat_runner/workflow_step_infracost_setup.py +++ b/terrat_runner/workflow_step_infracost_setup.py @@ -1,3 +1,5 @@ +import sys + import json import logging import os @@ -94,6 +96,14 @@ def _create_base_infracost(state, config, infracost_dir, infracost_json): '--format=json', '--out-file={}'.format(infracost_json)]) + with open(infracost_config_yml) as f: + sys.stdout.write('***** infracost config yml\n') + sys.stdout.write(f.read() + '\n') + + with open(infracost_json) as f: + sys.stdout.write('***** infracost base json\n') + sys.stdout.write(f.read() + '\n') + finally: subprocess.check_call(['git', 'checkout', current_branch, '--'], cwd=state.working_dir) subprocess.call(['git', 'stash', 'pop']) @@ -127,6 +137,16 @@ def run(state, config): '--format=json', '--out-file={}'.format(curr_infracost)]) + with open(infracost_config_yml) as f: + sys.stdout.write('***** infracost config yml\n') + sys.stdout.write(f.read() + '\n') + + with open(curr_infracost) as f: + sys.stdout.write('***** infracost json\n') + sys.stdout.write(f.read() + '\n') + + sys.stdout.flush() + _run_retry(state, ['infracost', 'diff', @@ -136,6 +156,10 @@ def run(state, config): '--out-file={}'.format(diff_infracost)]) if 'level=error' not in output: + with open(diff_infracost) as f: + sys.stdout.write('***** infracost diff\n') + sys.stdout.write(f.read() + '\n') + with open(diff_infracost) as f: diff = json.load(f) From 95d98fa20cd1d96c53da7b2d1e7abb97fadc77ab Mon Sep 17 00:00:00 2001 From: Malcolm Date: Fri, 29 Mar 2024 17:45:42 -0400 Subject: [PATCH 2/2] PRO-466 FIX Infracost integration --- terrat_runner/infracost.py | 16 ------------- .../workflow_step_infracost_setup.py | 24 ------------------- 2 files changed, 40 deletions(-) diff --git a/terrat_runner/infracost.py b/terrat_runner/infracost.py index aee3250d..95ecc3fd 100644 --- a/terrat_runner/infracost.py +++ b/terrat_runner/infracost.py @@ -18,22 +18,6 @@ def convert_cost(cost): def create_infracost_yml(outname, dirspaces): - # We want to configure infracost with the most minimal configuration, so we - # find the set of base directories that we'll run in (with a check for if - # "." is in there) and create a new set of dirspaces just for those, and - # then build the config. - by_workspace = {} - for ds in dirspaces: - by_workspace.setdefault(ds['workspace'], []).append(ds) - - dirspaces = [] - for ws, dspaces in by_workspace.items(): - ds = set([d['path'].split('/')[0] for d in dspaces]) - if '.' in ds: - dirspaces.append({'path': '.', 'workspace': ws}) - else: - dirspaces.extend([{'path': d, 'workspace': ws} for d in ds]) - config = { 'version': '0.1', 'projects': [ diff --git a/terrat_runner/workflow_step_infracost_setup.py b/terrat_runner/workflow_step_infracost_setup.py index 433d1e9c..1ff6b4de 100644 --- a/terrat_runner/workflow_step_infracost_setup.py +++ b/terrat_runner/workflow_step_infracost_setup.py @@ -1,5 +1,3 @@ -import sys - import json import logging import os @@ -96,14 +94,6 @@ def _create_base_infracost(state, config, infracost_dir, infracost_json): '--format=json', '--out-file={}'.format(infracost_json)]) - with open(infracost_config_yml) as f: - sys.stdout.write('***** infracost config yml\n') - sys.stdout.write(f.read() + '\n') - - with open(infracost_json) as f: - sys.stdout.write('***** infracost base json\n') - sys.stdout.write(f.read() + '\n') - finally: subprocess.check_call(['git', 'checkout', current_branch, '--'], cwd=state.working_dir) subprocess.call(['git', 'stash', 'pop']) @@ -137,16 +127,6 @@ def run(state, config): '--format=json', '--out-file={}'.format(curr_infracost)]) - with open(infracost_config_yml) as f: - sys.stdout.write('***** infracost config yml\n') - sys.stdout.write(f.read() + '\n') - - with open(curr_infracost) as f: - sys.stdout.write('***** infracost json\n') - sys.stdout.write(f.read() + '\n') - - sys.stdout.flush() - _run_retry(state, ['infracost', 'diff', @@ -156,10 +136,6 @@ def run(state, config): '--out-file={}'.format(diff_infracost)]) if 'level=error' not in output: - with open(diff_infracost) as f: - sys.stdout.write('***** infracost diff\n') - sys.stdout.write(f.read() + '\n') - with open(diff_infracost) as f: diff = json.load(f)