Skip to content

Commit d2aae7c

Browse files
committed
Dump the output if getting the state failed
1 parent 392018e commit d2aae7c

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

management_instance/runbooks/shared_scripts/apply_all_downstream_projects.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import re
44
import json
5+
import sys
56

67
# If this script is not being run as part of an Octopus step, return variables from environment variables.
78
# Periods are replaced with underscores, and the variable name is converted to uppercase
@@ -92,7 +93,12 @@ def find_downstream_projects(apply_project_callback):
9293
if not octopus_space_name == tenant_name:
9394
continue
9495

95-
state_json, _, _ = execute(['terraform', 'show', '-json'], cwd=project_space_population_dir)
96+
state_json, _, ret_code = execute(['terraform', 'show', '-json'], cwd=project_space_population_dir)
97+
98+
if ret_code != 0:
99+
print(state_json)
100+
sys.exit(1)
101+
96102
state = json.loads(state_json)
97103

98104
resources = [x for x in state.get('values', {}).get('root_module', {}).get('resources', {}) if

management_instance/runbooks/shared_scripts/find_conflicts.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import re
44
import subprocess
55
import argparse
6+
import sys
67

78
# If this script is not being run as part of an Octopus step, return variables from environment variables.
89
# Periods are replaced with underscores, and the variable name is converted to uppercase
@@ -191,7 +192,12 @@ def init_argparse():
191192

192193
execute(['terraform', 'workspace', 'select', trimmed_workspace])
193194

194-
state_json, _, _ = execute(['terraform', 'show', '-json'])
195+
state_json, _, ret_code = execute(['terraform', 'show', '-json'])
196+
197+
if ret_code != 0:
198+
print(state_json)
199+
sys.exit(1)
200+
195201
state = json.loads(state_json)
196202

197203
resources = [x for x in state.get('values', {}).get('root_module', {}).get('resources', {}) if

management_instance/runbooks/shared_scripts/list_downstream_projects.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import subprocess
44
import os
55
import argparse
6+
import sys
67

78
# If this script is not being run as part of an Octopus step, return variables from environment variables.
89
# Periods are replaced with underscores, and the variable name is converted to uppercase
@@ -142,8 +143,12 @@ def init_argparse():
142143
continue
143144

144145
execute(['terraform', 'workspace', 'select', trimmed_workspace])
145-
workspace_json, _, _, = execute(['terraform', 'show', '-json'])
146-
printverbose(workspace_json)
146+
workspace_json, _, ret_code, = execute(['terraform', 'show', '-json'])
147+
148+
if ret_code != 0:
149+
print(workspace_json)
150+
sys.exit(1)
151+
147152
state = json.loads(workspace_json)
148153
resources = [x for x in state.get('values', {}).get('root_module', {}).get('resources', {}) if
149154
x.get('type', '') == 'octopusdeploy_project']

management_instance/runbooks/shared_scripts/merge_all_downstream_projects.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import re
44
import shutil
55
import subprocess
6+
import sys
67
from urllib.parse import urlparse
78
import argparse
89

@@ -216,7 +217,12 @@ def find_downstream_projects(parser, merge_repo_callback):
216217
if not octopus_space_name == tenant_name:
217218
continue
218219

219-
state_json, _, _ = execute(['terraform', 'show', '-json'])
220+
state_json, _, ret_code = execute(['terraform', 'show', '-json'])
221+
222+
if ret_code != 0:
223+
print(state_json)
224+
sys.exit(1)
225+
220226
state = json.loads(state_json)
221227

222228
resources = [x for x in state.get('values', {}).get('root_module', {}).get('resources', {}) if

0 commit comments

Comments
 (0)