diff --git a/prepare-tf/README.md b/prepare-tf/README.md index d2fd2806..a89a1680 100644 --- a/prepare-tf/README.md +++ b/prepare-tf/README.md @@ -90,17 +90,16 @@ terraform init 3. Configure provider authentication. -See steps above, and add the following extra steps: +Our Terraform configurations try to pick up provider authentication information from +local configuration files typically used by the CLI tool of each provider. Our goal +is to make sure that you don't have to set extra environment variables when applying +the Terraform configurations, as long as the CLI tool of that provider has the relevant +authentication information. -- Digital Ocean: - ```bash - export DIGITALOCEAN_ACCESS_TOKEN=$(grep ^access-token ~/.config/doctl/config.yaml | cut -d: -f2 | tr -d " ") - ``` +Here are provider-specific instructions: -- Linode: - ```bash - export LINODE_TOKEN=$(grep ^token ~/.config/linode-cli | cut -d= -f2 | tr -d " ") - ``` +- for Digital Ocean, run `doctl auth init`, which will populate `~/.config/doctl/config.yaml` +- for Linode, run `linode-cli configure`, which will populate `~/.config/linode-cli` 4. Decide how many clusters and how many nodes per clusters you want. diff --git a/prepare-tf/cleanup.sh b/prepare-tf/cleanup.sh index 58d73f7e..5bef4432 100755 --- a/prepare-tf/cleanup.sh +++ b/prepare-tf/cleanup.sh @@ -1,6 +1,4 @@ #!/bin/sh -export LINODE_TOKEN=$(grep ^token ~/.config/linode-cli | cut -d= -f2 | tr -d " ") -export DIGITALOCEAN_ACCESS_TOKEN=$(grep ^access-token ~/.config/doctl/config.yaml | cut -d: -f2 | tr -d " ") for T in tag-*; do ( cd $T diff --git a/prepare-tf/run.sh b/prepare-tf/run.sh index 0f5cda33..61da09ab 100755 --- a/prepare-tf/run.sh +++ b/prepare-tf/run.sh @@ -3,14 +3,6 @@ set -e TIME=$(which time) -if [ -f ~/.config/doctl/config.yaml ]; then - export DIGITALOCEAN_ACCESS_TOKEN=$(grep ^access-token ~/.config/doctl/config.yaml | cut -d: -f2 | tr -d " ") -fi - -if [ -f ~/.config/linode-cli ]; then - export LINODE_TOKEN=$(grep ^token ~/.config/linode-cli | cut -d= -f2 | tr -d " ") -fi - [ "$1" ] || { echo "Syntax:" echo "" @@ -58,9 +50,6 @@ PROVIDER="$1" exit 1 } -export LINODE_TOKEN=$(grep ^token ~/.config/linode-cli | cut -d= -f2 | tr -d " ") -export DIGITALOCEAN_ACCESS_TOKEN=$(grep ^access-token ~/.config/doctl/config.yaml | cut -d: -f2 | tr -d " ") - cp -a source $TAG cd $TAG cp -r modules/$PROVIDER modules/PROVIDER diff --git a/prepare-tf/source/modules/digitalocean/providers.tf b/prepare-tf/source/modules/digitalocean/providers.tf index 85da66b3..c2cb425d 100644 --- a/prepare-tf/source/modules/digitalocean/providers.tf +++ b/prepare-tf/source/modules/digitalocean/providers.tf @@ -6,3 +6,7 @@ terraform { } } } + +provider "digitalocean" { + token = yamldecode(file("~/.config/doctl/config.yaml"))["access-token"] +} diff --git a/prepare-tf/source/modules/linode/providers.tf b/prepare-tf/source/modules/linode/providers.tf index 010bf865..bddcd7ee 100644 --- a/prepare-tf/source/modules/linode/providers.tf +++ b/prepare-tf/source/modules/linode/providers.tf @@ -6,3 +6,7 @@ terraform { } } } + +provider "digitalocean" { + token = yamldecode(file("~/.config/doctl/config.yaml"))["access-token"] +}