From e338c2616ea3f0ab4c9ea3766751d376003588a3 Mon Sep 17 00:00:00 2001 From: Noel Georgi Date: Tue, 26 Mar 2024 17:31:25 +0530 Subject: [PATCH] chore: modularize equinix code for e2e make the equinix code similar to AWS and Azure so that we can use it for e2e tests. Signed-off-by: Noel Georgi --- .drone.yaml | 9 +- examples/terraform/aws/main.tf | 1 + .../equinix-metal/.terraform.lock.hcl | 69 +++++---- examples/terraform/equinix-metal/README.md | 49 +++--- .../equinix-metal/equinix-arm64.yaml | 3 + examples/terraform/equinix-metal/main.tf | 139 +++++++++++++----- .../templates/installer.yaml.tmpl | 3 + examples/terraform/equinix-metal/variables.tf | 67 +++++++-- examples/terraform/equinix-metal/versions.tf | 4 +- 9 files changed, 231 insertions(+), 113 deletions(-) create mode 100644 examples/terraform/equinix-metal/equinix-arm64.yaml create mode 100644 examples/terraform/equinix-metal/templates/installer.yaml.tmpl diff --git a/.drone.yaml b/.drone.yaml index 5a0d24f..d78ec25 100644 --- a/.drone.yaml +++ b/.drone.yaml @@ -60,11 +60,16 @@ steps: AWS_SECRET_ACCESS_KEY: from_secret: 'aws_secret_access_key' commands: + - mkdir -p _out - cp hack/backend.tf examples/terraform/${TYPE}/backend.tf + - az login --service-principal -u "$${ARM_CLIENT_ID}" -p "$${ARM_CLIENT_SECRET}" --tenant "$${ARM_TENANT_ID}" + - az storage blob download-batch --overwrite -d _out --pattern "e2e-$${TYPE}-generated/*" -s ${BUCKET_PATH} + # copying the downloaded vars + - mv _out/e2e-${TYPE}-generated/* examples/terraform/${TYPE} - terraform -chdir=examples/terraform/${TYPE} init -backend-config="resource_group_name=General" -backend-config="storage_account_name=$${AZURE_STORAGE_ACCOUNT}" -backend-config="container_name=${BUCKET_PATH}" -backend-config="key=${TYPE}-terraform.tfstate" # lets attempt to remove the talosconfig/kubeconfig data source so destroy is not blocked - - terraform -chdir=examples/terraform/${TYPE} state rm data.talos_client_configuration.this data.talos_cluster_kubeconfig.this || true - - terraform -chdir=examples/terraform/${TYPE} apply -destroy -auto-approve + - terraform -chdir=examples/terraform/${TYPE} state rm data.talos_client_configuration.this data.talos_cluster_kubeconfig.this data.talos_cluster_health.this || true + - terraform -chdir=examples/terraform/${TYPE} apply -destroy -auto-approve -var-file="vars.json" -refresh="$${REFRESH_ON_DESTROY:-true}" when: event: - promote diff --git a/examples/terraform/aws/main.tf b/examples/terraform/aws/main.tf index 4727c0a..9ed89bc 100644 --- a/examples/terraform/aws/main.tf +++ b/examples/terraform/aws/main.tf @@ -382,6 +382,7 @@ data "talos_client_configuration" "this" { cluster_name = var.cluster_name client_configuration = talos_machine_secrets.this.client_configuration endpoints = module.talos_control_plane_nodes.*.public_ip + nodes = flatten([module.talos_control_plane_nodes.*.public_ip, flatten([for node in module.talos_worker_group : node.private_ip])]) } data "talos_cluster_kubeconfig" "this" { diff --git a/examples/terraform/equinix-metal/.terraform.lock.hcl b/examples/terraform/equinix-metal/.terraform.lock.hcl index 08bc3f0..6705df9 100644 --- a/examples/terraform/equinix-metal/.terraform.lock.hcl +++ b/examples/terraform/equinix-metal/.terraform.lock.hcl @@ -2,47 +2,46 @@ # Manual edits may be lost in future updates. provider "registry.terraform.io/equinix/equinix" { - version = "1.11.1" - constraints = "1.11.1" + version = "1.33.0" + constraints = "1.33.0" hashes = [ - "h1:byMoA1Tdm4omgcvXCG7F4U3883yMppKFqUIWfRewchY=", - "h1:zY9lHFA+SPAZxeElvaNt0/2d/e6GaPVObnwseI8A/m0=", - "zh:0441965d03d1b378ab99205e55067cc5fc60b2a22886ee1ef62f910a988cd2d8", - "zh:1013a1276f95ee5deefed9ddea97d9018490843151af90558f0f4e656f9a037e", - "zh:182ebd08581581e572f680689b08bad7928bf183b7258ded5aab31e0b9dd0138", - "zh:58c0c4fe74581855e7240124a5c200d09f2b2834f0640b2a61e6b8c1fd0e778d", - "zh:5c8ed70611d980dd34aebcf8f6faecc028535df6e2c6ec2ec40fd918623da7b7", - "zh:5d388a2bc4acb25c2e7728c94cc18b0af1e367a716b296e24d58a361d31e6363", - "zh:61fe36fc2ba1e78f96bfc09c401d264d96dc6d09df9d58f83120630ee1941de5", - "zh:6d0f4705c6ab48e0e983688b9dc171ef9e1e2b9706927701a53a234519f25b36", - "zh:70fbfd6e59f644c2d5467085c7ab073a6b6313d95fd90a626e34c126a3078a7c", - "zh:823df43ac4e4d38e5b6b4310f3c888b7ffe0f6cd234897a0c76edebef4842f42", - "zh:8824ba6ac9689bfd570566796843407df3aa995b18cf4986db9d541701500209", - "zh:a5dede4d4c4dae6574e0efaf1f91d310cca8382002b95bf690b4cb336ec26876", - "zh:ed8bfd649f636e2fa91fc962c1da1d6a3fc2e5769222664f8a7b382c3dbf85fe", - "zh:f54cecbdec8e82e71be3561cf5c68351dbbe2f290826068fa19b5a30735a444a", + "h1:Cp4jL4QO6tDJr0MWRXnxZ/2xoWukxX1VxQ35BEeAvgM=", + "zh:0ee336623b14cf035ec86f6b14885af39e66c28fe78e4043fbebd2218c5a8f10", + "zh:1638a63b9654ad2741827e0594a329aa01262a4f837ab4debdd5c960645ce967", + "zh:1766e6962eac6c358b2220689f93ddf1a2636cb62f925688f9219fca54d90a03", + "zh:30052a958f9f8ae4fcf24fdef2abf1dd16f306c04eadba90943208bdd6e2193e", + "zh:34002b6a54ba942959ebdd32bb24487b22231ea200cd80700bc48f78a3de0165", + "zh:556737ef80e7c7ec4d02874278675555b487cf1945605207c866ae76ab4b19e7", + "zh:5ada9cbb554c7fc37857248a59d2d2f2272aaab9f6359a8f41307f728314abfb", + "zh:623cf490304571157fe23767ae94416617d604935595eaae02b5a32c56d88a1d", + "zh:8eb72c61b1d23c218405a33d82b40712c6dbd82ea8851eea8225ec2cd7126362", + "zh:9853a78d696ee3937e2028603380ce2ff37812742813db1338455b3065d96a67", + "zh:a2762f90f680e84ab8bd8c5c4a494f48142fb31d652b177762dac32627280659", + "zh:a32ebed9e4b4d54225e4fd7aa0097dd287f0ce93363bb0cadd14d7d85d110b3a", + "zh:beb21c3596090093b60306fa53a9e6d7103da7a560c5b8e2e19ab04a4b8a0dad", + "zh:d3f9c303afbb14b43bb70ab736cb85a79e0ee98a360fa4ecd76e7dd11bad8ab6", ] } provider "registry.terraform.io/siderolabs/talos" { - version = "0.3.2" - constraints = "0.3.2" + version = "0.4.0" + constraints = "0.4.0" hashes = [ - "h1:2jFWaSAqDJZAwltT/dIz6/Da8qLbuK5Q649a0BsWsLk=", + "h1:gZizwbmLby0q/j4SH/e7FWbPocS05Kv+GsXrqKpW8o0=", "zh:0fa82a384b25a58b65523e0ea4768fa1212b1f5cfc0c9379d31162454fedcc9d", - "zh:12e9539ca442f1f487b2ec8f497c417b46dd1a1c56fe5c49dba309c5c2bc8c4d", - "zh:1a7f6f4171df7a1aca2655468921a2edfac6d0191135da17d49d159c56b85a38", - "zh:286d2215f916a06861cd293258d2b4e54e651c5bc0ea3ba0f7059c8d1eb6b6b0", - "zh:3e5a1273a53afa8b97e9249d7999c76f68209e2e219e2971e0ddd03c54f6ca6e", - "zh:811ec2121ed7a978323fff1b2d9159f088b76381abc49994b04aede4fdcd659c", - "zh:8fb91f044ce687edf777377642d34899a3a70de6d628e8a54e14781764b4cfd4", - "zh:93a5fbaee0300577d78fe288721e71125e0b58425f3f75b7b1de8459431e0a55", - "zh:95cb837443bea3d096f6d6b095b5f111862765ddda88fe92da06dfc666674039", - "zh:b90a40329dbd41e9100534c4718f0e2a3b5e83bf457eba172e7e51bea4555eee", - "zh:d19f17719e3e7569ef7da8593864727c7bdab824de3baee07b9a9ff0b02235be", - "zh:d25ec24d53a0de0afec2ed4caef8c50d1a236ee75ced0050283d4fcf9d5dd9ac", - "zh:d6300b786b7951dbe129b063f4355ed66925ec764378a7188fb9d1ec35d4bfc7", - "zh:e061109513ae289b7eb378c161b0e503bde216cd442a0f6d7216fdc8a886b38a", - "zh:e759c4d12bd4e742c3623d27b503d1bf69727fc279d68f6f44922d85c8bdd8c5", + "zh:1bf1fc97799acd3e4e928d046219273380f9986958efd797debd9f0f7656bed8", + "zh:1c2246f69fee54420100a74ecb03a1c32ab1a00c6cc2b44329cd838b547502da", + "zh:24687dda8bea73ad9dbd50f20b418f5c6c452133855eebb8255db62ddea2c464", + "zh:29c41e0ee1b59186d3484d2c52feff88e9df4d03b331eb78d76f28e2a83a1435", + "zh:306ef50dbfca9f9bd5260ca92737d26d48a77df9157f9b1d7272170cd48324e7", + "zh:3e95b418406cd4a8f7a2ebf95e54c54167cd206a2b2011697309fe9613348f19", + "zh:472387b831a4e7e93f4bc48282895db556c0d7fe3176f4531387c9c293e63c3d", + "zh:49130ce1b66149f895d6f283c8b3005d931a35f7d742a6391830836a5a622b7b", + "zh:4afbcbc58c62661444bdff8cd17cae1028be2328a645e9c686d6b355e38605af", + "zh:56cd09f6ef968b1af827a889b44ddf60f3b3a92b774ed95ecd076db21bcebc8c", + "zh:921a9b381f1ffd12528d1d928cb020138380dcc312d6d7892cc9dd3b484d76eb", + "zh:9e2207847f868b0a3661ed05d8b7baa5d8bd6e2eba797fae8e358afc29f92653", + "zh:db714e4b4f9c551392359172a2bb9cabbb5322b94043e14286a86fb61ebebd28", + "zh:ffdfd4fdf7d18bbd75b4a7d426b17216539479f0a24be4c35dd33f9843f2096d", ] } diff --git a/examples/terraform/equinix-metal/README.md b/examples/terraform/equinix-metal/README.md index 48ffe5a..40955d0 100644 --- a/examples/terraform/equinix-metal/README.md +++ b/examples/terraform/equinix-metal/README.md @@ -12,9 +12,14 @@ From this directory, issue `terraform init` to ensure the proper providers are p ## Usage +Refer to [Boot Assets](https://www.talos.dev/latest/talos-guides/install/boot-assets/) on how to use [Image Factory](https://www.talos.dev/latest/learn-more/image-factory/) to customize the below mentioned Terraform variables + +Change the version of `ipxe_script_url` to the version of Talos you want to use. +Change the `install_image` to the version of Talos you want to use. + To create a default cluster, this should be as simple as `terraform apply`. This will create a cluster called `talos-em` with 3 control plane nodes and a single worker in the Washington DC region. -It will also create an elastic IP that is used +It will also create an elastic IP that is used Each of these machines will their smallest offering, the `c3.small.x86`. If different specs or regions are required, override them through command line with the `-var` flag or by creating a varsfile and overriding with `-var-file`. Destroying the cluster should, again, be a simple `terraform destroy`. @@ -26,15 +31,15 @@ Getting the kubeconfig and talosconfig for this cluster can be done with `terraf | Name | Version | |------|---------| -| [equinix](#requirement\_equinix) | 1.11.1 | -| [talos](#requirement\_talos) | 0.3.2 | +| [equinix](#requirement\_equinix) | 1.33.0 | +| [talos](#requirement\_talos) | 0.4.0 | ## Providers | Name | Version | |------|---------| -| [equinix](#provider\_equinix) | 1.11.1 | -| [talos](#provider\_talos) | 0.3.2 | +| [equinix](#provider\_equinix) | 1.33.0 | +| [talos](#provider\_talos) | 0.4.0 | ## Modules @@ -44,29 +49,33 @@ No modules. | Name | Type | |------|------| -| [equinix_metal_device.talos_control_plane](https://registry.terraform.io/providers/equinix/equinix/1.11.1/docs/resources/metal_device) | resource | -| [equinix_metal_device.talos_worker](https://registry.terraform.io/providers/equinix/equinix/1.11.1/docs/resources/metal_device) | resource | -| [equinix_metal_reserved_ip_block.talos_control_plane_vip](https://registry.terraform.io/providers/equinix/equinix/1.11.1/docs/resources/metal_reserved_ip_block) | resource | -| [talos_machine_bootstrap.this](https://registry.terraform.io/providers/siderolabs/talos/0.3.2/docs/resources/machine_bootstrap) | resource | -| [talos_machine_configuration_apply.controlplane](https://registry.terraform.io/providers/siderolabs/talos/0.3.2/docs/resources/machine_configuration_apply) | resource | -| [talos_machine_configuration_apply.worker](https://registry.terraform.io/providers/siderolabs/talos/0.3.2/docs/resources/machine_configuration_apply) | resource | -| [talos_machine_secrets.this](https://registry.terraform.io/providers/siderolabs/talos/0.3.2/docs/resources/machine_secrets) | resource | -| [talos_client_configuration.this](https://registry.terraform.io/providers/siderolabs/talos/0.3.2/docs/data-sources/client_configuration) | data source | -| [talos_cluster_kubeconfig.this](https://registry.terraform.io/providers/siderolabs/talos/0.3.2/docs/data-sources/cluster_kubeconfig) | data source | -| [talos_machine_configuration.controlplane](https://registry.terraform.io/providers/siderolabs/talos/0.3.2/docs/data-sources/machine_configuration) | data source | -| [talos_machine_configuration.worker](https://registry.terraform.io/providers/siderolabs/talos/0.3.2/docs/data-sources/machine_configuration) | data source | +| [equinix_metal_device.talos_control_plane_nodes](https://registry.terraform.io/providers/equinix/equinix/1.33.0/docs/resources/metal_device) | resource | +| [equinix_metal_device.talos_worker_group](https://registry.terraform.io/providers/equinix/equinix/1.33.0/docs/resources/metal_device) | resource | +| [equinix_metal_reserved_ip_block.talos_control_plane_vip](https://registry.terraform.io/providers/equinix/equinix/1.33.0/docs/resources/metal_reserved_ip_block) | resource | +| [talos_machine_bootstrap.this](https://registry.terraform.io/providers/siderolabs/talos/0.4.0/docs/resources/machine_bootstrap) | resource | +| [talos_machine_configuration_apply.controlplane](https://registry.terraform.io/providers/siderolabs/talos/0.4.0/docs/resources/machine_configuration_apply) | resource | +| [talos_machine_configuration_apply.worker_group](https://registry.terraform.io/providers/siderolabs/talos/0.4.0/docs/resources/machine_configuration_apply) | resource | +| [talos_machine_secrets.this](https://registry.terraform.io/providers/siderolabs/talos/0.4.0/docs/resources/machine_secrets) | resource | +| [talos_client_configuration.this](https://registry.terraform.io/providers/siderolabs/talos/0.4.0/docs/data-sources/client_configuration) | data source | +| [talos_cluster_health.this](https://registry.terraform.io/providers/siderolabs/talos/0.4.0/docs/data-sources/cluster_health) | data source | +| [talos_cluster_kubeconfig.this](https://registry.terraform.io/providers/siderolabs/talos/0.4.0/docs/data-sources/cluster_kubeconfig) | data source | +| [talos_machine_configuration.controlplane](https://registry.terraform.io/providers/siderolabs/talos/0.4.0/docs/data-sources/machine_configuration) | data source | +| [talos_machine_configuration.worker_group](https://registry.terraform.io/providers/siderolabs/talos/0.4.0/docs/data-sources/machine_configuration) | data source | ## Inputs | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [cluster\_name](#input\_cluster\_name) | Name of cluster | `string` | `"talos-em"` | no | +| [config\_patch\_files](#input\_config\_patch\_files) | Path to talos config path files that applies to all nodes | `list(string)` | `[]` | no | +| [control\_plane](#input\_control\_plane) | Info for control plane that will be created |
object({
plan = optional(string, "c3.small.x86")
# Image Factory schematic ID with kernel args set to `talos.platform=equinixMetal console=ttyAMA0,115200`
ipxe_script_url = optional(string, "https://pxe.factory.talos.dev/pxe/1193f285087c2414e8cd1cb44ff4f3a9da2876eb4f21cfe24cff9437956fe7da/v1.7.0/metal-amd64")
install_image = optional(string, "ghcr.io/talos-systems/installer:v1.7.0")
num_instances = optional(number, 3)
config_patch_files = optional(list(string), [])
tags = optional(list(string), [])
})
| `{}` | no | | [em\_api\_token](#input\_em\_api\_token) | API token for Equinix Metal | `string` | n/a | yes | -| [em\_plan](#input\_em\_plan) | Equinix Metal server to use | `string` | `"c3.small.x86"` | no | | [em\_project\_id](#input\_em\_project\_id) | Equinix Metal project ID | `string` | n/a | yes | | [em\_region](#input\_em\_region) | Equinix Metal region to use | `string` | `"dc"` | no | -| [num\_control\_plane](#input\_num\_control\_plane) | Number of control plane nodes to create | `number` | `3` | no | -| [num\_workers](#input\_num\_workers) | Number of worker nodes to create | `number` | `1` | no | +| [extra\_tags](#input\_extra\_tags) | Extra tags to add to the cluster cloud resources | `list(string)` | `[]` | no | +| [kubernetes\_version](#input\_kubernetes\_version) | Kubernetes version to use for the cluster, if not set the k8s version shipped with the talos sdk version will be used | `string` | `null` | no | +| [talos\_version\_contract](#input\_talos\_version\_contract) | Talos API version to use for the cluster, if not set the the version shipped with the talos sdk version will be used | `string` | `null` | no | +| [worker\_groups](#input\_worker\_groups) | List of node worker node groups to create |
list(object({
name = string
plan = optional(string, "c3.small.x86")
# Image Factory schematic ID with kernel args set to `talos.platform=equinixMetal console=ttyAMA0,115200`
ipxe_script_url = optional(string, "https://pxe.factory.talos.dev/pxe/1193f285087c2414e8cd1cb44ff4f3a9da2876eb4f21cfe24cff9437956fe7da/v1.7.0/metal-amd64")
install_image = optional(string, "ghcr.io/talos-systems/installer:v1.7.0")
num_instances = optional(number, 1)
config_patch_files = optional(list(string), [])
tags = optional(list(string), [])
}))
|
[
{
"name": "default"
}
]
| no | ## Outputs @@ -74,4 +83,4 @@ No modules. |------|-------------| | [kubeconfig](#output\_kubeconfig) | n/a | | [talosconfig](#output\_talosconfig) | n/a | - \ No newline at end of file + diff --git a/examples/terraform/equinix-metal/equinix-arm64.yaml b/examples/terraform/equinix-metal/equinix-arm64.yaml new file mode 100644 index 0000000..0e570d9 --- /dev/null +++ b/examples/terraform/equinix-metal/equinix-arm64.yaml @@ -0,0 +1,3 @@ +machine: + install: + disk: /dev/nvme0n1 diff --git a/examples/terraform/equinix-metal/main.tf b/examples/terraform/equinix-metal/main.tf index dd5253a..015b318 100644 --- a/examples/terraform/equinix-metal/main.tf +++ b/examples/terraform/equinix-metal/main.tf @@ -1,5 +1,4 @@ # Create EM resources - resource "equinix_metal_reserved_ip_block" "talos_control_plane_vip" { project_id = var.em_project_id type = "public_ipv4" @@ -8,79 +7,139 @@ resource "equinix_metal_reserved_ip_block" "talos_control_plane_vip" { description = "${var.cluster_name} Control Plane VIP" } -resource "equinix_metal_device" "talos_control_plane" { +resource "equinix_metal_device" "talos_control_plane_nodes" { + count = var.control_plane.num_instances + project_id = var.em_project_id - plan = var.em_plan + plan = var.control_plane.plan metro = var.em_region - operating_system = "talos_v1" + tags = concat(var.extra_tags, var.control_plane.tags) + operating_system = "custom_ipxe" + ipxe_script_url = var.control_plane.ipxe_script_url billing_cycle = "hourly" hostname = "${var.cluster_name}-control-plane-${count.index}" - count = var.num_control_plane } -resource "equinix_metal_device" "talos_worker" { +resource "equinix_metal_device" "talos_worker_group" { + for_each = merge([ + for info in var.worker_groups : { + for index in range(0, info.num_instances) : "${info.name}.${index}" => info + } + ]...) + project_id = var.em_project_id - plan = var.em_plan + plan = each.value.plan metro = var.em_region - operating_system = "talos_v1" + tags = concat(var.extra_tags, each.value.tags) + operating_system = "custom_ipxe" + ipxe_script_url = each.value.ipxe_script_url billing_cycle = "hourly" - hostname = "${var.cluster_name}-worker-${count.index}" - count = var.num_workers + hostname = "${var.cluster_name}-worker-group-${each.value.name}-${trimprefix(each.key, "${each.value.name}.")}" } # Configure and bootstrap Talos resource "talos_machine_secrets" "this" {} -data "talos_client_configuration" "this" { - cluster_name = var.cluster_name - client_configuration = talos_machine_secrets.this.client_configuration - endpoints = equinix_metal_device.talos_control_plane[*].access_public_ipv4 +data "talos_machine_configuration" "controlplane" { + cluster_name = var.cluster_name + cluster_endpoint = "https://${equinix_metal_reserved_ip_block.talos_control_plane_vip.network}:6443" + machine_type = "controlplane" + machine_secrets = talos_machine_secrets.this.machine_secrets + talos_version = var.talos_version_contract + kubernetes_version = var.kubernetes_version + docs = false + examples = false + config_patches = concat( + [templatefile("${path.module}/templates/vip.yaml.tmpl", { + em_vip_ip = equinix_metal_reserved_ip_block.talos_control_plane_vip.network + em_api_token = var.em_api_token + })], + [templatefile("${path.module}/templates/installer.yaml.tmpl", { + install_image = var.control_plane.install_image + })], + [for path in var.control_plane.config_patch_files : file(path)] + ) } -data "talos_machine_configuration" "controlplane" { - cluster_name = var.cluster_name - cluster_endpoint = "https://${equinix_metal_reserved_ip_block.talos_control_plane_vip.network}:6443" - machine_type = "controlplane" - machine_secrets = talos_machine_secrets.this.machine_secrets +data "talos_machine_configuration" "worker_group" { + for_each = merge([for info in var.worker_groups : { "${info.name}" = info }]...) + + cluster_name = var.cluster_name + cluster_endpoint = "https://${equinix_metal_reserved_ip_block.talos_control_plane_vip.network}:6443" + machine_type = "worker" + machine_secrets = talos_machine_secrets.this.machine_secrets + talos_version = var.talos_version_contract + kubernetes_version = var.kubernetes_version + docs = false + examples = false + config_patches = concat( + [templatefile("${path.module}/templates/installer.yaml.tmpl", { + install_image = each.value.install_image + })], + [for path in each.value.config_patch_files : file(path)] + ) } resource "talos_machine_configuration_apply" "controlplane" { + count = var.control_plane.num_instances + client_configuration = talos_machine_secrets.this.client_configuration machine_configuration_input = data.talos_machine_configuration.controlplane.machine_configuration - count = length(equinix_metal_device.talos_control_plane) - node = equinix_metal_device.talos_control_plane[count.index].access_public_ipv4 - config_patches = [ - templatefile("${path.module}/templates/vip.yaml.tmpl", { - em_vip_ip = equinix_metal_reserved_ip_block.talos_control_plane_vip.network - em_api_token = var.em_api_token - }) - ] + endpoint = equinix_metal_device.talos_control_plane_nodes[count.index].access_public_ipv4 + node = equinix_metal_device.talos_control_plane_nodes[count.index].access_private_ipv4 } -data "talos_machine_configuration" "worker" { - cluster_name = var.cluster_name - cluster_endpoint = "https://${equinix_metal_reserved_ip_block.talos_control_plane_vip.network}:6443" - machine_type = "worker" - machine_secrets = talos_machine_secrets.this.machine_secrets -} +resource "talos_machine_configuration_apply" "worker_group" { + for_each = merge([ + for info in var.worker_groups : { + for index in range(0, info.num_instances) : + "${info.name}.${index}" => { + name = info.name, + public_ip = equinix_metal_device.talos_worker_group["${info.name}.${index}"].access_public_ipv4, + private_ip = equinix_metal_device.talos_worker_group["${info.name}.${index}"].access_private_ipv4 + } + } + ]...) -resource "talos_machine_configuration_apply" "worker" { client_configuration = talos_machine_secrets.this.client_configuration - machine_configuration_input = data.talos_machine_configuration.controlplane.machine_configuration - count = length(equinix_metal_device.talos_worker) - node = equinix_metal_device.talos_worker[count.index].access_public_ipv4 + machine_configuration_input = data.talos_machine_configuration.worker_group[each.value.name].machine_configuration + endpoint = each.value.public_ip + node = each.value.private_ip } resource "talos_machine_bootstrap" "this" { depends_on = [talos_machine_configuration_apply.controlplane] client_configuration = talos_machine_secrets.this.client_configuration - node = equinix_metal_device.talos_control_plane[0].access_public_ipv4 + endpoint = equinix_metal_device.talos_control_plane_nodes[0].access_public_ipv4 + node = equinix_metal_device.talos_control_plane_nodes[0].access_public_ipv4 +} + +data "talos_client_configuration" "this" { + cluster_name = var.cluster_name + client_configuration = talos_machine_secrets.this.client_configuration + endpoints = equinix_metal_device.talos_control_plane_nodes.*.access_public_ipv4 + nodes = flatten([equinix_metal_device.talos_control_plane_nodes.*.access_public_ipv4, flatten([for node in equinix_metal_device.talos_worker_group : node.access_public_ipv4])]) } data "talos_cluster_kubeconfig" "this" { + depends_on = [talos_machine_bootstrap.this] + + client_configuration = talos_machine_secrets.this.client_configuration + endpoint = equinix_metal_device.talos_control_plane_nodes.0.access_public_ipv4 + node = equinix_metal_device.talos_control_plane_nodes.0.access_public_ipv4 +} + +data "talos_cluster_health" "this" { + depends_on = [ + talos_machine_configuration_apply.controlplane, + talos_machine_configuration_apply.worker_group, + data.talos_cluster_kubeconfig.this + ] + client_configuration = talos_machine_secrets.this.client_configuration - node = equinix_metal_device.talos_control_plane[0].access_public_ipv4 - wait = true + endpoints = equinix_metal_device.talos_control_plane_nodes.*.access_public_ipv4 + control_plane_nodes = equinix_metal_device.talos_control_plane_nodes.*.access_private_ipv4 + worker_nodes = [for node in equinix_metal_device.talos_worker_group : node.access_private_ipv4] } diff --git a/examples/terraform/equinix-metal/templates/installer.yaml.tmpl b/examples/terraform/equinix-metal/templates/installer.yaml.tmpl new file mode 100644 index 0000000..0fb506a --- /dev/null +++ b/examples/terraform/equinix-metal/templates/installer.yaml.tmpl @@ -0,0 +1,3 @@ +machine: + install: + image: ${install_image} diff --git a/examples/terraform/equinix-metal/variables.tf b/examples/terraform/equinix-metal/variables.tf index 120a8ef..87377ef 100644 --- a/examples/terraform/equinix-metal/variables.tf +++ b/examples/terraform/equinix-metal/variables.tf @@ -10,16 +10,61 @@ variable "cluster_name" { default = "talos-em" } -variable "num_control_plane" { - description = "Number of control plane nodes to create" - type = number - default = 3 +variable "talos_version_contract" { + description = "Talos API version to use for the cluster, if not set the the version shipped with the talos sdk version will be used" + type = string + default = null +} + +variable "kubernetes_version" { + description = "Kubernetes version to use for the cluster, if not set the k8s version shipped with the talos sdk version will be used" + type = string + default = null } -variable "num_workers" { - description = "Number of worker nodes to create" - type = number - default = 1 +variable "control_plane" { + description = "Info for control plane that will be created" + type = object({ + plan = optional(string, "c3.small.x86") + # Image Factory schematic ID with kernel args set to `talos.platform=equinixMetal console=ttyAMA0,115200` + ipxe_script_url = optional(string, "https://pxe.factory.talos.dev/pxe/1193f285087c2414e8cd1cb44ff4f3a9da2876eb4f21cfe24cff9437956fe7da/v1.7.0/metal-amd64") + install_image = optional(string, "ghcr.io/talos-systems/installer:v1.7.0") + num_instances = optional(number, 3) + config_patch_files = optional(list(string), []) + tags = optional(list(string), []) + }) + + default = {} +} + +variable "worker_groups" { + description = "List of node worker node groups to create" + type = list(object({ + name = string + plan = optional(string, "c3.small.x86") + # Image Factory schematic ID with kernel args set to `talos.platform=equinixMetal console=ttyAMA0,115200` + ipxe_script_url = optional(string, "https://pxe.factory.talos.dev/pxe/1193f285087c2414e8cd1cb44ff4f3a9da2876eb4f21cfe24cff9437956fe7da/v1.7.0/metal-amd64") + install_image = optional(string, "ghcr.io/talos-systems/installer:v1.7.0") + num_instances = optional(number, 1) + config_patch_files = optional(list(string), []) + tags = optional(list(string), []) + })) + + default = [{ + name = "default" + }] +} + +variable "extra_tags" { + description = "Extra tags to add to the cluster cloud resources" + type = list(string) + default = [] +} + +variable "config_patch_files" { + description = "Path to talos config path files that applies to all nodes" + type = list(string) + default = [] } variable "em_region" { @@ -28,12 +73,6 @@ variable "em_region" { default = "dc" } -variable "em_plan" { - description = "Equinix Metal server to use" - type = string - default = "c3.small.x86" -} - variable "em_project_id" { description = "Equinix Metal project ID" type = string diff --git a/examples/terraform/equinix-metal/versions.tf b/examples/terraform/equinix-metal/versions.tf index cc23e58..21a33e3 100644 --- a/examples/terraform/equinix-metal/versions.tf +++ b/examples/terraform/equinix-metal/versions.tf @@ -4,11 +4,11 @@ terraform { required_providers { equinix = { source = "equinix/equinix" - version = "1.11.1" + version = "1.33.0" } talos = { source = "siderolabs/talos" - version = "0.3.2" + version = "0.4.0" } } }