bunkerized-nginx/tests/terraform/k8s.tf

47 lines
1.2 KiB
Terraform
Raw Normal View History

# Variables
variable "k8s_ip" {
type = string
nullable = false
2023-08-25 17:51:32 +02:00
sensitive = true
}
# Create cicd_bw_k8s private network
resource "scaleway_vpc_private_network" "pn" {
name = "cicd_bw_k8s"
}
# Create k8s cluster
resource "scaleway_k8s_cluster" "cluster" {
type = "kapsule"
name = "bw_k8s"
version = "1.24.7"
cni = "cilium"
private_network_id = scaleway_vpc_private_network.pn.id
}
# Create k8s pool
resource "scaleway_k8s_pool" "pool" {
cluster_id = scaleway_k8s_cluster.cluster.id
name = "bw_k8s"
node_type = "DEV1-L"
size = 3
wait_for_pool_ready = true
}
# Get kubeconfig file
2023-08-30 15:39:38 +02:00
resource "local_sensitive_file" "kubeconfig" {
depends_on = [scaleway_k8s_pool.pool]
2023-08-30 15:39:38 +02:00
content = scaleway_k8s_cluster.cluster.kubeconfig[0].config_file
filename = "/tmp/k8s/kubeconfig"
}
provider "kubectl" {
2023-08-30 15:39:38 +02:00
config_path = "${local_sensitive_file.kubeconfig.filename}"
}
# Setup LB
2023-08-30 15:39:38 +02:00
resource "local_sensitive_file" "lb_yml" {
depends_on = [local_sensitive_file.kubeconfig]
content = templatefile("templates/lb.yml.tftpl", {
lb_ip = var.k8s_ip
})
filename = "/tmp/k8s/lb.yml"
}
resource "kubectl_manifest" "lb" {
2023-08-30 15:39:38 +02:00
depends_on = [local_sensitive_file.lb_yml]
yaml_body = local_sensitive_file.lb_yml.content
}