github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/ops/terraform/scripts/connect_workspace.sh (about)

     1  #!/bin/bash
     2  
     3  # a script that will automatically connect to the correct google project
     4  # based on a terraform variables file
     5  # a bit like kubectx but for bacalhau terraform clusters
     6  set -euo pipefail
     7  IFS=$'\n\t'
     8  
     9  export WORKSPACE=${1:-""}
    10  export VARIABLES_FILE=${VARIABLES_FILE:-"$WORKSPACE.tfvars"}
    11  
    12  if [ -z "$WORKSPACE" ]; then
    13    echo "Usage: $0 <workspace>"
    14    exit 1
    15  fi
    16  
    17  if [ ! -f "$VARIABLES_FILE" ]; then
    18    echo "$VARIABLES_FILE file not found"
    19    exit 1
    20  fi
    21  
    22  function get_variable() {
    23    cat $VARIABLES_FILE | grep "$1" | awk '{print $3}'
    24  }
    25  
    26  eval "gcloud config set project $(get_variable gcp_project)"
    27  eval "gcloud config set compute/zone $(get_variable zone)"
    28  eval "terraform workspace select $WORKSPACE"