Skip to content

Commit

Permalink
chore: modularize equinix code for e2e
Browse files Browse the repository at this point in the history
make the equinix code similar to AWS and Azure so that we can use it for
e2e tests.

Signed-off-by: Noel Georgi <[email protected]>
  • Loading branch information
frezbo committed Apr 2, 2024
1 parent 814de94 commit c2a0436
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 113 deletions.
9 changes: 7 additions & 2 deletions .drone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/terraform/aws/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
69 changes: 34 additions & 35 deletions examples/terraform/equinix-metal/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 29 additions & 20 deletions examples/terraform/equinix-metal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -26,15 +31,15 @@ Getting the kubeconfig and talosconfig for this cluster can be done with `terraf

| Name | Version |
|------|---------|
| <a name="requirement_equinix"></a> [equinix](#requirement\_equinix) | 1.11.1 |
| <a name="requirement_talos"></a> [talos](#requirement\_talos) | 0.3.2 |
| <a name="requirement_equinix"></a> [equinix](#requirement\_equinix) | 1.33.0 |
| <a name="requirement_talos"></a> [talos](#requirement\_talos) | 0.4.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_equinix"></a> [equinix](#provider\_equinix) | 1.11.1 |
| <a name="provider_talos"></a> [talos](#provider\_talos) | 0.3.2 |
| <a name="provider_equinix"></a> [equinix](#provider\_equinix) | 1.33.0 |
| <a name="provider_talos"></a> [talos](#provider\_talos) | 0.4.0 |

## Modules

Expand All @@ -44,34 +49,38 @@ 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 |
|------|-------------|------|---------|:--------:|
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Name of cluster | `string` | `"talos-em"` | no |
| <a name="input_config_patch_files"></a> [config\_patch\_files](#input\_config\_patch\_files) | Path to talos config path files that applies to all nodes | `list(string)` | `[]` | no |
| <a name="input_control_plane"></a> [control\_plane](#input\_control\_plane) | Info for control plane that will be created | <pre>object({<br> plan = optional(string, "c3.small.x86")<br> # Image Factory schematic ID with kernel args set to `talos.platform=equinixMetal console=ttyAMA0,115200`<br> ipxe_script_url = optional(string, "https://pxe.factory.talos.dev/pxe/1193f285087c2414e8cd1cb44ff4f3a9da2876eb4f21cfe24cff9437956fe7da/v1.7.0/metal-amd64")<br> install_image = optional(string, "ghcr.io/talos-systems/installer:v1.7.0")<br> num_instances = optional(number, 3)<br> config_patch_files = optional(list(string), [])<br> tags = optional(list(string), [])<br> })</pre> | `{}` | no |
| <a name="input_em_api_token"></a> [em\_api\_token](#input\_em\_api\_token) | API token for Equinix Metal | `string` | n/a | yes |
| <a name="input_em_plan"></a> [em\_plan](#input\_em\_plan) | Equinix Metal server to use | `string` | `"c3.small.x86"` | no |
| <a name="input_em_project_id"></a> [em\_project\_id](#input\_em\_project\_id) | Equinix Metal project ID | `string` | n/a | yes |
| <a name="input_em_region"></a> [em\_region](#input\_em\_region) | Equinix Metal region to use | `string` | `"dc"` | no |
| <a name="input_num_control_plane"></a> [num\_control\_plane](#input\_num\_control\_plane) | Number of control plane nodes to create | `number` | `3` | no |
| <a name="input_num_workers"></a> [num\_workers](#input\_num\_workers) | Number of worker nodes to create | `number` | `1` | no |
| <a name="input_extra_tags"></a> [extra\_tags](#input\_extra\_tags) | Extra tags to add to the cluster cloud resources | `list(string)` | `[]` | no |
| <a name="input_kubernetes_version"></a> [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 |
| <a name="input_talos_version_contract"></a> [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 |
| <a name="input_worker_groups"></a> [worker\_groups](#input\_worker\_groups) | List of node worker node groups to create | <pre>list(object({<br> name = string<br> plan = optional(string, "c3.small.x86")<br> # Image Factory schematic ID with kernel args set to `talos.platform=equinixMetal console=ttyAMA0,115200`<br> ipxe_script_url = optional(string, "https://pxe.factory.talos.dev/pxe/1193f285087c2414e8cd1cb44ff4f3a9da2876eb4f21cfe24cff9437956fe7da/v1.7.0/metal-amd64")<br> install_image = optional(string, "ghcr.io/talos-systems/installer:v1.7.0")<br> num_instances = optional(number, 1)<br> config_patch_files = optional(list(string), [])<br> tags = optional(list(string), [])<br> }))</pre> | <pre>[<br> {<br> "name": "default"<br> }<br>]</pre> | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_kubeconfig"></a> [kubeconfig](#output\_kubeconfig) | n/a |
| <a name="output_talosconfig"></a> [talosconfig](#output\_talosconfig) | n/a |
<!-- END_TF_DOCS -->
<!-- END_TF_DOCS -->
3 changes: 3 additions & 0 deletions examples/terraform/equinix-metal/equinix-arm64.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
machine:
install:
disk: /dev/nvme0n1
Loading

0 comments on commit c2a0436

Please sign in to comment.