🏭️ Refactor Digital Ocean and Linode authentication in prepare-tf

Fetch credentials from CLI configuration files instead of environment variables.
This commit is contained in:
Jérôme Petazzoni
2023-03-04 14:35:09 +01:00
parent 8738f68a72
commit 84f131cdc5
5 changed files with 16 additions and 22 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -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

View File

@@ -6,3 +6,7 @@ terraform {
}
}
}
provider "digitalocean" {
token = yamldecode(file("~/.config/doctl/config.yaml"))["access-token"]
}

View File

@@ -6,3 +6,7 @@ terraform {
}
}
}
provider "digitalocean" {
token = yamldecode(file("~/.config/doctl/config.yaml"))["access-token"]
}