@@ -13,7 +13,6 @@ if [ -z "$AZIMUTH_CONFIG_ROOT" ] || [ -z "$AZIMUTH_CONFIG_ENVIRONMENT_ROOT" ]; t
13
13
exit 1
14
14
fi
15
15
16
-
17
16
ansible_variable () {
18
17
ANSIBLE_LOAD_CALLBACK_PLUGINS=true \
19
18
ANSIBLE_STDOUT_CALLBACK=json \
@@ -22,6 +21,15 @@ ansible_variable() {
22
21
jq -r -R " fromjson? | .plays[0].tasks[0].hosts.localhost.$1 "
23
22
}
24
23
24
+ tf_init () {
25
+ ansible_variable terraform_backend_config > " $terraform_dir /backend_config.json"
26
+ $terraform_binary_path \
27
+ -chdir=" $terraform_dir " \
28
+ init \
29
+ -input=false \
30
+ -reconfigure \
31
+ -backend-config=$terraform_dir /backend_config.json
32
+ }
25
33
26
34
# Add the Terraform binary directory to the PATH, so we can use it if it was
27
35
# downloaded as part of a provision
45
53
work_dir=" $( ansible_variable work_directory) /seed-ssh"
46
54
mkdir -p " $work_dir "
47
55
56
+ # Check if quiet mode (-q) was passed to SSH command
57
+ # so that we can suppress other output elsewhere too
58
+ QUIET_MODE=false
59
+ for arg in $@ ; do
60
+ if [[ ! $arg == -* ]]; then
61
+ # Break if we encounter a non-flag arg since
62
+ # this is likely a command to run within the SSH
63
+ # session instead of an arg intended for SSH client
64
+ break
65
+ elif [[ $arg == " -q" ]]; then
66
+ QUIET_MODE=true
67
+ fi
68
+ done
69
+
48
70
# Initialise the OpenTofu backend
49
71
terraform_backend_type=" $( ansible_variable terraform_backend_type) "
50
72
if [ " $terraform_backend_type " = " local" ]; then
@@ -60,13 +82,12 @@ terraform {
60
82
backend "${terraform_backend_type} " {}
61
83
}
62
84
EOF
63
- ansible_variable terraform_backend_config > " $terraform_dir /backend_config.json"
64
- $terraform_binary_path \
65
- -chdir=" $terraform_dir " \
66
- init \
67
- -input=false \
68
- -reconfigure \
69
- -backend-config=$terraform_dir /backend_config.json
85
+ # If -q (quiet) is passed to ssh then also suppress terraform / tofu output
86
+ if [[ $QUIET_MODE == " true" ]]; then
87
+ tf_init > /dev/null
88
+ else
89
+ tf_init
90
+ fi
70
91
fi
71
92
72
93
# Read the required variables from the Terraform state
0 commit comments