diff --git a/.gitignore b/.gitignore index 7f75251..432bd68 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ Session.vim *.tfstate *.tfstate.* +.terraform.lock.hcl + # Crash log files crash.log @@ -42,12 +44,6 @@ override.tf.json *_override.tf *_override.tf.json -# Include override files you do wish to add to version control using negated pattern -# -# !example_override.tf -!.terraform.lock.hcl -**/*/.terraform.lock.hcl - # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan # example: *tfplan* **/terraform.tfvars diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl deleted file mode 100644 index 14a465f..0000000 --- a/.terraform.lock.hcl +++ /dev/null @@ -1,103 +0,0 @@ -# This file is maintained automatically by "terraform init". -# Manual edits may be lost in future updates. - -provider "registry.terraform.io/equinix/equinix" { - version = "1.14.1" - constraints = ">= 1.10.0" - hashes = [ - "h1:leVuWUGydv+Nbs7Mmjm4iOF/mu+GWploPZW9dg7r3IY=", - "zh:1b478c206ae88a3bfd4ab376ce19e5c577b8f3389005cc159bb041b6dc9e00b1", - "zh:24b793281076cd57ac42665d919406ba4077768db01b0f1f1e7daff814159a49", - "zh:35d2902215d27592ff6cbbe478910aa40474ee0f0875a42ea06a11b32cae4ff7", - "zh:3ca24f4c577042ef4232105eb92b18fd83e59e1a99955507526a7a96edcd83de", - "zh:4f0ef4b10eca14fc091be18547d125fdf687b290ec3925bfcb3006033a6d8155", - "zh:50fe98f600a1cb15fb1b7153a5f70a2432e2920b9d99498a327db7c81fdbaaec", - "zh:8a1619f0fb5aa0eebec1133a2e7795da503425252300ffd286587a91f1316bd5", - "zh:8baf418e8acb130e32ab0402bcc2545fd1d0ac8ad3d6d337f51acb70eb99719d", - "zh:9062cdbbd2bedf1ad1ace95eca13f962d6dd8deb6db2e25e153027098e1aa985", - "zh:bc9160faff9ddb9e532e6ae7c79f8e66163ba19eadc34b0975a0c7b0084db02b", - "zh:bf67edb2daae4fe6728e4f879aecd9b4130beb82c0ad79e4cd2b159b48c93c02", - "zh:c125746c76a8580a403c56b69d702d0831523cfea3b7a3889ffc48835b7403ce", - "zh:c6fe46df23138c80d70cec18a791f02ccdf5c6c0b77a3f85964c0ddd33ad0025", - "zh:dd50a69bb647668a5255db0d01e655dc708b1e3a0ea780db2efb2418a6599ccd", - ] -} - -provider "registry.terraform.io/hashicorp/local" { - version = "2.4.0" - constraints = "2.4.0" - hashes = [ - "h1:ZUEYUmm2t4vxwzxy1BvN1wL6SDWrDxfH7pxtzX8c6d0=", - "zh:53604cd29cb92538668fe09565c739358dc53ca56f9f11312b9d7de81e48fab9", - "zh:66a46e9c508716a1c98efbf793092f03d50049fa4a83cd6b2251e9a06aca2acf", - "zh:70a6f6a852dd83768d0778ce9817d81d4b3f073fab8fa570bff92dcb0824f732", - "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", - "zh:82a803f2f484c8b766e2e9c32343e9c89b91997b9f8d2697f9f3837f62926b35", - "zh:9708a4e40d6cc4b8afd1352e5186e6e1502f6ae599867c120967aebe9d90ed04", - "zh:973f65ce0d67c585f4ec250c1e634c9b22d9c4288b484ee2a871d7fa1e317406", - "zh:c8fa0f98f9316e4cfef082aa9b785ba16e36ff754d6aba8b456dab9500e671c6", - "zh:cfa5342a5f5188b20db246c73ac823918c189468e1382cb3c48a9c0c08fc5bf7", - "zh:e0e2b477c7e899c63b06b38cd8684a893d834d6d0b5e9b033cedc06dd7ffe9e2", - "zh:f62d7d05ea1ee566f732505200ab38d94315a4add27947a60afa29860822d3fc", - "zh:fa7ce69dde358e172bd719014ad637634bbdabc49363104f4fca759b4b73f2ce", - ] -} - -provider "registry.terraform.io/hashicorp/null" { - version = "3.2.1" - hashes = [ - "h1:ydA0/SNRVB1o95btfshvYsmxA+jZFRZcvKzZSB+4S1M=", - "zh:58ed64389620cc7b82f01332e27723856422820cfd302e304b5f6c3436fb9840", - "zh:62a5cc82c3b2ddef7ef3a6f2fedb7b9b3deff4ab7b414938b08e51d6e8be87cb", - "zh:63cff4de03af983175a7e37e52d4bd89d990be256b16b5c7f919aff5ad485aa5", - "zh:74cb22c6700e48486b7cabefa10b33b801dfcab56f1a6ac9b6624531f3d36ea3", - "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", - "zh:79e553aff77f1cfa9012a2218b8238dd672ea5e1b2924775ac9ac24d2a75c238", - "zh:a1e06ddda0b5ac48f7e7c7d59e1ab5a4073bbcf876c73c0299e4610ed53859dc", - "zh:c37a97090f1a82222925d45d84483b2aa702ef7ab66532af6cbcfb567818b970", - "zh:e4453fbebf90c53ca3323a92e7ca0f9961427d2f0ce0d2b65523cc04d5d999c2", - "zh:e80a746921946d8b6761e77305b752ad188da60688cfd2059322875d363be5f5", - "zh:fbdb892d9822ed0e4cb60f2fedbdbb556e4da0d88d3b942ae963ed6ff091e48f", - "zh:fca01a623d90d0cad0843102f9b8b9fe0d3ff8244593bd817f126582b52dd694", - ] -} - -provider "registry.terraform.io/hashicorp/random" { - version = "3.4.3" - constraints = "3.4.3" - hashes = [ - "h1:saZR+mhthL0OZl4SyHXZraxyaBNVMxiZzks78nWcZ2o=", - "zh:41c53ba47085d8261590990f8633c8906696fa0a3c4b384ff6a7ecbf84339752", - "zh:59d98081c4475f2ad77d881c4412c5129c56214892f490adf11c7e7a5a47de9b", - "zh:686ad1ee40b812b9e016317e7f34c0d63ef837e084dea4a1f578f64a6314ad53", - "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", - "zh:84103eae7251384c0d995f5a257c72b0096605048f757b749b7b62107a5dccb3", - "zh:8ee974b110adb78c7cd18aae82b2729e5124d8f115d484215fd5199451053de5", - "zh:9dd4561e3c847e45de603f17fa0c01ae14cae8c4b7b4e6423c9ef3904b308dda", - "zh:bb07bb3c2c0296beba0beec629ebc6474c70732387477a65966483b5efabdbc6", - "zh:e891339e96c9e5a888727b45b2e1bb3fcbdfe0fd7c5b4396e4695459b38c8cb1", - "zh:ea4739860c24dfeaac6c100b2a2e357106a89d18751f7693f3c31ecf6a996f8d", - "zh:f0c76ac303fd0ab59146c39bc121c5d7d86f878e9a69294e29444d4c653786f8", - "zh:f143a9a5af42b38fed328a161279906759ff39ac428ebcfe55606e05e1518b93", - ] -} - -provider "registry.terraform.io/hashicorp/tls" { - version = "4.0.4" - constraints = "4.0.4" - hashes = [ - "h1:GZcFizg5ZT2VrpwvxGBHQ/hO9r6g0vYdQqx3bFD3anY=", - "zh:23671ed83e1fcf79745534841e10291bbf34046b27d6e68a5d0aab77206f4a55", - "zh:45292421211ffd9e8e3eb3655677700e3c5047f71d8f7650d2ce30242335f848", - "zh:59fedb519f4433c0fdb1d58b27c210b27415fddd0cd73c5312530b4309c088be", - "zh:5a8eec2409a9ff7cd0758a9d818c74bcba92a240e6c5e54b99df68fff312bbd5", - "zh:5e6a4b39f3171f53292ab88058a59e64825f2b842760a4869e64dc1dc093d1fe", - "zh:810547d0bf9311d21c81cc306126d3547e7bd3f194fc295836acf164b9f8424e", - "zh:824a5f3617624243bed0259d7dd37d76017097dc3193dac669be342b90b2ab48", - "zh:9361ccc7048be5dcbc2fafe2d8216939765b3160bd52734f7a9fd917a39ecbd8", - "zh:aa02ea625aaf672e649296bce7580f62d724268189fe9ad7c1b36bb0fa12fa60", - "zh:c71b4cd40d6ec7815dfeefd57d88bc592c0c42f5e5858dcc88245d371b4b8b1e", - "zh:dabcd52f36b43d250a3d71ad7abfa07b5622c69068d989e60b79b2bb4f220316", - "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", - ] -} diff --git a/README.md b/README.md index bea5f3d..9641bc9 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ This project may be deployed into new project(s) or existing project(s). Check o | Name | Description | |------|---------| +| [k3s-setup](./examples/k3s-setup/) | Deploys a SUSE K3s cluster into existing projects | +| [k3s-setup-new](./examples/k3s-setup-new/) | Deploys a SUSE K3s cluster into new projects provisioned for each user described in users.csv | | [eksa-setup](./examples/eksa-setup/) | Deploys a AWS EKS-A cluster into existing projects | | [eksa-setup-new](./examples/eksa-setup-new/) | Deploys a AWS EKS-A cluster into new projects provisioned for each user described in users.csv | | [metal-setup](./examples/metal-setup/) | Deploys a cluster or bare nodes into existing projects | @@ -52,6 +54,7 @@ No providers. | Name | Source | Version | |------|--------|---------| | [deploy\_eksa](#module\_deploy\_eksa) | ./modules/eksa | n/a | +| [deploy\_k3s](#module\_deploy\_k3s) | ./modules/k3s | n/a | | [deploy\_metal](#module\_deploy\_metal) | ./modules/metal | n/a | | [project\_setup](#module\_project\_setup) | ./modules/invite-from-csv | n/a | @@ -63,14 +66,17 @@ No resources. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| [metal\_auth\_token](#input\_metal\_auth\_token) | Equinix Metal user api token. | `string` | n/a | yes | -| [metal\_organization\_id](#input\_metal\_organization\_id) | Equinix Metal organization id | `string` | n/a | yes | | [eksa\_config](#input\_eksa\_config) | Module configuration for EKSA module |
object({
cluster_name = string
cp_device_count = number
worker_device_count = number
})
|
{
"cluster_name": "equinix-labs-cluster",
"cp_device_count": 3,
"worker_device_count": 3
}
| no | | [enable\_eksa](#input\_enable\_eksa) | Enable EKSA module | `bool` | `false` | no | +| [enable\_k3s](#input\_enable\_k3s) | Enable K3s module | `bool` | `false` | no | | [enable\_metal](#input\_enable\_metal) | Enable Metal module | `bool` | `false` | no | | [enable\_workshop\_setup](#input\_enable\_workshop\_setup) | Enable Workshop Setup module | `bool` | `false` | no | +| [global\_ip](#input\_global\_ip) | Enables a global anycast IPv4 that will be shared for all clusters in all metros | `bool` | `false` | no | +| [k3s\_config](#input\_k3s\_config) | Module configuration for K3s module |
list(object({
name = string
metro = string
plan_control_plane = string
plan_node = string
node_count = number
k3s_ha = bool
os = string
control_plane_hostnames = string
node_hostnames = string
custom_k3s_token = string
ip_pool_count = number
k3s_version = string
metallb_version = string
}))
|
[
{
"control_plane_hostnames": "k3s-cp",
"custom_k3s_token": "",
"ip_pool_count": 1,
"k3s_ha": true,
"k3s_version": "",
"metallb_version": "",
"metro": "SV",
"name": "k3s-cluster",
"node_count": 3,
"node_hostnames": "k3s-node",
"os": "debian_11",
"plan_control_plane": "c3.small.x86",
"plan_node": "c3.small.x86"
}
]
| no | +| [metal\_auth\_token](#input\_metal\_auth\_token) | Equinix Metal user api token. | `string` | n/a | yes | | [metal\_config](#input\_metal\_config) | Configuration for Metal module |
object({
device_count = number
os = string
billing_cycle = string
cluster_name = string
device_type = string
})
|
{
"billing_cycle": "hourly",
"cluster_name": "metal-cluster",
"device_count": 3,
"device_type": "m3.small.x86",
"os": "ubuntu_20_04"
}
| no | | [metal\_metro](#input\_metal\_metro) | Equinix Metal metro | `string` | `"sv"` | no | +| [metal\_organization\_id](#input\_metal\_organization\_id) | Equinix Metal organization id | `string` | n/a | yes | | [metal\_project\_id](#input\_metal\_project\_id) | Project ID | `string` | `""` | no | | [metal\_tags](#input\_metal\_tags) | String list of common tags for Equinix resources | `list(string)` |
[
"terraform",
"equinix-labs"
]
| no | @@ -79,6 +85,7 @@ No resources. | Name | Description | |------|-------------| | [deploy\_eksa\_outputs](#output\_deploy\_eksa\_outputs) | Outputs of the Deploy EKSA module | +| [deploy\_k3s\_outputs](#output\_deploy\_k3s\_outputs) | Outputs of the Deploy K3s module | | [deploy\_metal\_outputs](#output\_deploy\_metal\_outputs) | Outputs of the Deploy Metal module | | [project\_setup\_outputs](#output\_project\_setup\_outputs) | Outputs of the Project Setup module | diff --git a/examples/eksa-setup-new/outputs.tf b/examples/eksa-setup-new/outputs.tf index 3017949..cd8cd83 100644 --- a/examples/eksa-setup-new/outputs.tf +++ b/examples/eksa-setup-new/outputs.tf @@ -5,7 +5,7 @@ output "workshop_setup_outputs" { value = { for k, v in module.workshop_setup.project_setup_outputs : k => v } } -# Module Deploy Metal Outputs +# Module Deploy EKSA Outputs output "deploy_eksa_outputs" { description = "Outputs of the Deploy EKSA module" diff --git a/examples/eksa-setup/outputs.tf b/examples/eksa-setup/outputs.tf index 67a88d3..3d215a8 100644 --- a/examples/eksa-setup/outputs.tf +++ b/examples/eksa-setup/outputs.tf @@ -1,4 +1,4 @@ -# Module Deploy Metal Outputs +# Module Deploy EKSA Outputs output "deploy_eksa_outputs" { description = "Outputs of the Deploy EKSA module" diff --git a/examples/k3s-setup-new/README.md b/examples/k3s-setup-new/README.md new file mode 100644 index 0000000..faf8b62 --- /dev/null +++ b/examples/k3s-setup-new/README.md @@ -0,0 +1,45 @@ +# Terraform Equinix Labs K3s Setup Example + +This is an example of how to utilize the root module to deploy the [invite-from-csv](https://github.com/equinix-labs/terraform-equinix-labs/tree/main/modules/invite-from-csv) module and the [k3s](https://github.com/equinix-labs/terraform-equinix-metal-k3s) module. In this example, each user identified in the `users.csv` file (see users.csv.example) will have a project provisioned and an invitation sent by email to join that project. Kubernetes will then be provisioned into each user's project with the configurations set within the [variables.tf](./variables.tf) file. + + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 1.3 | +| [equinix](#requirement\_equinix) | >= 1.10.0 | + +## Providers + +No providers. + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| [deploy\_k3s](#module\_deploy\_k3s) | ../../ | n/a | +| [workshop\_setup](#module\_workshop\_setup) | ../../ | n/a | + +## Resources + +No resources. + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [enable\_k3s](#input\_enable\_k3s) | Enable K3s module | `bool` | `true` | no | +| [enable\_workshop\_setup](#input\_enable\_workshop\_setup) | Enable Workshop Setup module | `bool` | `true` | no | +| [global\_ip](#input\_global\_ip) | Enables a global anycast IPv4 that will be shared for all clusters in all metros | `string` | `false` | no | +| [k3s\_config](#input\_k3s\_config) | Module configuration for K3s module |
list(object({
name = string
metro = string
plan_control_plane = string
plan_node = string
node_count = number
k3s_ha = bool
os = string
control_plane_hostnames = string
node_hostnames = string
custom_k3s_token = string
ip_pool_count = number
k3s_version = string
metallb_version = string
}))
|
[
{
"control_plane_hostnames": "k3s-cp",
"custom_k3s_token": "",
"ip_pool_count": 1,
"k3s_ha": false,
"k3s_version": "v1.4.stable.1",
"metallb_version": "",
"metro": "SV",
"name": "k3s-cluster",
"node_count": 3,
"node_hostnames": "k3s-node",
"os": "debian_11",
"plan_control_plane": "c3.small.x86",
"plan_node": "c3.small.x86"
}
]
| no | +| [metal\_auth\_token](#input\_metal\_auth\_token) | Equinix Metal user api token. | `string` | n/a | yes | +| [metal\_organization\_id](#input\_metal\_organization\_id) | Equinix Metal organization id | `string` | n/a | yes | + +## Outputs + +| Name | Description | +|------|-------------| +| [deploy\_k3s\_outputs](#output\_deploy\_k3s\_outputs) | Outputs of the Deploy K3s module | +| [workshop\_setup\_outputs](#output\_workshop\_setup\_outputs) | Outputs of the Workshop Setup module | + diff --git a/examples/k3s-setup-new/main.tf b/examples/k3s-setup-new/main.tf new file mode 100644 index 0000000..5730f7e --- /dev/null +++ b/examples/k3s-setup-new/main.tf @@ -0,0 +1,36 @@ +# Setup provider block +terraform { + required_version = ">= 1.3" + + required_providers { + equinix = { + source = "equinix/equinix" + version = ">= 1.10.0" + } + } +} + +# Setup metal auth token for provider +provider "equinix" { + auth_token = var.metal_auth_token +} + +# Setup the workshop +module "workshop_setup" { + enable_workshop_setup = var.enable_workshop_setup + source = "../../" + metal_organization_id = var.metal_organization_id + metal_auth_token = var.metal_auth_token +} + +# Deploy the K3s module if platform of choice is K3s +module "deploy_k3s" { + for_each = { for k, v in module.workshop_setup.project_setup_outputs[0].invite_from_csv_outputs : k => v if var.enable_k3s } + enable_k3s = var.enable_k3s + source = "../../" + metal_organization_id = var.metal_organization_id + metal_auth_token = var.metal_auth_token + metal_project_id = each.value.collaborator_project_id + global_ip = var.global_ip + k3s_config = var.k3s_config +} diff --git a/examples/k3s-setup-new/outputs.tf b/examples/k3s-setup-new/outputs.tf new file mode 100644 index 0000000..31afcd3 --- /dev/null +++ b/examples/k3s-setup-new/outputs.tf @@ -0,0 +1,13 @@ +# Module Workshop Setup Outputs +output "workshop_setup_outputs" { + description = "Outputs of the Workshop Setup module" + + value = { for k, v in module.workshop_setup.project_setup_outputs : k => v } +} + +# Module Deploy K3s Outputs +output "deploy_k3s_outputs" { + description = "Outputs of the Deploy K3s module" + + value = { for k, v in var.k3s_config : k => v } +} diff --git a/examples/k3s-setup-new/terraform.tfvars.example b/examples/k3s-setup-new/terraform.tfvars.example new file mode 100644 index 0000000..78edcfa --- /dev/null +++ b/examples/k3s-setup-new/terraform.tfvars.example @@ -0,0 +1,2 @@ +metal_api_token="your_token_here" #This must be a user API token +metal_organization_id="your_organization_id" diff --git a/examples/k3s-setup-new/users.csv.example b/examples/k3s-setup-new/users.csv.example new file mode 100644 index 0000000..45ec366 --- /dev/null +++ b/examples/k3s-setup-new/users.csv.example @@ -0,0 +1,4 @@ +email,metro,plan +may@example.com,da,m3.small.x86 +chris@example.com,da,m3.small.x86 +oscar@example.com,da,m3.small.x86 diff --git a/examples/k3s-setup-new/variables.tf b/examples/k3s-setup-new/variables.tf new file mode 100644 index 0000000..cbdabdf --- /dev/null +++ b/examples/k3s-setup-new/variables.tf @@ -0,0 +1,64 @@ +# Module Vars +variable "metal_auth_token" { + description = "Equinix Metal user api token." + type = string + sensitive = true +} + +variable "metal_organization_id" { + type = string + description = "Equinix Metal organization id" +} + +variable "enable_workshop_setup" { + type = bool + description = "Enable Workshop Setup module" + default = true +} + +variable "global_ip" { + description = "Enables a global anycast IPv4 that will be shared for all clusters in all metros" + type = string + default = false +} + +variable "enable_k3s" { + type = bool + description = "Enable K3s module" + default = true +} + +# Module Config +variable "k3s_config" { + description = "Module configuration for K3s module" + type = list(object({ + name = string + metro = string + plan_control_plane = string + plan_node = string + node_count = number + k3s_ha = bool + os = string + control_plane_hostnames = string + node_hostnames = string + custom_k3s_token = string + ip_pool_count = number + k3s_version = string + metallb_version = string + })) + default = [{ + name = "k3s-cluster" + metro = "SV" + plan_control_plane = "c3.small.x86" + plan_node = "c3.small.x86" + node_count = 3 + k3s_ha = false + os = "debian_11" + control_plane_hostnames = "k3s-cp" + node_hostnames = "k3s-node" + custom_k3s_token = "" + ip_pool_count = 1 + k3s_version = "v1.4.stable.1" + metallb_version = "" + }] +} diff --git a/examples/k3s-setup/README.md b/examples/k3s-setup/README.md new file mode 100644 index 0000000..e59da7e --- /dev/null +++ b/examples/k3s-setup/README.md @@ -0,0 +1,43 @@ +# Terraform Equinix Labs K3s Setup Example + +This is an example of how to utilize the root module to deploy the [k3s](https://github.com/equinix-labs/terraform-equinix-metal-k3s) module. In this example, deployment target projects must identified by the variable `metal_project_ids`. Kubernetes will then be provisioned into each project defined by variable `metal_project_ids` with the configurations set by variable `k3s_config` in the [variables.tf](./variables.tf) file. + + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 1.3 | +| [equinix](#requirement\_equinix) | >= 1.10.0 | + +## Providers + +No providers. + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| [deploy\_k3s](#module\_deploy\_k3s) | ../../ | n/a | + +## Resources + +No resources. + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [enable\_k3s](#input\_enable\_k3s) | Enable K3s module | `bool` | `true` | no | +| [global\_ip](#input\_global\_ip) | Enables a global anycast IPv4 that will be shared for all clusters in all metros | `string` | `false` | no | +| [k3s\_config](#input\_k3s\_config) | Module configuration for K3s module |
list(object({
name = string
metro = string
plan_control_plane = string
plan_node = string
node_count = number
k3s_ha = bool
os = string
control_plane_hostnames = string
node_hostnames = string
custom_k3s_token = string
ip_pool_count = number
k3s_version = string
metallb_version = string
}))
|
[
{
"control_plane_hostnames": "k3s-cp",
"custom_k3s_token": "",
"ip_pool_count": 1,
"k3s_ha": false,
"k3s_version": "v1.4.stable.1",
"metallb_version": "",
"metro": "SV",
"name": "k3s-cluster",
"node_count": 3,
"node_hostnames": "k3s-node",
"os": "debian_11",
"plan_control_plane": "c3.small.x86",
"plan_node": "c3.small.x86"
}
]
| no | +| [metal\_auth\_token](#input\_metal\_auth\_token) | Equinix Metal user api token. | `string` | n/a | yes | +| [metal\_organization\_id](#input\_metal\_organization\_id) | Equinix Metal organization id | `string` | n/a | yes | +| [metal\_project\_ids](#input\_metal\_project\_ids) | Project ID to deploy K3s into | `list(string)` |
[
"49d38495-3601-4cd1-9de3-16a060ead426"
]
| no | + +## Outputs + +| Name | Description | +|------|-------------| +| [deploy\_k3s\_outputs](#output\_deploy\_k3s\_outputs) | Outputs of the Deploy K3s module | + diff --git a/examples/k3s-setup/main.tf b/examples/k3s-setup/main.tf new file mode 100644 index 0000000..1dfd510 --- /dev/null +++ b/examples/k3s-setup/main.tf @@ -0,0 +1,28 @@ +# Setup provider block +terraform { + required_version = ">= 1.3" + + required_providers { + equinix = { + source = "equinix/equinix" + version = ">= 1.10.0" + } + } +} + +# Setup metal auth token for provider +provider "equinix" { + auth_token = var.metal_auth_token +} + +# Deploy the K3s module if platform of choice is K3s +module "deploy_k3s" { + for_each = { for k, v in var.metal_project_ids : k => v if var.enable_k3s } + enable_k3s = var.enable_k3s + source = "../../" + metal_organization_id = var.metal_organization_id + metal_auth_token = var.metal_auth_token + metal_project_id = each.value + global_ip = var.global_ip + k3s_config = var.k3s_config +} diff --git a/examples/k3s-setup/outputs.tf b/examples/k3s-setup/outputs.tf new file mode 100644 index 0000000..fbea866 --- /dev/null +++ b/examples/k3s-setup/outputs.tf @@ -0,0 +1,6 @@ +# Module Deploy K3s Outputs +output "deploy_k3s_outputs" { + description = "Outputs of the Deploy K3s module" + + value = { for k, v in var.k3s_config : k => v } +} diff --git a/examples/k3s-setup/terraform.tfvars.example b/examples/k3s-setup/terraform.tfvars.example new file mode 100644 index 0000000..78edcfa --- /dev/null +++ b/examples/k3s-setup/terraform.tfvars.example @@ -0,0 +1,2 @@ +metal_api_token="your_token_here" #This must be a user API token +metal_organization_id="your_organization_id" diff --git a/examples/k3s-setup/users.csv.example b/examples/k3s-setup/users.csv.example new file mode 100644 index 0000000..45ec366 --- /dev/null +++ b/examples/k3s-setup/users.csv.example @@ -0,0 +1,4 @@ +email,metro,plan +may@example.com,da,m3.small.x86 +chris@example.com,da,m3.small.x86 +oscar@example.com,da,m3.small.x86 diff --git a/examples/k3s-setup/variables.tf b/examples/k3s-setup/variables.tf new file mode 100644 index 0000000..e81bb44 --- /dev/null +++ b/examples/k3s-setup/variables.tf @@ -0,0 +1,64 @@ +# Module Vars +variable "metal_auth_token" { + description = "Equinix Metal user api token." + type = string + sensitive = true +} + +variable "metal_organization_id" { + type = string + description = "Equinix Metal organization id" +} + +variable "metal_project_ids" { + description = "Project ID to deploy K3s into" + type = list(string) + default = [] +} + +variable "global_ip" { + description = "Enables a global anycast IPv4 that will be shared for all clusters in all metros" + type = string + default = false +} + +variable "enable_k3s" { + type = bool + description = "Enable K3s module" + default = true +} + +# Module Config +variable "k3s_config" { + description = "Module configuration for K3s module" + type = list(object({ + name = string + metro = string + plan_control_plane = string + plan_node = string + node_count = number + k3s_ha = bool + os = string + control_plane_hostnames = string + node_hostnames = string + custom_k3s_token = string + ip_pool_count = number + k3s_version = string + metallb_version = string + })) + default = [{ + name = "k3s-cluster" + metro = "SV" + plan_control_plane = "c3.small.x86" + plan_node = "c3.small.x86" + node_count = 3 + k3s_ha = false + os = "debian_11" + control_plane_hostnames = "k3s-cp" + node_hostnames = "k3s-node" + custom_k3s_token = "" + ip_pool_count = 1 + k3s_version = "v1.4.stable.1" + metallb_version = "" + }] +} diff --git a/locals.tf b/locals.tf index 1860ec2..acccadc 100644 --- a/locals.tf +++ b/locals.tf @@ -1,10 +1,12 @@ # Local vars locals { module_context = { - metal_api_token = var.metal_auth_token - project_id = var.metal_project_id - organization_id = var.metal_organization_id - metro = var.metal_metro - tags = var.metal_tags + metal_api_token = var.metal_auth_token + project_id = var.metal_project_id + metal_project_id = var.metal_project_id + organization_id = var.metal_organization_id + metro = var.metal_metro + global_ip = var.global_ip + tags = var.metal_tags } } diff --git a/main.tf b/main.tf index a6106b3..3dd9cf5 100644 --- a/main.tf +++ b/main.tf @@ -35,3 +35,12 @@ module "deploy_eksa" { module_context = local.module_context module_config = var.eksa_config } + +# Deploy the K3s module if platform of choice is K3s +module "deploy_k3s" { + count = var.enable_k3s ? 1 : 0 + source = "./modules/k3s" + + module_context = local.module_context + module_config = var.k3s_config +} diff --git a/modules/collaborator-project/main.tf b/modules/collaborator-project/main.tf index 792da86..7897eb4 100644 --- a/modules/collaborator-project/main.tf +++ b/modules/collaborator-project/main.tf @@ -11,6 +11,11 @@ terraform { resource "equinix_metal_project" "project" { name = replace(var.collaborator, "@", "-") + bgp_config { + deployment_type = var.bgp_deployment_type + md5 = var.bgp_md5_hash + asn = var.bgp_asn + } } resource "equinix_metal_project_api_key" "project_key" { diff --git a/modules/collaborator-project/variables.tf b/modules/collaborator-project/variables.tf index 05c76ba..f1e896d 100644 --- a/modules/collaborator-project/variables.tf +++ b/modules/collaborator-project/variables.tf @@ -20,3 +20,22 @@ variable "collaborator" { type = string description = "Collaborator email to join the organization" } + +# BGP Configs +variable "bgp_deployment_type" { + type = string + description = "BGP deployment type" + default = "local" +} + +variable "bgp_md5_hash" { + type = string + description = "BGP md5 hash key" + default = "54190397c4d8086bf35D" +} + +variable "bgp_asn" { + type = number + description = "BGP asn" + default = 65000 +} diff --git a/modules/k3s/README.md b/modules/k3s/README.md new file mode 100644 index 0000000..9a08d2b --- /dev/null +++ b/modules/k3s/README.md @@ -0,0 +1,38 @@ +# Terraform Equinix Labs K3s Module + +This module utilizes the [K3s module](https://registry.terraform.io/modules/equinix/k3s/metal/latest) module to deploy SUSE K3s. + + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 1.3 | + +## Providers + +No providers. + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| [k3s](#module\_k3s) | equinix/k3s/metal | 0.2.0 | + +## Resources + +No resources. + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [module\_config](#input\_module\_config) | Module configuration for K3s module |
list(object({
name = string
metro = string
plan_control_plane = string
plan_node = string
node_count = number
k3s_ha = bool
os = string
control_plane_hostnames = string
node_hostnames = string
custom_k3s_token = string
ip_pool_count = number
k3s_version = string
metallb_version = string
}))
|
[
{
"control_plane_hostnames": "k3s-cp",
"custom_k3s_token": "",
"ip_pool_count": 1,
"k3s_ha": false,
"k3s_version": "",
"metallb_version": "",
"metro": "SV",
"name": "k3s-cluster",
"node_count": 3,
"node_hostnames": "k3s-node",
"os": "debian_11",
"plan_control_plane": "c3.small.x86",
"plan_node": "c3.small.x86"
}
]
| no | +| [module\_context](#input\_module\_context) | Input context for the module |
object({
metal_project_id = string
global_ip = bool
})
| n/a | yes | + +## Outputs + +| Name | Description | +|------|-------------| +| [k3s\_outputs](#output\_k3s\_outputs) | Outputs of the K3s module | + diff --git a/modules/k3s/main.tf b/modules/k3s/main.tf new file mode 100644 index 0000000..3130325 --- /dev/null +++ b/modules/k3s/main.tf @@ -0,0 +1,13 @@ +terraform { + required_version = ">= 1.3" +} + +# Module block to call SUSE K3s module +module "k3s" { + source = "equinix/k3s/metal" + version = "0.2.0" + + metal_project_id = var.module_context.metal_project_id + global_ip = var.module_context.global_ip + clusters = var.module_config +} diff --git a/modules/k3s/outputs.tf b/modules/k3s/outputs.tf new file mode 100644 index 0000000..1c78747 --- /dev/null +++ b/modules/k3s/outputs.tf @@ -0,0 +1,6 @@ +# Module outputs +output "k3s_outputs" { + description = "Outputs of the K3s module" + + value = { for k, v in module.k3s : k => v } +} diff --git a/modules/k3s/variables.tf b/modules/k3s/variables.tf new file mode 100644 index 0000000..2a28b4e --- /dev/null +++ b/modules/k3s/variables.tf @@ -0,0 +1,43 @@ +# Module Context +variable "module_context" { + description = "Input context for the module" + type = object({ + metal_project_id = string + global_ip = bool + }) +} + +# Module Config +variable "module_config" { + description = "Module configuration for K3s module" + type = list(object({ + name = string + metro = string + plan_control_plane = string + plan_node = string + node_count = number + k3s_ha = bool + os = string + control_plane_hostnames = string + node_hostnames = string + custom_k3s_token = string + ip_pool_count = number + k3s_version = string + metallb_version = string + })) + default = [{ + name = "k3s-cluster" + metro = "SV" + plan_control_plane = "c3.small.x86" + plan_node = "c3.small.x86" + node_count = 3 + k3s_ha = false + os = "debian_11" + control_plane_hostnames = "k3s-cp" + node_hostnames = "k3s-node" + custom_k3s_token = "" + ip_pool_count = 1 + k3s_version = "" + metallb_version = "" + }] +} diff --git a/outputs.tf b/outputs.tf index d65c3bb..6cec074 100644 --- a/outputs.tf +++ b/outputs.tf @@ -5,7 +5,6 @@ output "project_setup_outputs" { value = { for k, v in module.project_setup : k => v } } - # Module Deploy Metal Outputs output "deploy_metal_outputs" { description = "Outputs of the Deploy Metal module" @@ -19,3 +18,10 @@ output "deploy_eksa_outputs" { value = { for k, v in var.metal_config : k => v } } + +# Module Deploy K3s Outputs +output "deploy_k3s_outputs" { + description = "Outputs of the Deploy K3s module" + + value = { for k, v in var.k3s_config : k => v } +} diff --git a/variables.tf b/variables.tf index d12b11b..5c457d3 100644 --- a/variables.tf +++ b/variables.tf @@ -80,3 +80,50 @@ variable "eksa_config" { worker_device_count = 3 } } + +# Variables for "K3s" module +variable "global_ip" { + type = bool + description = "Enables a global anycast IPv4 that will be shared for all clusters in all metros" + default = false +} + +variable "enable_k3s" { + type = bool + description = "Enable K3s module" + default = false +} + +variable "k3s_config" { + description = "Module configuration for K3s module" + type = list(object({ + name = string + metro = string + plan_control_plane = string + plan_node = string + node_count = number + k3s_ha = bool + os = string + control_plane_hostnames = string + node_hostnames = string + custom_k3s_token = string + ip_pool_count = number + k3s_version = string + metallb_version = string + })) + default = [{ + name = "k3s-cluster" + metro = "SV" + plan_control_plane = "c3.small.x86" + plan_node = "c3.small.x86" + node_count = 3 + k3s_ha = true + os = "debian_11" + control_plane_hostnames = "k3s-cp" + node_hostnames = "k3s-node" + custom_k3s_token = "" + ip_pool_count = 1 + k3s_version = "" + metallb_version = "" + }] +}