From 122ba08a4342c79ab752e8babb4050b818c9d20c Mon Sep 17 00:00:00 2001 From: Eytan Naim Date: Mon, 20 Nov 2023 11:39:05 +0200 Subject: [PATCH] add timeout --- modules/aws/mx/configuration.tf | 11 +++++++---- modules/aws/mx/configure.tftpl | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/modules/aws/mx/configuration.tf b/modules/aws/mx/configuration.tf index 0bc43427d..60bc3bcb4 100644 --- a/modules/aws/mx/configuration.tf +++ b/modules/aws/mx/configuration.tf @@ -1,5 +1,5 @@ locals { - conf_timeout = 60 * 15 + conf_timeout = 60 * 40 configuration_elements = concat( local.service_group_configuration, @@ -8,9 +8,12 @@ locals { ) commands = <<-EOF ${templatefile("${path.module}/configure.tftpl", - { mx_address = local.mx_address_for_api - https_auth_header = local.https_auth_header -configuration_elements = local.configuration_elements })} + { mx_address = local.mx_address_for_api + https_auth_header = local.https_auth_header + configuration_elements = local.configuration_elements + timeout = local.conf_timeout + }) + } EOF } diff --git a/modules/aws/mx/configure.tftpl b/modules/aws/mx/configure.tftpl index 21c2b101a..c20df6edd 100644 --- a/modules/aws/mx/configure.tftpl +++ b/modules/aws/mx/configure.tftpl @@ -2,9 +2,20 @@ set -x set -e +start_time=$(date +%s) + cookie_file=$(mktemp) response_file=$(mktemp) +function exit_on_timeout() { + now=$(date +%s) + elapsed=$((now-start_time)) + if [ $elapsed -gt ${timeout} ]; then + echo "Timeout reached." + exit 1 + fi +} + http_code=$(curl -k -s --cookie-jar $cookie_file -o $response_file -w "%%{http_code}" \ --request POST 'https://${mx_address}:8083/SecureSphere/api/v1/auth/session' \ --header "Authorization: Basic ${https_auth_header}") @@ -27,6 +38,7 @@ while true; do fi fi + exit_on_timeout echo "sleep 1m" sleep 60 done @@ -52,6 +64,8 @@ while true; do break fi fi + + exit_on_timeout echo "sleep 1m" sleep 60 done