From c33672508f6727313278725a89cca5812f9e54ae Mon Sep 17 00:00:00 2001 From: Hang Anh Hung <50902568+hanganhhung123@users.noreply.github.com> Date: Thu, 16 Nov 2023 11:30:39 +0800 Subject: [PATCH 1/2] Remove organization in check_terraform_cloud_agent_exist() and redirect to STDERR in make_curl_request() --- scripts/tfcloud/tfcloud.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/tfcloud/tfcloud.sh b/scripts/tfcloud/tfcloud.sh index c49d71ea..452ed7d7 100644 --- a/scripts/tfcloud/tfcloud.sh +++ b/scripts/tfcloud/tfcloud.sh @@ -40,14 +40,14 @@ check_terraform_cloud_agent_exist() { if [[ -n ${gitops_agent_pool_name} ]]; then - url="https://${TF_VAR_tf_cloud_hostname}/api/v2/organizations/${TF_VAR_tf_cloud_organization}/agent-pools" + url="https://${TF_VAR_tf_cloud_hostname}/api/v2/agent-pools" body=$(make_curl_request -url "$url" -gracefully_continue) result=$(echo $body | jq -r ".data[] | select (.attributes.name == \"${gitops_agent_pool_name}\") | .id") elif [[ -n ${gitops_agent_pool_id} ]]; then # Checking the agent pool exists - url="https://${TF_VAR_tf_cloud_hostname}/api/v2/organizations/${TF_VAR_tf_cloud_organization}/agent-pools/${gitops_agent_pool_id}" + url="https://${TF_VAR_tf_cloud_hostname}/api/v2/agent-pools/${gitops_agent_pool_id}" body=$(make_curl_request -url "$url" -gracefully_continue) result="$gitops_agent_pool_id" @@ -536,9 +536,9 @@ function make_curl_request() { esac done - command="curl -sS -L -w '%{http_code}' --header 'Authorization: Bearer xxxxxx' --header 'Content-Type: application/vnd.api+json' $options -- '"${url}"' 2> >(tee /dev/stderr)" + command="curl -sS -L -w '%{http_code}' --header 'Authorization: Bearer xxxxxx' --header 'Content-Type: application/vnd.api+json' $options -- '"${url}"'" debug "$(echo "Running command: $command")" >&2 - command="curl -sS -L -w '%{http_code}' --header 'Authorization: Bearer "$REMOTE_ORG_TOKEN"' --header 'Content-Type: application/vnd.api+json' $options -- '"${url}"' 2> >(tee /dev/stderr)" + command="curl -sS -L -w '%{http_code}' --header 'Authorization: Bearer "$REMOTE_ORG_TOKEN"' --header 'Content-Type: application/vnd.api+json' $options -- '"${url}"'" response=$(eval $command) return_code=$? From 4cd442c28f9933cf4a82266964f4f3e4472a659b Mon Sep 17 00:00:00 2001 From: Hang Anh Hung <50902568+hanganhhung123@users.noreply.github.com> Date: Tue, 19 Dec 2023 10:55:01 +0800 Subject: [PATCH 2/2] Write standard error into file descriptor 2 with >&2 --- scripts/tfcloud/tfcloud.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/tfcloud/tfcloud.sh b/scripts/tfcloud/tfcloud.sh index 452ed7d7..68578386 100644 --- a/scripts/tfcloud/tfcloud.sh +++ b/scripts/tfcloud/tfcloud.sh @@ -536,9 +536,9 @@ function make_curl_request() { esac done - command="curl -sS -L -w '%{http_code}' --header 'Authorization: Bearer xxxxxx' --header 'Content-Type: application/vnd.api+json' $options -- '"${url}"'" + command="curl -sS -L -w '%{http_code}' --header 'Authorization: Bearer xxxxxx' --header 'Content-Type: application/vnd.api+json' $options -- '"${url}"' 2> >(tee -a >&2)" debug "$(echo "Running command: $command")" >&2 - command="curl -sS -L -w '%{http_code}' --header 'Authorization: Bearer "$REMOTE_ORG_TOKEN"' --header 'Content-Type: application/vnd.api+json' $options -- '"${url}"'" + command="curl -sS -L -w '%{http_code}' --header 'Authorization: Bearer "$REMOTE_ORG_TOKEN"' --header 'Content-Type: application/vnd.api+json' $options -- '"${url}"' 2> >(tee -a >&2)" response=$(eval $command) return_code=$? @@ -607,4 +607,4 @@ function process_curl_response() { else debug "Success: HTTP status code is ${http_code}" >&2 fi -} \ No newline at end of file +}