Skip to content

Commit

Permalink
Merge pull request #24 from equinix-labs/add_k3s
Browse files Browse the repository at this point in the history
feat: added k3s module, addons, examples, updated READMEs
  • Loading branch information
ctreatma authored Aug 11, 2023
2 parents 3942250 + 4c253ed commit 4c91f9b
Show file tree
Hide file tree
Showing 27 changed files with 518 additions and 119 deletions.
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Session.vim
*.tfstate
*.tfstate.*

.terraform.lock.hcl

# Crash log files
crash.log

Expand All @@ -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
Expand Down
103 changes: 0 additions & 103 deletions .terraform.lock.hcl

This file was deleted.

11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -52,6 +54,7 @@ No providers.
| Name | Source | Version |
|------|--------|---------|
| <a name="module_deploy_eksa"></a> [deploy\_eksa](#module\_deploy\_eksa) | ./modules/eksa | n/a |
| <a name="module_deploy_k3s"></a> [deploy\_k3s](#module\_deploy\_k3s) | ./modules/k3s | n/a |
| <a name="module_deploy_metal"></a> [deploy\_metal](#module\_deploy\_metal) | ./modules/metal | n/a |
| <a name="module_project_setup"></a> [project\_setup](#module\_project\_setup) | ./modules/invite-from-csv | n/a |

Expand All @@ -63,14 +66,17 @@ No resources.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_metal_auth_token"></a> [metal\_auth\_token](#input\_metal\_auth\_token) | Equinix Metal user api token. | `string` | n/a | yes |
| <a name="input_metal_organization_id"></a> [metal\_organization\_id](#input\_metal\_organization\_id) | Equinix Metal organization id | `string` | n/a | yes |
| <a name="input_eksa_config"></a> [eksa\_config](#input\_eksa\_config) | Module configuration for EKSA module | <pre>object({<br> cluster_name = string<br> cp_device_count = number<br> worker_device_count = number<br> })</pre> | <pre>{<br> "cluster_name": "equinix-labs-cluster",<br> "cp_device_count": 3,<br> "worker_device_count": 3<br>}</pre> | no |
| <a name="input_enable_eksa"></a> [enable\_eksa](#input\_enable\_eksa) | Enable EKSA module | `bool` | `false` | no |
| <a name="input_enable_k3s"></a> [enable\_k3s](#input\_enable\_k3s) | Enable K3s module | `bool` | `false` | no |
| <a name="input_enable_metal"></a> [enable\_metal](#input\_enable\_metal) | Enable Metal module | `bool` | `false` | no |
| <a name="input_enable_workshop_setup"></a> [enable\_workshop\_setup](#input\_enable\_workshop\_setup) | Enable Workshop Setup module | `bool` | `false` | no |
| <a name="input_global_ip"></a> [global\_ip](#input\_global\_ip) | Enables a global anycast IPv4 that will be shared for all clusters in all metros | `bool` | `false` | no |
| <a name="input_k3s_config"></a> [k3s\_config](#input\_k3s\_config) | Module configuration for K3s module | <pre>list(object({<br> name = string<br> metro = string<br> plan_control_plane = string<br> plan_node = string<br> node_count = number<br> k3s_ha = bool<br> os = string<br> control_plane_hostnames = string<br> node_hostnames = string<br> custom_k3s_token = string<br> ip_pool_count = number<br> k3s_version = string<br> metallb_version = string<br> }))</pre> | <pre>[<br> {<br> "control_plane_hostnames": "k3s-cp",<br> "custom_k3s_token": "",<br> "ip_pool_count": 1,<br> "k3s_ha": true,<br> "k3s_version": "",<br> "metallb_version": "",<br> "metro": "SV",<br> "name": "k3s-cluster",<br> "node_count": 3,<br> "node_hostnames": "k3s-node",<br> "os": "debian_11",<br> "plan_control_plane": "c3.small.x86",<br> "plan_node": "c3.small.x86"<br> }<br>]</pre> | no |
| <a name="input_metal_auth_token"></a> [metal\_auth\_token](#input\_metal\_auth\_token) | Equinix Metal user api token. | `string` | n/a | yes |
| <a name="input_metal_config"></a> [metal\_config](#input\_metal\_config) | Configuration for Metal module | <pre>object({<br> device_count = number<br> os = string<br> billing_cycle = string<br> cluster_name = string<br> device_type = string<br> })</pre> | <pre>{<br> "billing_cycle": "hourly",<br> "cluster_name": "metal-cluster",<br> "device_count": 3,<br> "device_type": "m3.small.x86",<br> "os": "ubuntu_20_04"<br>}</pre> | no |
| <a name="input_metal_metro"></a> [metal\_metro](#input\_metal\_metro) | Equinix Metal metro | `string` | `"sv"` | no |
| <a name="input_metal_organization_id"></a> [metal\_organization\_id](#input\_metal\_organization\_id) | Equinix Metal organization id | `string` | n/a | yes |
| <a name="input_metal_project_id"></a> [metal\_project\_id](#input\_metal\_project\_id) | Project ID | `string` | `""` | no |
| <a name="input_metal_tags"></a> [metal\_tags](#input\_metal\_tags) | String list of common tags for Equinix resources | `list(string)` | <pre>[<br> "terraform",<br> "equinix-labs"<br>]</pre> | no |

Expand All @@ -79,6 +85,7 @@ No resources.
| Name | Description |
|------|-------------|
| <a name="output_deploy_eksa_outputs"></a> [deploy\_eksa\_outputs](#output\_deploy\_eksa\_outputs) | Outputs of the Deploy EKSA module |
| <a name="output_deploy_k3s_outputs"></a> [deploy\_k3s\_outputs](#output\_deploy\_k3s\_outputs) | Outputs of the Deploy K3s module |
| <a name="output_deploy_metal_outputs"></a> [deploy\_metal\_outputs](#output\_deploy\_metal\_outputs) | Outputs of the Deploy Metal module |
| <a name="output_project_setup_outputs"></a> [project\_setup\_outputs](#output\_project\_setup\_outputs) | Outputs of the Project Setup module |
<!-- END_TF_DOCS -->
Expand Down
2 changes: 1 addition & 1 deletion examples/eksa-setup-new/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion examples/eksa-setup/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Module Deploy Metal Outputs
# Module Deploy EKSA Outputs
output "deploy_eksa_outputs" {
description = "Outputs of the Deploy EKSA module"

Expand Down
45 changes: 45 additions & 0 deletions examples/k3s-setup-new/README.md
Original file line number Diff line number Diff line change
@@ -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.

<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
| <a name="requirement_equinix"></a> [equinix](#requirement\_equinix) | >= 1.10.0 |

## Providers

No providers.

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_deploy_k3s"></a> [deploy\_k3s](#module\_deploy\_k3s) | ../../ | n/a |
| <a name="module_workshop_setup"></a> [workshop\_setup](#module\_workshop\_setup) | ../../ | n/a |

## Resources

No resources.

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_enable_k3s"></a> [enable\_k3s](#input\_enable\_k3s) | Enable K3s module | `bool` | `true` | no |
| <a name="input_enable_workshop_setup"></a> [enable\_workshop\_setup](#input\_enable\_workshop\_setup) | Enable Workshop Setup module | `bool` | `true` | no |
| <a name="input_global_ip"></a> [global\_ip](#input\_global\_ip) | Enables a global anycast IPv4 that will be shared for all clusters in all metros | `string` | `false` | no |
| <a name="input_k3s_config"></a> [k3s\_config](#input\_k3s\_config) | Module configuration for K3s module | <pre>list(object({<br> name = string<br> metro = string<br> plan_control_plane = string<br> plan_node = string<br> node_count = number<br> k3s_ha = bool<br> os = string<br> control_plane_hostnames = string<br> node_hostnames = string<br> custom_k3s_token = string<br> ip_pool_count = number<br> k3s_version = string<br> metallb_version = string<br> }))</pre> | <pre>[<br> {<br> "control_plane_hostnames": "k3s-cp",<br> "custom_k3s_token": "",<br> "ip_pool_count": 1,<br> "k3s_ha": false,<br> "k3s_version": "v1.4.stable.1",<br> "metallb_version": "",<br> "metro": "SV",<br> "name": "k3s-cluster",<br> "node_count": 3,<br> "node_hostnames": "k3s-node",<br> "os": "debian_11",<br> "plan_control_plane": "c3.small.x86",<br> "plan_node": "c3.small.x86"<br> }<br>]</pre> | no |
| <a name="input_metal_auth_token"></a> [metal\_auth\_token](#input\_metal\_auth\_token) | Equinix Metal user api token. | `string` | n/a | yes |
| <a name="input_metal_organization_id"></a> [metal\_organization\_id](#input\_metal\_organization\_id) | Equinix Metal organization id | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_deploy_k3s_outputs"></a> [deploy\_k3s\_outputs](#output\_deploy\_k3s\_outputs) | Outputs of the Deploy K3s module |
| <a name="output_workshop_setup_outputs"></a> [workshop\_setup\_outputs](#output\_workshop\_setup\_outputs) | Outputs of the Workshop Setup module |
<!-- END_TF_DOCS -->
36 changes: 36 additions & 0 deletions examples/k3s-setup-new/main.tf
Original file line number Diff line number Diff line change
@@ -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
}
13 changes: 13 additions & 0 deletions examples/k3s-setup-new/outputs.tf
Original file line number Diff line number Diff line change
@@ -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 }
}
2 changes: 2 additions & 0 deletions examples/k3s-setup-new/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
metal_api_token="your_token_here" #This must be a user API token
metal_organization_id="your_organization_id"
4 changes: 4 additions & 0 deletions examples/k3s-setup-new/users.csv.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
email,metro,plan
[email protected],da,m3.small.x86
[email protected],da,m3.small.x86
[email protected],da,m3.small.x86
64 changes: 64 additions & 0 deletions examples/k3s-setup-new/variables.tf
Original file line number Diff line number Diff line change
@@ -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 = ""
}]
}
Loading

0 comments on commit 4c91f9b

Please sign in to comment.