Skip to content

Commit

Permalink
Merge pull request #358 from hanganhhung123/main
Browse files Browse the repository at this point in the history
Remove organization in check_terraform_cloud_agent_exist() and redirect to STDERR in make_curl_request()
  • Loading branch information
LaurentLesle authored Dec 19, 2023
2 parents 1f13d9a + 4cd442c commit fecd567
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions scripts/tfcloud/tfcloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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}"' 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}"' 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}"' 2> >(tee -a >&2)"

response=$(eval $command)
return_code=$?
Expand Down Expand Up @@ -607,4 +607,4 @@ function process_curl_response() {
else
debug "Success: HTTP status code is ${http_code}" >&2
fi
}
}

0 comments on commit fecd567

Please sign in to comment.