From 453bdb0be59e9f900bf472f49f4b7a05c2f4b8b9 Mon Sep 17 00:00:00 2001 From: Dennis Hoppe Date: Thu, 13 Jan 2022 10:01:59 +0100 Subject: [PATCH] Reorganize structure of Terraform manifests --- locals.tf | 16 +++++++++++++ main.tf | 67 ---------------------------------------------------- providers.tf | 3 +++ variables.tf | 44 ++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 67 deletions(-) create mode 100644 locals.tf create mode 100644 providers.tf create mode 100644 variables.tf diff --git a/locals.tf b/locals.tf new file mode 100644 index 0000000..5a4dbe4 --- /dev/null +++ b/locals.tf @@ -0,0 +1,16 @@ +locals { + first_control_plane_network_ip = cidrhost(hcloud_network.k3s.ip_range, 2) + ssh_public_key = trimspace(file(var.public_key)) + hcloud_image_name = "ubuntu-20.04" + + k3os_install_commands = [ + "apt install -y grub-efi grub-pc-bin mtools xorriso", + "latest=$(curl -s https://api.github.com/repos/rancher/k3os/releases | jq '.[0].tag_name')", + "curl -Lo ./install.sh https://raw.githubusercontent.com/rancher/k3os/$(echo $latest | xargs)/install.sh", + "chmod +x ./install.sh", + "./install.sh --config /tmp/config.yaml /dev/sda https://github.com/rancher/k3os/releases/download/$(echo $latest | xargs)/k3os-amd64.iso", + "shutdown -r +1", + "sleep 3", + "exit 0" + ] +} diff --git a/main.tf b/main.tf index 6588eb1..e33087b 100644 --- a/main.tf +++ b/main.tf @@ -1,52 +1,3 @@ -variable "hcloud_token" { - description = "Hetzner API tokey" - type = string -} - -variable "public_key" { - description = "SSH public Key." - type = string -} - -variable "private_key" { - description = "SSH private Key." - type = string -} - -variable "location" { - description = "Default server location" - type = string -} - -variable "control_plane_server_type" { - description = "Default control plane server type" - type = string -} - -variable "agent_server_type" { - description = "Default agent server type" - type = string -} - -variable "lb_server_type" { - description = "Default load balancer server type" - type = string -} - -variable "servers_num" { - description = "Number of control plane nodes." - type = number -} - -variable "agents_num" { - description = "Number of agent nodes." - type = number -} - -provider "hcloud" { - token = var.hcloud_token -} - resource "random_password" "k3s_token" { length = 48 special = false @@ -193,24 +144,6 @@ resource "hcloud_firewall" "k3s" { } - -locals { - first_control_plane_network_ip = cidrhost(hcloud_network.k3s.ip_range, 2) - ssh_public_key = trimspace(file(var.public_key)) - hcloud_image_name = "ubuntu-20.04" - - k3os_install_commands = [ - "apt install -y grub-efi grub-pc-bin mtools xorriso", - "latest=$(curl -s https://api.github.com/repos/rancher/k3os/releases | jq '.[0].tag_name')", - "curl -Lo ./install.sh https://raw.githubusercontent.com/rancher/k3os/$(echo $latest | xargs)/install.sh", - "chmod +x ./install.sh", - "./install.sh --config /tmp/config.yaml /dev/sda https://github.com/rancher/k3os/releases/download/$(echo $latest | xargs)/k3os-amd64.iso", - "shutdown -r +1", - "sleep 3", - "exit 0" - ] -} - data "hcloud_image" "linux" { name = local.hcloud_image_name } diff --git a/providers.tf b/providers.tf new file mode 100644 index 0000000..706ed68 --- /dev/null +++ b/providers.tf @@ -0,0 +1,3 @@ +provider "hcloud" { + token = var.hcloud_token +} diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..8f2c670 --- /dev/null +++ b/variables.tf @@ -0,0 +1,44 @@ +variable "hcloud_token" { + description = "Hetzner API tokey" + type = string +} + +variable "public_key" { + description = "SSH public Key." + type = string +} + +variable "private_key" { + description = "SSH private Key." + type = string +} + +variable "location" { + description = "Default server location" + type = string +} + +variable "control_plane_server_type" { + description = "Default control plane server type" + type = string +} + +variable "agent_server_type" { + description = "Default agent server type" + type = string +} + +variable "lb_server_type" { + description = "Default load balancer server type" + type = string +} + +variable "servers_num" { + description = "Number of control plane nodes." + type = number +} + +variable "agents_num" { + description = "Number of agent nodes." + type = number +}