Skip to content

Commit 6225263

Browse files
committed
Initial commit
1 parent aa7011d commit 6225263

File tree

8 files changed

+737
-1
lines changed

8 files changed

+737
-1
lines changed

README.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,46 @@
11
# terraform-xo-microk8s
2-
This repository contains a Terraform module designed to deploy virtual machines that form a MicroK8s cluster using Xen-Orchestra
2+
This repository contains a Terraform module designed to deploy virtual machines that form a MicroK8s cluster using Xen-Orchestra. It creates a 3-node cluster by default but more nodes can be added dynamically.
3+
4+
# Example usage
5+
6+
```bash
7+
module "microk8s_cluster" {
8+
source = "../"
9+
10+
# Node settings
11+
node_count = 0
12+
node_prefix = "us20-k8s"
13+
node_cpu_count = 2
14+
node_memory_gb = 4
15+
node_os_disk_size = 10
16+
node_os_disk_xoa_sr_uuid = ["f5476a1f-03ad-f4fb-ed42-82397ff9a211"]
17+
node_xoa_template_uuid = "5cd9d957-fc99-cb17-7550-777204797183"
18+
19+
# Master settings
20+
master_count = 3
21+
master_prefix = "us20-k8s"
22+
master_cpu_count = 8
23+
master_memory_gb = 8
24+
master_os_disk_size = 10
25+
master_os_disk_xoa_sr_uuid = ["cf62bbaf-8107-19cb-9b8c-62cbf28d2f52"]
26+
master_xoa_template_uuid = "499cad8b-dff9-cfa9-cc18-719184d85747"
27+
28+
# Xen Orchestra settings can be set via environment variables
29+
#xoa_username => XOA_USERNAME
30+
#xoa_password => XOA_PASSWORD
31+
#xoa_ignore_ssl => XOA_IGNORE_SSL
32+
#xoa_api_url => XOA_API_URL
33+
34+
xoa_pool_name = "my-xcp-ng-pool"
35+
xoa_network_name = "[95] Kubernetes"
36+
start_delay = 0
37+
38+
# Other settings
39+
public_ssh_key = "ssh-rsa AAAAB3N..."
40+
41+
dns_zone = "example.com."
42+
dns_sub_zone = "k8s"
43+
cluster_dns_zone = "k8s.example.com."
44+
cluster_name = "cluster"
45+
}
46+
```

local_mac_addressses.tf

Lines changed: 4 additions & 0 deletions
Large diffs are not rendered by default.

providers.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This file contains the Xen orchestra configuration for VM's.
2+
# docs : https://github.com/terra-farm/terraform-provider-xenorchestra/blob/master/docs/resources/vm.md
3+
terraform {
4+
required_providers {
5+
xenorchestra = {
6+
source = "terra-farm/xenorchestra"
7+
}
8+
macaddress = {
9+
source = "ivoronin/macaddress"
10+
#version = "0.3.0"
11+
}
12+
gitlab = {
13+
source = "gitlabhq/gitlab"
14+
#version = "16.4.1"
15+
}
16+
sshcommand = {
17+
source = "invidian/sshcommand"
18+
#version = "0.2.2"
19+
}
20+
}
21+
}

