mirror of
https://github.com/jpetazzo/container.training.git
synced 2026-07-23 06:46:27 +00:00
🏭️ Refactor Digital Ocean and Linode authentication in prepare-tf
Fetch credentials from CLI configuration files instead of environment variables.
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -6,3 +6,7 @@ terraform {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "digitalocean" {
|
||||
token = yamldecode(file("~/.config/doctl/config.yaml"))["access-token"]
|
||||
}
|
||||
|
||||
@@ -6,3 +6,7 @@ terraform {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "digitalocean" {
|
||||
token = yamldecode(file("~/.config/doctl/config.yaml"))["access-token"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user