Skip to content

Commit 5be5089

Browse files
committedSep 14, 2021
docs: add OpenStack example
1 parent 3b27c30 commit 5be5089

10 files changed

+211
-1
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
This is a [Terraform](https://www.terraform.io) provider for [Talos](https://www.talos.dev), a minimal and modern OS for running Kubernetes clusters. It helps to bootstrap a Talos based Kubernetes cluster, and returns the `kubeconfig` data that can be used with the [Kubernetes](https://registry.terraform.io/providers/hashicorp/kubernetes/latest) and [Helm](https://registry.terraform.io/providers/hashicorp/helm/latest) providers.
44

5-
The `examples/digitalocean` folder contains instructions on how to deploy a Talos cluster on [DigitalOcean](https://www.digitalocean.com), and can be used as a starting point to write configurations for other cloud providers.
5+
The `examples` folder contains working Terraform configurations to deploy Talos clusters on [DigitalOcean](https://www.digitalocean.com) and [OpenStack](https://www.openstack.org), and can be used as a starting point to write configurations for other cloud providers.

‎examples/openstack/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# OpenStack
2+
3+
```shell-session
4+
talosctl gen config openstack https://1.2.3.4
5+
terraform init
6+
terraform apply
7+
```
8+
9+
(tested on [VEXXHOST](https://vexxhost.com)).

‎examples/openstack/control-plane.tf

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
resource "openstack_compute_instance_v2" "talos_control_plane" {
2+
count = var.control_plane_number
3+
4+
name = "talos-control-plane-${count.index}"
5+
flavor_name = var.control_plane_flavor
6+
image_id = openstack_images_image_v2.talos.id
7+
8+
network {
9+
name = var.network_name
10+
}
11+
12+
user_data = yamlencode(merge(
13+
local.control_plane_config,
14+
{
15+
cluster = merge(
16+
local.control_plane_config.cluster,
17+
{
18+
controlPlane = {
19+
endpoint = "https://${openstack_lb_loadbalancer_v2.talos_control_plane.vip_address}"
20+
}
21+
}
22+
)
23+
}
24+
))
25+
}

‎examples/openstack/custom-image.tf

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
resource "openstack_images_image_v2" "talos" {
2+
container_format = "bare"
3+
disk_format = "raw"
4+
image_source_url = var.talos_image
5+
name = "Talos"
6+
}

‎examples/openstack/kubernetes.tf

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
resource "talos_bootstrap" "openstack" {
2+
endpoint = openstack_compute_instance_v2.talos_control_plane[0].access_ip_v4
3+
machine_ca = base64decode(local.talos_config.contexts.openstack.ca)
4+
machine_crt = base64decode(local.talos_config.contexts.openstack.crt)
5+
machine_key = base64decode(local.talos_config.contexts.openstack.key)
6+
}
7+
8+
output "kubeconfig" {
9+
value = talos_bootstrap.openstack
10+
}
11+
12+
provider "kubernetes" {
13+
host = openstack_lb_loadbalancer_v2.talos_control_plane.vip_address
14+
client_certificate = talos_bootstrap.openstack.client_certificate
15+
client_key = talos_bootstrap.openstack.client_key
16+
cluster_ca_certificate = talos_bootstrap.openstack.cluster_ca_certificate
17+
}
18+
19+
resource "time_sleep" "wait_60_seconds" {
20+
depends_on = [talos_bootstrap.openstack]
21+
22+
create_duration = "60s"
23+
}
24+
25+
data "kubernetes_all_namespaces" "allns" {
26+
depends_on = [time_sleep.wait_60_seconds]
27+
}
28+
29+
output "all-ns" {
30+
value = data.kubernetes_all_namespaces.allns.namespaces
31+
}

‎examples/openstack/load-balancer.tf

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
data "openstack_networking_network_v2" "talos_network" {
2+
name = var.network_name
3+
}
4+
5+
resource "openstack_lb_loadbalancer_v2" "talos_control_plane" {
6+
name = "talos-control-plane"
7+
vip_network_id = data.openstack_networking_network_v2.talos_network.id
8+
}
9+
10+
resource "openstack_lb_listener_v2" "talos_control_plane" {
11+
name = "talos-control-plane"
12+
loadbalancer_id = openstack_lb_loadbalancer_v2.talos_control_plane.id
13+
protocol = "TCP"
14+
protocol_port = 443
15+
}
16+
17+
resource "openstack_lb_pool_v2" "talos_control_plane" {
18+
name = "talos-control-plane"
19+
lb_method = "ROUND_ROBIN"
20+
listener_id = openstack_lb_listener_v2.talos_control_plane.id
21+
protocol = "TCP"
22+
}
23+
24+
resource "openstack_lb_monitor_v2" "talos_control_plane" {
25+
pool_id = openstack_lb_pool_v2.talos_control_plane.id
26+
delay = 5
27+
max_retries = 4
28+
timeout = 10
29+
type = "TCP"
30+
}
31+
32+
resource "openstack_lb_member_v2" "talos_control_plane" {
33+
count = var.control_plane_number
34+
35+
name = "talos-control-plane-${count.index}"
36+
address = openstack_compute_instance_v2.talos_control_plane[count.index].network[0].fixed_ip_v4
37+
pool_id = openstack_lb_pool_v2.talos_control_plane.id
38+
protocol_port = 6443
39+
}

‎examples/openstack/local-values.tf

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
locals {
2+
control_plane_config = yamldecode(file("${path.module}/controlplane.yaml"))
3+
talos_config = yamldecode(file("${path.module}/talosconfig"))
4+
worker_config = yamldecode(file("${path.module}/worker.yaml"))
5+
}

‎examples/openstack/main.tf

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
terraform {
2+
required_providers {
3+
openstack = {
4+
source = "terraform-provider-openstack/openstack"
5+
version = "~> 1.43"
6+
}
7+
talos = {
8+
source = "tensor5/talos"
9+
version = "~> 0.1"
10+
}
11+
}
12+
}
13+
14+
provider "openstack" {
15+
auth_url = var.auth_url
16+
application_credential_id = var.application_credential_id
17+
application_credential_secret = var.application_credential_secret
18+
region = var.region
19+
use_octavia = true
20+
}
21+
22+
provider "talos" {}

‎examples/openstack/variables.tf

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
variable "control_plane_number" {
2+
description = "Number of control plane nodes"
3+
default = 3
4+
}
5+
6+
variable "control_plane_flavor" {
7+
description = "Flavor of a control plane node"
8+
type = string
9+
}
10+
11+
variable "worker_number" {
12+
description = "Number of worker nodes"
13+
default = 1
14+
}
15+
16+
variable "worker_flavor" {
17+
description = "Flavor of a worker node"
18+
type = string
19+
}
20+
21+
variable "auth_url" {
22+
description = "OpenStack authentication URL"
23+
type = string
24+
}
25+
26+
variable "application_credential_id" {
27+
type = string
28+
}
29+
30+
variable "application_credential_secret" {
31+
sensitive = true
32+
type = string
33+
}
34+
35+
variable "network_name" {
36+
description = "Network name"
37+
default = "public"
38+
}
39+
40+
variable "region" {
41+
description = "Region"
42+
type = string
43+
}
44+
45+
variable "talos_image" {
46+
description = "URL of Talos raw disk image"
47+
type = string
48+
}

‎examples/openstack/worker.tf

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
resource "openstack_compute_instance_v2" "talos_worker" {
2+
count = var.worker_number
3+
4+
name = "talos-worker-${count.index}"
5+
flavor_name = var.worker_flavor
6+
image_id = openstack_images_image_v2.talos.id
7+
8+
network {
9+
name = var.network_name
10+
}
11+
12+
user_data = yamlencode(merge(
13+
local.worker_config,
14+
{
15+
cluster = merge(
16+
local.worker_config.cluster,
17+
{
18+
controlPlane = {
19+
endpoint = "https://${openstack_lb_loadbalancer_v2.talos_control_plane.vip_address}"
20+
}
21+
}
22+
)
23+
}
24+
))
25+
}

0 commit comments

Comments
 (0)