variables.tf

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
# Node Settings
2+
variable "node_count" {
3+
description = "Number of worker nodes to deploy"
4+
type = number
5+
default = 0
6+
}
7+
8+
variable "node_prefix" {
9+
description = "Prefix for worker node names"
10+
type = string
11+
default = "us20-k8s"
12+
}
13+
14+
variable "node_cpu_count" {
15+
description = "Number of CPUs for each worker node"
16+
type = number
17+
default = 4
18+
}
19+
20+
variable "node_memory_gb" {
21+
description = "Memory in GB for each worker node"
22+
type = number
23+
default = 8
24+
}
25+
26+
variable "node_os_disk_size" {
27+
description = "OS disk size in GB for each worker node"
28+
type = number
29+
default = 32
30+
}
31+
32+
variable "node_os_disk_xoa_sr_uuid" {
33+
description = "Storage repository UUID for worker node OS disks"
34+
type = list(string)
35+
}
36+
37+
variable "node_xoa_template_uuid" {
38+
description = "Template UUID for worker nodes in Xen Orchestra"
39+
type = string
40+
}
41+
42+
variable "node_xoa_network_name" {
43+
description = "Network name for worker nodes in Xen Orchestra (overrides `xoa_network_name`)"
44+
type = string
45+
default = null
46+
}
47+
48+
variable "node_tags" {
49+
description = "Tags to apply to worker nodes"
50+
type = list(string)
51+
default = [
52+
"xcp-ng.org/arch:amd64",
53+
"xcp-ng.org/os:ubuntu"
54+
]
55+
}
56+
57+
# Master Settings
58+
variable "master_count" {
59+
description = "Number of master nodes to deploy"
60+
type = number
61+
default = 3
62+
}
63+
64+
variable "master_prefix" {
65+
description = "Prefix for master node names"
66+
type = string
67+
default = "us20-k8s"
68+
}
69+
70+
variable "master_cpu_count" {
71+
description = "Number of CPUs for each master node"
72+
type = number
73+
default = 2
74+
}
75+
76+
variable "master_memory_gb" {
77+
description = "Memory in GB for each master node"
78+
type = number
79+
default = 4
80+
}
81+
82+
variable "master_os_disk_size" {
83+
description = "OS disk size in GB for each master node"
84+
type = number
85+
default = 32
86+
}
87+
88+
variable "master_os_disk_xoa_sr_uuid" {
89+
description = "Storage repository UUID for master node OS disks"
90+
type = list(string)
91+
}
92+
93+
variable "master_xoa_template_uuid" {
94+
description = "Template UUID for master nodes in Xen Orchestra"
95+
type = string
96+
}
97+
98+
variable "master_xoa_network_name" {
99+
description = "Network name for master nodes in Xen Orchestra (overrides `xoa_network_name`)"
100+
type = string
101+
default = null
102+
}
103+
104+
variable "master_tags" {
105+
description = "Tags to apply to master nodes"
106+
type = list(string)
107+
default = [
108+
"xcp-ng.org/arch:amd64",
109+
"xcp-ng.org/os:ubuntu"
110+
]
111+
}
112+
113+
# Xen Orchestra Settings
114+
variable "xoa_api_url" {
115+
description = "URL for Xen Orchestra API (can be set via XOA_API_URL environment variable)"
116+
type = string
117+
}
118+
119+
variable "xoa_pool_name" {
120+
description = "Default name of the XCP-ng pool as seen in Xen Orchestra"
121+
type = string
122+
default = null
123+
}
124+
125+
variable "xoa_network_name" {
126+
description = "Default network for virtual machines as seen in Xen Orchestra"
127+
type = string
128+
default = null
129+
}
130+
131+
variable "master_xoa_pool_name" {
132+
description = "Name of the Xen Orchestra pool for master nodes (overrides `xoa_pool_name` for masters)"
133+
type = string
134+
default = null
135+
}
136+
137+
variable "node_xoa_pool_name" {
138+
description = "Name of the Xen Orchestra pool for worker nodes (overrides `xoa_pool_name` for nodes)"
139+
type = string
140+
default = null
141+
}
142+
143+
variable "xoa_username" {
144+
description = "Username for Xen Orchestra API (can be set via XOA_USERNAME environment variable)"
145+
type = string
146+
default = null
147+
}
148+
149+
variable "xoa_password" {
150+
description = "Password for Xen Orchestra API (can be set via XOA_PASSWORD environment variable)"
151+
type = string
152+
default = null
153+
}
154+
155+
variable "xoa_ignore_ssl" {
156+
description = "Ignore SSL verification for Xen Orchestra API (can be set via XOA_IGNORE_SSL environment variable)"
157+
type = bool
158+
default = null
159+
}
160+
161+
variable "start_delay" {
162+
description = "The amount of time the cluster virtual machines will wait on XCP-NG host startup"
163+
type = number
164+
default = 0
165+
}
166+
167+
# Other Settings
168+
variable "cluster_dns_zone" {
169+
description = "DNS zone for the cluster"
170+
type = string
171+
}
172+
173+
variable "public_ssh_key" {
174+
description = "Public SSH key for accessing the nodes"
175+
type = string
176+
}
177+
178+
variable "private_ssh_key_path" {
179+
description = "Private SSH key path for accessing the nodes"
180+
type = string
181+
default = "/root/.ssh/id_rsa"
182+
}
183+
184+
variable "dns_zone" {
185+
description = "DNS zone"
186+
type = string
187+
}
188+
189+
variable "dns_sub_zone" {
190+
description = "DNS sub-zone"
191+
type = string
192+
}
193+
194+
variable "cluster_name" {
195+
description = "Name used in the virtual machine names, not an actual Kubernetes settings"
196+
type = string
197+
default = "my-cluster"
198+
}
199+
200+
variable "microk8s_version" {
201+
description = "The snap channel version to install, for example `1.29/stable`. Defaults to latest if not specified"
202+
type = string
203+
default = null
204+
}
205+
206+
variable "cloud_network_config_template" {
207+
description = "Template for cloud network config"
208+
type = string
209+
default = <<EOF
210+
network:
211+
version: 1
212+
config:
213+
- type: physical
214+
name: eth0
215+
subnets:
216+
- type: dhcp
217+
EOF
218+
}

xen_data.tf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
provider "xenorchestra" {
2+
# Configuration options
3+
# Must be ws or wss
4+
url = var.xoa_api_url # Or set XOA_URL environment variable
5+
#username = var.xoa_username # Or set XOA_USER environment variable
6+
#password = var.xoa_password # Or set XOA_PASSWORD environment variable
7+
insecure = var.xoa_ignore_ssl # Or set XOA_INSECURE environment variable to any value
8+
}
9+
10+
11+
# docs : https://github.com/terra-farm/terraform-provider-xenorchestra/blob/master/docs/resources/vm.md
12+
13+
locals {
14+
master_pool_name = var.master_xoa_pool_name == null ? var.xoa_pool_name : var.master_xoa_pool_name
15+
node_pool_name = var.node_xoa_pool_name == null ? var.xoa_pool_name : var.node_xoa_pool_name
16+
master_network = var.master_xoa_network_name == null ? var.xoa_network_name : var.master_xoa_network_name
17+
node_network = var.node_xoa_network_name == null ? var.xoa_network_name : var.node_xoa_network_name
18+
}
19+
20+
data "xenorchestra_pool" "xcp_ng_master" {
21+
name_label = local.master_pool_name
22+
}
23+
24+
data "xenorchestra_pool" "xcp_ng_node" {
25+
name_label = local.node_pool_name
26+
}
27+
28+
data "xenorchestra_network" "master" {
29+
pool_id = data.xenorchestra_pool.xcp_ng_master.id
30+
name_label = local.master_network
31+
}
32+
33+
data "xenorchestra_network" "node" {
34+
pool_id = data.xenorchestra_pool.xcp_ng_node.id
35+
name_label = local.node_network
36+
}

0 commit comments

Comments
 (0)