aztfmod / rover

The rover is a docker container in charge of the deployment of the Terraform platform engineering for Azure
MIT License
175 stars 147 forks source link

Error when run Rover on Ubuntu and error 404 when checking Terraform Cloud Agent exist #357

Open hanganhhung123 opened 1 year ago

hanganhhung123 commented 1 year ago

1. An error occur when I run Rover on Ubuntu 20.04

in tfcloud.sh#539 file, function process_curl_response() has 2 lines to curl the TFE with token and redirect to STDERR by 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 /dev/stderr)"
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)"

When I try to do the migration to Terraform Cloud, below is the error I'm face with

tee: /dev/stderr: No such device or address
Error /tf/rover/tfcloud/tfcloud.sh on or near line 543; exiting with status 1

I have made some changes to remove the 2> >(tee /dev/stderr) out of tfcloud.sh and rerun the migration, it's worked. So I need some help to remove the 2> >(tee /dev/stderr) in the code, or are there any other solution for it?

2. Terraform Cloud Agent Check failure

in tfcloud.sh#43, the function check_terraform_cloud_agent_exist() check if the tfcloud agent exist via url

url="https://${TF_VAR_tf_cloud_hostname}/api/v2/organizations/${TF_VAR_tf_cloud_organization}/agent-pools"

or

url="https://${TF_VAR_tf_cloud_hostname}/api/v2/organizations/${TF_VAR_tf_cloud_organization}/agent-pools/${gitops_agent_pool_id}"

When I run the Terraform Cloud migrate/plan/apply with agent mode, it throw this error:

Gracefully continue on error: HTTP status code is 404 for https://*****.com/api/v2/organizations/*****/agent-pools/apool-*****
apool-*****

Base on the latest api-docs from Harshicorp to list agent, the valid format of the url must not have the suffix /organizations/${TF_VAR_tf_cloud_organization}. It has pass from my testing also. I need some help to fix it for latest run.

LaurentLesle commented 1 year ago

Can you check the user running the rover has permission to /dev/stderr?

ls -l /dev/stderr
hanganhhung123 commented 11 months ago

Hi @LaurentLesle, The agent is runing with root user and it can access to /dev/stderr as bellow.

Screenshot 2023-12-18 at 15 31 49

I found out that /dev/stderr is equivalent with &2. On linux, write to &2 works for every user; write to /dev/stderr works only for root users. I don't know why root user cannot write standard error into stderr. I have make some test to replace 2> >(tee /dev/stderr) by 2> >(tee -a >&2) and the error gone