2023-02-16 15:15:19 +01:00
|
|
|
# Variables
|
|
|
|
variable "k8s_ip" {
|
|
|
|
type = string
|
|
|
|
nullable = false
|
2023-08-25 17:51:32 +02:00
|
|
|
sensitive = true
|
2023-02-16 15:15:19 +01:00
|
|
|
}
|
2023-10-17 18:15:40 +02:00
|
|
|
# Create cicd_bw_k8s private network
|
|
|
|
resource "scaleway_vpc_private_network" "pn" {
|
|
|
|
name = "cicd_bw_k8s"
|
|
|
|
}
|
2023-02-16 15:15:19 +01:00
|
|
|
# Create k8s cluster
|
|
|
|
resource "scaleway_k8s_cluster" "cluster" {
|
|
|
|
type = "kapsule"
|
|
|
|
name = "bw_k8s"
|
|
|
|
version = "1.24.7"
|
|
|
|
cni = "cilium"
|
2023-10-17 18:15:40 +02:00
|
|
|
private_network_id = scaleway_vpc_private_network.pn.id
|
2023-02-16 15:15:19 +01:00
|
|
|
}
|
|
|
|
# Create k8s pool
|
|
|
|
resource "scaleway_k8s_pool" "pool" {
|
|
|
|
cluster_id = scaleway_k8s_cluster.cluster.id
|
|
|
|
name = "bw_k8s"
|
2023-03-28 17:43:10 +02:00
|
|
|
node_type = "DEV1-L"
|
2023-02-16 15:15:19 +01:00
|
|
|
size = 3
|
|
|
|
wait_for_pool_ready = true
|
|
|
|
}
|
|
|
|
# Get kubeconfig file
|
2023-08-30 15:39:38 +02:00
|
|
|
resource "local_sensitive_file" "kubeconfig" {
|
2023-02-16 15:15:19 +01:00
|
|
|
depends_on = [scaleway_k8s_pool.pool]
|
2023-08-30 15:39:38 +02:00
|
|
|
content = scaleway_k8s_cluster.cluster.kubeconfig[0].config_file
|
2023-02-16 15:15:19 +01:00
|
|
|
filename = "/tmp/k8s/kubeconfig"
|
|
|
|
}
|
|
|
|
provider "kubectl" {
|
2023-08-30 15:39:38 +02:00
|
|
|
config_path = "${local_sensitive_file.kubeconfig.filename}"
|
2023-02-16 15:15:19 +01:00
|
|
|
}
|
|
|
|
# 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", {
|
2023-02-16 15:15:19 +01:00
|
|
|
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
|
2023-02-16 15:15:19 +01:00
|
|
|
}
|