Skip to content

Commit ddb4209

Browse files
sd109MoteHue
authored andcommitted
Add optional -q flag to seed ssh script to suppress tofu output (azimuth-cloud#189)
* Add optional -q flag to seed ssh script to suppress tofu output * Update comments
1 parent 9d5d4ee commit ddb4209

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

bin/kube-connect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ if [ "$install_mode" = "ha" ]; then
8080
cluster_name="$(ansible_variable capi_cluster_release_name)"
8181
kubeconfig_arg="KUBECONFIG=./kubeconfig-${cluster_name}.yaml"
8282
fi
83-
"$AZIMUTH_CONFIG_ROOT/bin/seed-ssh" \
83+
"$AZIMUTH_CONFIG_ROOT/bin/seed-ssh" -q \
8484
$kubeconfig_arg \
8585
kubectl config view --raw > "$kubeconfig"
8686

@@ -104,7 +104,7 @@ kubectl config rename-context $ctx azimuth --kubeconfig $kubeconfig >/dev/null
104104

105105
# Launch the SOCKS proxy and store the PID
106106
echo "Starting SOCKS proxy..." >&2
107-
"$AZIMUTH_CONFIG_ROOT/bin/seed-ssh" -D $socks_port -N &
107+
"$AZIMUTH_CONFIG_ROOT/bin/seed-ssh" -q -D $socks_port -N &
108108
socks_pid="$!"
109109
# Wait a few seconds and check that the process is running
110110
sleep 5

bin/seed-ssh

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ if [ -z "$AZIMUTH_CONFIG_ROOT" ] || [ -z "$AZIMUTH_CONFIG_ENVIRONMENT_ROOT" ]; t
1313
exit 1
1414
fi
1515

16-
1716
ansible_variable() {
1817
ANSIBLE_LOAD_CALLBACK_PLUGINS=true \
1918
ANSIBLE_STDOUT_CALLBACK=json \
@@ -22,6 +21,15 @@ ansible_variable() {
2221
jq -r -R "fromjson? | .plays[0].tasks[0].hosts.localhost.$1"
2322
}
2423

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+
}
2533

2634
# Add the Terraform binary directory to the PATH, so we can use it if it was
2735
# downloaded as part of a provision
@@ -45,6 +53,20 @@ fi
4553
work_dir="$(ansible_variable work_directory)/seed-ssh"
4654
mkdir -p "$work_dir"
4755

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+
4870
# Initialise the OpenTofu backend
4971
terraform_backend_type="$(ansible_variable terraform_backend_type)"
5072
if [ "$terraform_backend_type" = "local" ]; then
@@ -60,13 +82,12 @@ terraform {
6082
backend "${terraform_backend_type}" {}
6183
}
6284
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
7091
fi
7192

7293
# Read the required variables from the Terraform state

0 commit comments

Comments
 (0)