Verified Commit b0316945 authored by Hugo's avatar Hugo
Browse files

simplifie les parametres

parent 7bd13e77
- name: destroy infrastructure
hosts: localhost
tasks:
- name: run terraform
community.general.terraform:
project_path: "terraform/"
state: absent
variables:
hcloud_token: "{{ lookup('env', 'HCLOUD_TOKEN') }}"
env: "{{ lookup('env', 'ENV') }}"
- name: provision infrastructure
hosts: localhost
vars_files:
- "vars/global.yaml"
- "vars/{{ lookup('env', 'ENV') }}.yaml"
tasks:
- import_tasks: "tasks/provision.yaml"
- name: setup nodes
hosts: all
remote_user: root
vars_files:
- "vars/global.yaml"
- "vars/{{ lookup('env', 'ENV') }}.yaml"
gather_facts: false
handlers:
- name: reboot
reboot: {}
tasks:
- import_tasks: "tasks/wait_nodes.yaml"
- import_tasks: "tasks/upgrade.yaml"
- import_tasks: "tasks/setup_worker.yaml"
when: '"worker" in group_names'
- name: deploy k8s
hosts: localhost
vars_files:
- "vars/global.yaml"
- "vars/{{ lookup('env', 'ENV') }}.yaml"
tasks:
- import_tasks: "tasks/deploy.yaml"
......
......@@ -2,6 +2,9 @@
community.general.terraform:
project_path: "terraform/"
state: present
variables:
hcloud_token: "{{ lookup('env', 'HCLOUD_TOKEN') }}"
env: "{{ lookup('env', 'ENV') }}"
register: tf
- name: register controller hosts
......
- name: wait for connection
ansible.builtin.wait_for_connection: {}
- name: gather facts
ansible.builtin.gather_facts: {}
......@@ -22,7 +22,7 @@ spec:
apiVersion: k0s.k0sproject.io/v1beta1
kind: Cluster
metadata:
name: {{cluster_name}}
name: ada-lovelace
spec:
api:
externalAddress: {{control_plane_ipv4}}
......
resource "hcloud_server" "controller" {
count = var.controller_count
name = "${var.cluster_name}-controller-${count.index}"
count = local.controller_count
name = "${local.cluster_name}-controller-${count.index}"
image = "debian-10"
server_type = var.controller_type
ssh_keys = var.ssh_keys
location = var.location
server_type = local.controller_type
ssh_keys = local.ssh_keys
location = local.location
labels = {
cluster = var.cluster_name
cluster = local.cluster_name
role = "controller"
}
}
resource "hcloud_load_balancer" "control_plane_load_balancer" {
name = "${var.cluster_name}-control-plane"
load_balancer_type = var.control_plane_lb_type
location = var.location
name = "${local.cluster_name}-control-plane"
load_balancer_type = local.control_plane_lb_type
location = local.location
labels = {
cluster = var.cluster_name
cluster = local.cluster_name
}
dynamic "target" {
for_each = hcloud_server.controller
......@@ -28,7 +28,7 @@ resource "hcloud_load_balancer" "control_plane_load_balancer" {
}
resource "hcloud_load_balancer_service" "control_plane_load_balancer_service" {
for_each = toset(var.control_plane_ports)
for_each = toset(local.control_plane_ports)
load_balancer_id = hcloud_load_balancer.control_plane_load_balancer.id
protocol = "tcp"
listen_port = each.value
......
......@@ -3,7 +3,7 @@ output "controller_ipv4" {
}
output "worker_ipv4" {
value = concat(hcloud_server.worker.*.ipv4_address,var.extra_workers)
value = concat(hcloud_server.worker.*.ipv4_address,local.extra_workers)
}
output "control_plane_ipv4" {
......
......@@ -4,77 +4,24 @@ variable "hcloud_token" {
sensitive = true
}
variable "ssh_keys" {
description = "SSH Keys"
type = list(string)
}
variable "cluster_name" {
description = "Cluster name"
type = string
}
variable "location" {
description = "Cluster location"
type = string
default = "fsn1"
}
variable "controller_count" {
description = "Controller node count"
type = number
}
variable "controller_type" {
description = "Controller type"
type = string
}
variable "worker_count" {
description = "Worker node count"
type = number
}
variable "worker_type" {
description = "Node type"
type = string
}
variable "volume_count" {
description = "Number of columes by node"
type = number
}
variable "volume_size" {
description = "Volume size"
type = number
default = 10
}
variable "control_plane_ports" {
description = "Load balancer ports"
type = list(string)
default = ["6443", "9443", "8132", "8133"]
}
variable "ingress_ports" {
description = "Ingress ports"
type = list(string)
default = ["80", "443"]
}
variable "control_plane_lb_type" {
description = "Control plane load balancer type"
type = string
}
variable "ingress_lb_type" {
description = "Ingress load balancer type"
variable "env" {
description = "Environment"
type = string
}
variable "extra_workers" {
description = "Ip list of extra workers"
type = list(string)
default = []
locals {
cluster_name = var.env == "production" ? "ada-lovelace" : "ada-lovelace-${var.env}"
ssh_keys = ["3245559"]
location = "fsn1"
controller_type = var.env == "production" ? "ccx12" : "cx11"
controller_count = 3
worker_type = "cx11"
worker_count = var.env == "production" ? 0 : 4
volume_count = 2
volume_size = 10
control_plane_ports = ["6443", "9443", "8132", "8133"]
ingress_ports = ["80", "443"]
control_plane_lb_type = "lb11"
ingress_lb_type = var.env == "production" ? "lb21" : "lb11"
extra_workers = var.env == "production" ? [] : []
}
resource "hcloud_server" "worker" {
count = var.worker_count
name = "${var.cluster_name}-worker-${count.index}"
count = local.worker_count
name = "${local.cluster_name}-worker-${count.index}"
image = "debian-10"
server_type = var.worker_type
ssh_keys = var.ssh_keys
location = var.location
server_type = local.worker_type
ssh_keys = local.ssh_keys
location = local.location
labels = {
cluster = var.cluster_name
cluster = local.cluster_name
role = "worker"
}
}
resource "hcloud_volume" "volume" {
count = var.volume_count * var.worker_count
name = "${var.cluster_name}-${count.index}"
size = var.volume_size
server_id = hcloud_server.worker[count.index % var.worker_count].id
count = local.volume_count * local.worker_count
name = "${local.cluster_name}-${count.index}"
size = local.volume_size
server_id = hcloud_server.worker[count.index % local.worker_count].id
depends_on = [hcloud_server.worker]
}
resource "hcloud_load_balancer" "ingress_load_balancer" {
name = "${var.cluster_name}-ingress"
load_balancer_type = var.ingress_lb_type
location = var.location
name = "${local.cluster_name}-ingress"
load_balancer_type = local.ingress_lb_type
location = local.location
labels = {
cluster = var.cluster_name
cluster = local.cluster_name
}
dynamic "target" {
for_each = hcloud_server.worker
......@@ -37,7 +37,7 @@ resource "hcloud_load_balancer" "ingress_load_balancer" {
}
resource "hcloud_load_balancer_service" "ingress_load_balancer_service" {
for_each = toset(var.ingress_ports)
for_each = toset(local.ingress_ports)
load_balancer_id = hcloud_load_balancer.ingress_load_balancer.id
protocol = "tcp"
listen_port = each.value
......@@ -45,7 +45,7 @@ resource "hcloud_load_balancer_service" "ingress_load_balancer_service" {
}
resource "hcloud_load_balancer_target" "ingress_load_balancer_target" {
for_each = toset(var.extra_workers)
for_each = toset(local.extra_workers)
type = "ip"
load_balancer_id = hcloud_load_balancer.ingress_load_balancer.id
ip = each.value
......
cluster_name: ada-lovelace
controller_count: 3
controller_type: cx11
worker_count: 0
worker_type: cx11
volume_count: 2
control_plane_lb_type: lb11
ingress_lb_type: lb11
controller_type: ccx12
worker_count: 0
volume_count: 0
control_plane_lb_type: lb11
ingress_lb_type: lb21
cluster_name: ada-lovelace-testing
controller_count: 3
controller_type: cx11
worker_count: 0
worker_type: cx11
volume_count: 2
control_plane_lb_type: lb11
ingress_lb_type: lb11
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment