khuedoan-homelab/infra/cluster.tf

56 lines
1.1 KiB
Terraform
Raw Normal View History

provider "rke" {
debug = true
}
2021-06-09 00:48:22 +07:00
locals {
hosts = yamldecode(file("../metal/hosts.yml"))
user = local.hosts.metal.vars.ansible_user
ssh_key = file(local.hosts.metal.vars.ansible_ssh_private_key_file)
}
2021-05-21 01:26:03 +07:00
resource "rke_cluster" "cluster" {
dynamic "nodes" {
for_each = [
2021-06-09 00:48:22 +07:00
local.hosts.metal.hosts.metal0.ansible_host,
local.hosts.metal.hosts.metal1.ansible_host,
local.hosts.metal.hosts.metal2.ansible_host
2021-05-21 01:26:03 +07:00
]
content {
address = nodes.value
2021-06-09 00:48:22 +07:00
user = local.user
2021-05-21 01:26:03 +07:00
role = [
"controlplane",
"etcd",
"worker"
]
2021-06-09 00:48:22 +07:00
ssh_key = local.ssh_key
2021-05-21 01:26:03 +07:00
}
}
dynamic "nodes" {
for_each = [
2021-06-09 00:48:22 +07:00
local.hosts.metal.hosts.metal3.ansible_host
2021-05-21 01:26:03 +07:00
]
content {
address = nodes.value
2021-06-09 00:48:22 +07:00
user = local.user
2021-05-21 01:26:03 +07:00
role = [
"worker"
]
2021-06-09 00:48:22 +07:00
ssh_key = local.ssh_key
2021-05-21 01:26:03 +07:00
}
}
ingress {
provider = "none"
}
}
resource "local_file" "kube_config_yaml" {
filename = "${path.root}/kube_config.yaml"
sensitive_content = rke_cluster.cluster.kube_config_yaml
file_permission = "0600"
}