added .envrc-terraform
8566243a
Hari Sekhon
committed
1 changed file
.envrc-terraform
/.envrc-terraform+57
/.envrc-terraform
Add comment 1 Plus  #!/usr/bin/env bash
Add comment 2 Plus  # vim:ts=4:sts=4:sw=4:et
Add comment 3 Plus  #
Add comment 4 Plus  # Author: Hari Sekhon
Add comment 5 Plus  # Date: Mon Feb 22 17:42:01 2021 +0000
Add comment 6 Plus  #
Add comment 7 Plus  # https://github.com/HariSekhon/Environments
Add comment 8 Plus  #
Add comment 9 Plus  # License: see accompanying Hari Sekhon LICENSE file
Add comment 10 Plus  #
Add comment 11 Plus  # If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
Add comment 12 Plus  #
Add comment 13 Plus  # https://www.linkedin.com/in/HariSekhon
Add comment 14 Plus  #
Add comment 15 Plus  
Add comment 16 Plus  # ============================================================================ #
Add comment 17 Plus  # T e r r a f o r m D i r E n v
Add comment 18 Plus  # ============================================================================ #
Add comment 19 Plus  
Add comment 20 Plus  set -euo pipefail
Add comment 21 Plus  [ -n "${DEBUG:-}" ] && set -x
Add comment 22 Plus  #srcdir="$(dirname "${BASH_SOURCE[0]}")"
Add comment 23 Plus  
Add comment 24 Plus  # XXX: beware that tfenv and tgswitch replace the terraform / terragrunt in the path and this is a race condition between different shells
Add comment 25 Plus  # it is not as good as the KUBECONFIG trick done in the .envrc-kubernetes
Add comment 26 Plus  
Add comment 27 Plus  # would auto-determine the version from the state file, but this commands seems to always return the version of your local binary pulling the state file, not the version from the actual terraform_version field in state file if you see when opening it up in the cloud bucket
Add comment 28 Plus  # terraform state pull | jq -r .terraform_version
Add comment 29 Plus  export TERRAFORM_VERSION=1.1.9
Add comment 30 Plus  
Add comment 31 Plus  # overrides .terraform-version file to make this single source of truth
Add comment 32 Plus  export TFENV_TERRAFORM_VERSION="$TERRAFORM_VERSION"
Add comment 33 Plus  export TFENV_AUTO_INSTALL=true
Add comment 34 Plus  
Add comment 35 Plus  # Terragrunt
Add comment 36 Plus  export TG_VERSION=0.39.2
Add comment 37 Plus  
Add comment 38 Plus  # if tgswitch is installed, trigger it to use the above TF_VERSION environment variable and switch to the correct version of Terragrunt
Add comment 39 Plus  # better than adding the ugly shell hook from the docs - https://github.com/warrensbox/tgswitch?tab=readme-ov-file#get-the-version-from-a-subdirectory
Add comment 40 Plus  if type -P tgswitch &>/dev/null; then
Add comment 41 Plus   tgswitch
Add comment 42 Plus  fi
Add comment 43 Plus  
Add comment 44 Plus  # XXX: set these or other variables for Terraform code to find
Add comment 45 Plus  export CLOUDFLARE_EMAIL=hari@...
Add comment 46 Plus  export CLOUDFLARE_API_KEY=... # generate here: https://dash.cloudflare.com/profile/api-tokens
Add comment 47 Plus  #export CLOUDFLARE_TOKEN=... # used by cloudflare_api.sh but not by terraform module
Add comment 48 Plus  
Add comment 49 Plus  # export the variables for terraform
Add comment 50 Plus  export TF_VAR_cloudflare_email="$CLOUDFLARE_EMAIL"
Add comment 51 Plus  export TF_VAR_cloudflare_api_key="$CLOUDFLARE_API_KEY" # must be a key, not a token using the link above
Add comment 52 Plus  
Add comment 53 Plus  # GITHUB_* environment variables may interfere with GitHub provider, so unset them
Add comment 54 Plus  for env_var in $(env | awk -F= '$1 ~ /GITHUB/ {print $1}'); do
Add comment 55 Plus   unset "$env_var"
Add comment 56 Plus  done
Add comment 57 Plus