From f5829d2be6b72e17cbeb1ef9111a0979755a7ad0 Mon Sep 17 00:00:00 2001 From: Ben Potter Date: Sun, 3 Sep 2023 18:26:48 -0500 Subject: [PATCH] chore(dogfood): authenticate to `coder` CLI if unauthenticated (#9487) --- dogfood/main.tf | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dogfood/main.tf b/dogfood/main.tf index 43bf7c973e..ba61d1d352 100644 --- a/dogfood/main.tf +++ b/dogfood/main.tf @@ -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 }