chore(dogfood): authenticate to `coder` CLI if unauthenticated (#9487)

This commit is contained in:
Ben Potter 2023-09-03 18:26:48 -05:00 committed by GitHub
parent 05439d2c1b
commit f5829d2be6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 0 deletions

View File

@ -90,6 +90,8 @@ resource "coder_agent" "dev" {
env = {
GITHUB_TOKEN : data.coder_git_auth.github.access_token,
OIDC_TOKEN : data.coder_workspace.me.owner_oidc_access_token,
CODER_USER_TOKEN : data.coder_workspace.me.owner_session_token,
CODER_DEPLOYMENT_URL : data.coder_workspace.me.access_url
}
startup_script_behavior = "blocking"
@ -202,6 +204,15 @@ resource "coder_agent" "dev" {
elif [ -f ~/personalize ]; then
echo "~/personalize is not executable, skipping..." | tee -a ~/.personalize.log
fi
# Automatically authenticate the user if they are not
# logged in to another deployment
if ! coder list >/dev/null 2>&1; then
set +x; coder login --token=$CODER_USER_TOKEN --url=$CODER_DEPLOYMENT_URL
else
echo "You are already authenticated with coder"
fi
EOT
}