From 9526a94b77918712b26762bbd6752c28f1e8d611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Petazzoni?= Date: Mon, 23 Jan 2023 16:07:28 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9A=20Improve=20Terraform-based=20depl?= =?UTF-8?q?oyment=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each time we call that script, we must set a few env vars beforehand. Let's make these vars optional parameters to the script instead. Also add helper scripts to list the locations (zones or regions) available to each provider. --- prepare-tf/README.md | 34 ++++--------------- prepare-tf/run.sh | 24 +++++++++++-- .../modules/digitalocean/list_locations.sh | 2 ++ .../modules/googlecloud/list_locations.sh | 2 ++ .../source/modules/linode/list_locations.sh | 2 ++ .../modules/oraclecloud/list_locations.sh | 2 ++ .../source/modules/scaleway/list_locations.sh | 6 ++++ 7 files changed, 42 insertions(+), 30 deletions(-) create mode 100755 prepare-tf/source/modules/digitalocean/list_locations.sh create mode 100755 prepare-tf/source/modules/googlecloud/list_locations.sh create mode 100755 prepare-tf/source/modules/linode/list_locations.sh create mode 100755 prepare-tf/source/modules/oraclecloud/list_locations.sh create mode 100755 prepare-tf/source/modules/scaleway/list_locations.sh diff --git a/prepare-tf/README.md b/prepare-tf/README.md index 1fb515d6..957de6a4 100644 --- a/prepare-tf/README.md +++ b/prepare-tf/README.md @@ -34,28 +34,15 @@ to that directory, then create the clusters using that configuration. - Scaleway: run `scw init` -2. Optional: set number of clusters, cluster size, and region. - -By default, 1 cluster will be configured, with 2 nodes, and auto-scaling up to 5 nodes. - -If you want, you can override these parameters, with the following variables. +2. Run! ```bash -export TF_VAR_how_many_clusters=5 -export TF_VAR_min_nodes_per_pool=2 -export TF_VAR_max_nodes_per_pool=4 -export TF_VAR_location=xxx +./run.sh [number of clusters] [min nodes] [max nodes] ``` -The `location` variable is optional. Each provider should have a default value. -The value of the `location` variable is provider-specific. Examples: +If you don't specify a provider name, it will list available providers. -| Provider | Example value | How to see possible values -|---------------|-------------------|--------------------------- -| Digital Ocean | `ams3` | `doctl compute region list` -| Google Cloud | `europe-north1-a` | `gcloud compute zones list` -| Linode | `eu-central` | `linode-cli regions list` -| Oracle Cloud | `eu-stockholm-1` | `oci iam region list` +If you don't specify a location, it will list locations available for this provider. You can also specify multiple locations, and then they will be used in round-robin fashion. @@ -66,22 +53,15 @@ my requests to increase that quota were denied) you can do the following: ```bash -export TF_VAR_location=$(gcloud compute zones list --format=json | jq -r .[].name | grep ^europe) +LOCATIONS=$(gcloud compute zones list --format=json | jq -r .[].name | grep ^europe) +./run.sh googlecloud "$LOCATIONS" ``` Then when you apply, clusters will be created across all available zones in Europe. (When I write this, there are 20+ zones in Europe, so even with my quota, I can create 40 clusters.) -3. Run! - -```bash -./run.sh -``` - -(If you don't specify a provider name, it will list available providers.) - -4. Shutting down +3. Shutting down Go to the directory that was created by the previous step (`tag-YYYY-MM...`) and run `terraform destroy`. diff --git a/prepare-tf/run.sh b/prepare-tf/run.sh index 723cd6e6..66b75d93 100755 --- a/prepare-tf/run.sh +++ b/prepare-tf/run.sh @@ -11,11 +11,29 @@ if [ -f ~/.config/linode-cli ]; then export LINODE_TOKEN=$(grep ^token ~/.config/linode-cli | cut -d= -f2 | tr -d " ") fi -PROVIDER=$1 -[ "$PROVIDER" ] || { - echo "Please specify a provider as first argument, or 'ALL' for parallel mode." +[ "$1" ] || { + echo "Syntax:" + echo "" + echo "$0 [how-many-clusters] [min-nodes] [max-nodes]" + echo "" echo "Available providers:" ls -1 source/modules + echo "" + echo "Leave the region empty to show available regions for this provider." + echo "You can also specify ALL as a provider to simultaneously provision" + echo "many clusters on *each* provider for benchmarking purposes." + echo "" + exit 1 +} + +PROVIDER="$1" +export TF_VAR_location="$2" +export TF_VAR_how_many_clusters="${3-1}" +export TF_VAR_min_nodes_per_pool="${4-2}" +export TF_VAR_max_nodes_per_pool="${5-4}" + +[ "$TF_VAR_location" ] || { + "./source/modules/$PROVIDER/list_locations.sh" exit 1 } diff --git a/prepare-tf/source/modules/digitalocean/list_locations.sh b/prepare-tf/source/modules/digitalocean/list_locations.sh new file mode 100755 index 00000000..6c1ba125 --- /dev/null +++ b/prepare-tf/source/modules/digitalocean/list_locations.sh @@ -0,0 +1,2 @@ +#!/bin/sh +doctl compute region list \ No newline at end of file diff --git a/prepare-tf/source/modules/googlecloud/list_locations.sh b/prepare-tf/source/modules/googlecloud/list_locations.sh new file mode 100755 index 00000000..5efea111 --- /dev/null +++ b/prepare-tf/source/modules/googlecloud/list_locations.sh @@ -0,0 +1,2 @@ +#!/bin/sh +gcloud compute zones list \ No newline at end of file diff --git a/prepare-tf/source/modules/linode/list_locations.sh b/prepare-tf/source/modules/linode/list_locations.sh new file mode 100755 index 00000000..98e58f29 --- /dev/null +++ b/prepare-tf/source/modules/linode/list_locations.sh @@ -0,0 +1,2 @@ +#!/bin/sh +linode-cli regions list \ No newline at end of file diff --git a/prepare-tf/source/modules/oraclecloud/list_locations.sh b/prepare-tf/source/modules/oraclecloud/list_locations.sh new file mode 100755 index 00000000..4c1defb0 --- /dev/null +++ b/prepare-tf/source/modules/oraclecloud/list_locations.sh @@ -0,0 +1,2 @@ +#!/bin/sh +oci iam region list \ No newline at end of file diff --git a/prepare-tf/source/modules/scaleway/list_locations.sh b/prepare-tf/source/modules/scaleway/list_locations.sh new file mode 100755 index 00000000..0bcae1eb --- /dev/null +++ b/prepare-tf/source/modules/scaleway/list_locations.sh @@ -0,0 +1,6 @@ +#!/bin/sh +echo "# Note that this is hard-coded in $0. +# I don't know if there is a way to list regions through the Scaleway API. +fr-par +nl-ams +pl-waw"