mirror of
https://github.com/jpetazzo/container.training.git
synced 2026-02-14 17:49:59 +00:00
🏭️ Second pass of Terraform refactoring
Break down provider-specific configuration into two files: - config.tf (actual configuration, e.g. credentials, that cannot be included in submodules) - variables.tf (per-provider knobs and settings, e.g. mapping logical VM size like S/M/L to actual cloud SKUs)
This commit is contained in:
@@ -120,11 +120,19 @@ Legend:
|
||||
│ ├── 📄common.tf
|
||||
│ ├── 📁🌍digitalocean
|
||||
│ └── ...
|
||||
├── 📁provider-config
|
||||
│ ├── 📄aws.tf
|
||||
│ ├── 📄azure.tf
|
||||
│ ├── 📄civo.tf
|
||||
│ ├── 📄digitalocean.tf
|
||||
├── 📁providers
|
||||
│ ├── 📁aws
|
||||
│ │ ├── 📄config.tf
|
||||
│ │ └── 📄variables.tf
|
||||
│ ├── 📁azure
|
||||
│ │ ├── 📄config.tf
|
||||
│ │ └── 📄variables.tf
|
||||
│ ├── 📁civo
|
||||
│ │ ├── 📄config.tf
|
||||
│ │ └── 📄variables.tf
|
||||
│ ├── 📁digitalocean
|
||||
│ │ ├── 📄config.tf
|
||||
│ │ └── 📄variables.tf
|
||||
│ └── ...
|
||||
├── 📁tags
|
||||
│ │ (contains Terraform configurations + other files
|
||||
@@ -150,7 +158,7 @@ The directory structure can feel a bit overwhelming at first, but it's built wit
|
||||
|
||||
**Don't repeat yourself.** As much as possible, common variables, definitions, and logic has been factored in the `common.tf` file that you can see in `one-kubernetes` and `virtual-machines`. That file is then symlinked in each provider-specific directory, to make sure that all providers use the same version of the `common.tf` file.
|
||||
|
||||
**Don't repeat yourself (again).** The things that are specific to each provider (e.g. how to obtain the credentials; the size of the VMs to use...) have been placed in the `provider-config` directory, and are shared between the `one-kubernetes` and the `virtual-machines` configurations.
|
||||
**Don't repeat yourself (again).** The things that are specific to each provider have been placed in the `providers` directory, and are shared between the `one-kubernetes` and the `virtual-machines` configurations. Specifically, for each provider, there is `config.tf` (which contains provider configuration, e.g. how to obtain the credentials for that provider) and `variables.tf` (which contains default values like which location and which VM size to use).
|
||||
|
||||
**Terraform configurations should work in `labctl` or standalone, without extra work.** The Terraform configurations (identified by 🌍 in the directory tree above) can be used directly. Just go to one of these directories, `terraform init`, `terraform apply`, and you're good to go. But they can also be used from `labctl`. `labctl` shouldn't barf out if you did a `terraform apply` in one of these directories (because it will only copy the `*.tf` files, and leave alone the other files, like the Terraform state).
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ module "clusters" {
|
||||
cluster_name = each.value.cluster_name
|
||||
min_nodes_per_pool = local.min_nodes_per_pool
|
||||
max_nodes_per_pool = local.max_nodes_per_pool
|
||||
enable_arm_pool = var.enable_arm_pool
|
||||
node_size = var.node_size
|
||||
common_tags = local.common_tags
|
||||
location = each.value.location
|
||||
|
||||
@@ -17,13 +17,8 @@ variable "node_size" {
|
||||
default = "M"
|
||||
}
|
||||
|
||||
variable "enable_arm_pool" {
|
||||
type = bool
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "location" {
|
||||
type = string
|
||||
type = string
|
||||
default = null
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
../../provider-config/aws.tf
|
||||
../../providers/aws/config.tf
|
||||
1
prepare-labs/terraform/one-kubernetes/aws/variables.tf
Symbolic link
1
prepare-labs/terraform/one-kubernetes/aws/variables.tf
Symbolic link
@@ -0,0 +1 @@
|
||||
../../providers/aws/variables.tf
|
||||
@@ -1 +1 @@
|
||||
../../provider-config/civo.tf
|
||||
../../providers/civo/config.tf
|
||||
@@ -4,4 +4,4 @@ terraform {
|
||||
source = "civo/civo"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1
prepare-labs/terraform/one-kubernetes/civo/variables.tf
Symbolic link
1
prepare-labs/terraform/one-kubernetes/civo/variables.tf
Symbolic link
@@ -0,0 +1 @@
|
||||
../../providers/civo/variables.tf
|
||||
@@ -1 +1 @@
|
||||
../../provider-config/digitalocean.tf
|
||||
../../providers/digitalocean/config.tf
|
||||
1
prepare-labs/terraform/one-kubernetes/digitalocean/variables.tf
Symbolic link
1
prepare-labs/terraform/one-kubernetes/digitalocean/variables.tf
Symbolic link
@@ -0,0 +1 @@
|
||||
../../providers/digitalocean/variables.tf
|
||||
@@ -1 +1 @@
|
||||
../../provider-config/exoscale.tf
|
||||
../../providers/exoscale/config.tf
|
||||
1
prepare-labs/terraform/one-kubernetes/exoscale/variables.tf
Symbolic link
1
prepare-labs/terraform/one-kubernetes/exoscale/variables.tf
Symbolic link
@@ -0,0 +1 @@
|
||||
../../providers/exoscale/variables.tf
|
||||
@@ -1 +1 @@
|
||||
../../provider-config/googlecloud.tf
|
||||
../../providers/googlecloud/config.tf
|
||||
12
prepare-labs/terraform/one-kubernetes/googlecloud/locals.tf
Normal file
12
prepare-labs/terraform/one-kubernetes/googlecloud/locals.tf
Normal file
@@ -0,0 +1,12 @@
|
||||
locals {
|
||||
location = var.location != null ? var.location : "europe-north1-a"
|
||||
region = replace(local.location, "/-[a-z]$/", "")
|
||||
# Unfortunately, the following line doesn't work
|
||||
# (that attribute just returns an empty string)
|
||||
# so we have to hard-code the project name.
|
||||
#project = data.google_client_config._.project
|
||||
project = "prepare-tf"
|
||||
}
|
||||
|
||||
data "google_client_config" "_" {}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
locals {
|
||||
location = var.location != null ? var.location : "europe-north1-a"
|
||||
region = replace(local.location, "/-[a-z]$/", "")
|
||||
# Unfortunately, the following line doesn't work
|
||||
# (that attribute just returns an empty string)
|
||||
# so we have to hard-code the project name.
|
||||
#project = data.google_client_config._.project
|
||||
project = "prepare-tf"
|
||||
}
|
||||
|
||||
data "google_client_config" "_" {}
|
||||
|
||||
1
prepare-labs/terraform/one-kubernetes/googlecloud/variables.tf
Symbolic link
1
prepare-labs/terraform/one-kubernetes/googlecloud/variables.tf
Symbolic link
@@ -0,0 +1 @@
|
||||
../../providers/googlecloud/variables.tf
|
||||
@@ -1 +1 @@
|
||||
../../provider-config/linode.tf
|
||||
../../providers/linode/config.tf
|
||||
1
prepare-labs/terraform/one-kubernetes/linode/variables.tf
Symbolic link
1
prepare-labs/terraform/one-kubernetes/linode/variables.tf
Symbolic link
@@ -0,0 +1 @@
|
||||
../../providers/linode/variables.tf
|
||||
@@ -1 +1 @@
|
||||
../../provider-config/oci.tf
|
||||
../../providers/oci/config.tf
|
||||
1
prepare-labs/terraform/one-kubernetes/oci/variables.tf
Symbolic link
1
prepare-labs/terraform/one-kubernetes/oci/variables.tf
Symbolic link
@@ -0,0 +1 @@
|
||||
../../providers/oci/variables.tf
|
||||
@@ -1 +1 @@
|
||||
../../provider-config/scaleway.tf
|
||||
../../providers/scaleway/config.tf
|
||||
1
prepare-labs/terraform/one-kubernetes/scaleway/variables.tf
Symbolic link
1
prepare-labs/terraform/one-kubernetes/scaleway/variables.tf
Symbolic link
@@ -0,0 +1 @@
|
||||
../../providers/scaleway/variables.tf
|
||||
@@ -1 +1 @@
|
||||
../../provider-config/vcluster.tf
|
||||
../../providers/vcluster/config.tf
|
||||
@@ -1,9 +0,0 @@
|
||||
variable "node_sizes" {
|
||||
type = map(string)
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "location" {
|
||||
type = string
|
||||
default = null
|
||||
}
|
||||
|
||||
1
prepare-labs/terraform/one-kubernetes/vcluster/variables.tf
Symbolic link
1
prepare-labs/terraform/one-kubernetes/vcluster/variables.tf
Symbolic link
@@ -0,0 +1 @@
|
||||
../../providers/vcluster/variables.tf
|
||||
3
prepare-labs/terraform/providers/aws/config.tf
Normal file
3
prepare-labs/terraform/providers/aws/config.tf
Normal file
@@ -0,0 +1,3 @@
|
||||
provider "aws" {
|
||||
region = var.location
|
||||
}
|
||||
@@ -1,7 +1,3 @@
|
||||
provider "aws" {
|
||||
region = var.location
|
||||
}
|
||||
|
||||
variable "node_sizes" {
|
||||
type = map(any)
|
||||
default = {
|
||||
3
prepare-labs/terraform/providers/azure/config.tf
Normal file
3
prepare-labs/terraform/providers/azure/config.tf
Normal file
@@ -0,0 +1,3 @@
|
||||
provider "azurerm" {
|
||||
features {}
|
||||
}
|
||||
@@ -1,7 +1,3 @@
|
||||
provider "azurerm" {
|
||||
features {}
|
||||
}
|
||||
|
||||
/*
|
||||
Available sizes:
|
||||
"Standard_D11_v2" # CPU=2 RAM=14
|
||||
@@ -7,17 +7,3 @@ locals {
|
||||
civo_current = local.civo_config.meta.current_apikey
|
||||
civo_apikey = local.civo_config.apikeys[local.civo_current]
|
||||
}
|
||||
|
||||
variable "node_sizes" {
|
||||
type = map(any)
|
||||
default = {
|
||||
S = "g4s.kube.small"
|
||||
M = "g4s.kube.medium"
|
||||
L = "g4s.kube.large"
|
||||
}
|
||||
}
|
||||
|
||||
variable "location" {
|
||||
type = string
|
||||
default = "lon1"
|
||||
}
|
||||
13
prepare-labs/terraform/providers/civo/variables.tf
Normal file
13
prepare-labs/terraform/providers/civo/variables.tf
Normal file
@@ -0,0 +1,13 @@
|
||||
variable "node_sizes" {
|
||||
type = map(any)
|
||||
default = {
|
||||
S = "g4s.kube.small"
|
||||
M = "g4s.kube.medium"
|
||||
L = "g4s.kube.large"
|
||||
}
|
||||
}
|
||||
|
||||
variable "location" {
|
||||
type = string
|
||||
default = "lon1"
|
||||
}
|
||||
3
prepare-labs/terraform/providers/digitalocean/config.tf
Normal file
3
prepare-labs/terraform/providers/digitalocean/config.tf
Normal file
@@ -0,0 +1,3 @@
|
||||
provider "digitalocean" {
|
||||
token = yamldecode(file("~/.config/doctl/config.yaml"))["access-token"]
|
||||
}
|
||||
@@ -1,7 +1,3 @@
|
||||
provider "digitalocean" {
|
||||
token = yamldecode(file("~/.config/doctl/config.yaml"))["access-token"]
|
||||
}
|
||||
|
||||
variable "node_sizes" {
|
||||
type = map(any)
|
||||
default = {
|
||||
@@ -2,17 +2,3 @@ provider "exoscale" {
|
||||
key = regex("\n key *= *\"([^\"]+)\"\n", file("~/.config/exoscale/exoscale.toml"))[0]
|
||||
secret = regex("\n secret *= *\"([^\"]+)\"\n", file("~/.config/exoscale/exoscale.toml"))[0]
|
||||
}
|
||||
|
||||
variable "node_sizes" {
|
||||
type = map(any)
|
||||
default = {
|
||||
S = "standard.small"
|
||||
M = "standard.medium"
|
||||
L = "standard.large"
|
||||
}
|
||||
}
|
||||
|
||||
variable "location" {
|
||||
type = string
|
||||
default = "ch-gva-2"
|
||||
}
|
||||
13
prepare-labs/terraform/providers/exoscale/variables.tf
Normal file
13
prepare-labs/terraform/providers/exoscale/variables.tf
Normal file
@@ -0,0 +1,13 @@
|
||||
variable "node_sizes" {
|
||||
type = map(any)
|
||||
default = {
|
||||
S = "standard.small"
|
||||
M = "standard.medium"
|
||||
L = "standard.large"
|
||||
}
|
||||
}
|
||||
|
||||
variable "location" {
|
||||
type = string
|
||||
default = "ch-gva-2"
|
||||
}
|
||||
9
prepare-labs/terraform/providers/hetzner/config.tf
Normal file
9
prepare-labs/terraform/providers/hetzner/config.tf
Normal file
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
Okay, the following is pretty gross - it uses the first token found in the hcloud CLI
|
||||
configuration file. We don't use Hetzner much anyway, and when we do, we only have one
|
||||
profile ever, and we want this thing to Just Work; so this should do for now, but might
|
||||
need to be improved if others actively use Hetzner to provision training labs.
|
||||
*/
|
||||
provider "hcloud" {
|
||||
token = regex("token = \"([A-Za-z0-9]+)\"", file("~/.config/hcloud/cli.toml"))[0]
|
||||
}
|
||||
@@ -1,13 +1,3 @@
|
||||
/*
|
||||
Okay, the following is pretty gross - it uses the first token found in the hcloud CLI
|
||||
configuration file. We don't use Hetzner much anyway, and when we do, we only have one
|
||||
profile ever, and we want this thing to Just Work; so this should do for now, but might
|
||||
need to be improved if others actively use Hetzner to provision training labs.
|
||||
*/
|
||||
provider "hcloud" {
|
||||
token = regex("token = \"([A-Za-z0-9]+)\"", file("~/.config/hcloud/cli.toml"))[0]
|
||||
}
|
||||
|
||||
/*
|
||||
$ hcloud server-type list | grep shared
|
||||
1 cx11 1 shared 2.0 GB 20 GB local
|
||||
3
prepare-labs/terraform/providers/linode/config.tf
Normal file
3
prepare-labs/terraform/providers/linode/config.tf
Normal file
@@ -0,0 +1,3 @@
|
||||
provider "linode" {
|
||||
token = regex("\ntoken *= *([0-9a-f]+)\n", file("~/.config/linode-cli"))[0]
|
||||
}
|
||||
@@ -1,7 +1,3 @@
|
||||
provider "linode" {
|
||||
token = regex("\ntoken *= *([0-9a-f]+)\n", file("~/.config/linode-cli"))[0]
|
||||
}
|
||||
|
||||
/*
|
||||
Available sizes:
|
||||
"g6-standard-1" # CPU=1 RAM=2
|
||||
0
prepare-labs/terraform/providers/oci/config.tf
Normal file
0
prepare-labs/terraform/providers/oci/config.tf
Normal file
0
prepare-labs/terraform/providers/scaleway/config.tf
Normal file
0
prepare-labs/terraform/providers/scaleway/config.tf
Normal file
9
prepare-labs/terraform/providers/vcluster/variables.tf
Normal file
9
prepare-labs/terraform/providers/vcluster/variables.tf
Normal file
@@ -0,0 +1,9 @@
|
||||
variable "node_sizes" {
|
||||
type = map(any)
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "location" {
|
||||
type = string
|
||||
default = null
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
../../provider-config/aws.tf
|
||||
../../providers/aws/config.tf
|
||||
1
prepare-labs/terraform/virtual-machines/aws/variables.tf
Symbolic link
1
prepare-labs/terraform/virtual-machines/aws/variables.tf
Symbolic link
@@ -0,0 +1 @@
|
||||
../../providers/aws/variables.tf
|
||||
@@ -1 +1 @@
|
||||
../../provider-config/azure.tf
|
||||
../../providers/azure/config.tf
|
||||
1
prepare-labs/terraform/virtual-machines/azure/variables.tf
Symbolic link
1
prepare-labs/terraform/virtual-machines/azure/variables.tf
Symbolic link
@@ -0,0 +1 @@
|
||||
../../providers/azure/variables.tf
|
||||
@@ -1 +1 @@
|
||||
../../provider-config/digitalocean.tf
|
||||
../../providers/digitalocean/config.tf
|
||||
@@ -0,0 +1 @@
|
||||
../../providers/digitalocean/variables.tf
|
||||
@@ -1 +1 @@
|
||||
../../provider-config/hetzner.tf
|
||||
../../providers/hetzner/config.tf
|
||||
1
prepare-labs/terraform/virtual-machines/hetzner/variables.tf
Symbolic link
1
prepare-labs/terraform/virtual-machines/hetzner/variables.tf
Symbolic link
@@ -0,0 +1 @@
|
||||
../../providers/hetzner/variables.tf
|
||||
@@ -1 +1 @@
|
||||
../../provider-config/linode.tf
|
||||
../../providers/linode/config.tf
|
||||
1
prepare-labs/terraform/virtual-machines/linode/variables.tf
Symbolic link
1
prepare-labs/terraform/virtual-machines/linode/variables.tf
Symbolic link
@@ -0,0 +1 @@
|
||||
../../providers/linode/variables.tf
|
||||
@@ -1 +1 @@
|
||||
../../provider-config/oci.tf
|
||||
../../providers/oci/config.tf
|
||||
1
prepare-labs/terraform/virtual-machines/oci/variables.tf
Symbolic link
1
prepare-labs/terraform/virtual-machines/oci/variables.tf
Symbolic link
@@ -0,0 +1 @@
|
||||
../../providers/oci/variables.tf
|
||||
1
prepare-labs/terraform/virtual-machines/openstack/config.tf
Symbolic link
1
prepare-labs/terraform/virtual-machines/openstack/config.tf
Symbolic link
@@ -0,0 +1 @@
|
||||
../../providers/openstack/config.tf
|
||||
1
prepare-labs/terraform/virtual-machines/openstack/variables.tf
Symbolic link
1
prepare-labs/terraform/virtual-machines/openstack/variables.tf
Symbolic link
@@ -0,0 +1 @@
|
||||
../../providers/openstack/variables.tf
|
||||
@@ -1 +1 @@
|
||||
../../provider-config/scaleway.tf
|
||||
../../providers/scaleway/config.tf
|
||||
1
prepare-labs/terraform/virtual-machines/scaleway/variables.tf
Symbolic link
1
prepare-labs/terraform/virtual-machines/scaleway/variables.tf
Symbolic link
@@ -0,0 +1 @@
|
||||
../../providers/scaleway/variables.tf
|
||||
Reference in New Issue
Block a user