loop to create configmap
This commit is contained in:
+92
-31
@@ -1,46 +1,107 @@
|
|||||||
terraform {
|
terraform {
|
||||||
required_version = "> 0.8.0"
|
required_version = "> 0.8.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "nginx_sites" {
|
variable "nginx_sites" {
|
||||||
type = map(object({
|
type = map(object({
|
||||||
service = string
|
service = string
|
||||||
enabled = optional(bool,true)
|
enabled = optional(bool, true)
|
||||||
proxy_cache = optional(bool,false)
|
proxy_cache = optional(bool, false)
|
||||||
extra-value = optional(string,"")
|
extra-value = optional(string, "")
|
||||||
http2_bool = optional(bool,false)
|
http2_bool = optional(bool, false)
|
||||||
proxy_pass_https = optional(bool,false)
|
proxy_pass_https = optional(bool, false)
|
||||||
authentication_required = optional(bool,false)
|
authentication_required = optional(bool, false)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "local_file" "nginx"{
|
resource "local_file" "nginx" {
|
||||||
# for_each = var.nginx_sites
|
# for_each = var.nginx_sites
|
||||||
for_each = { for key, value in var.nginx_sites : key => value if value.enabled == true}
|
for_each = { for key, value in var.nginx_sites : key => value if value.enabled == true }
|
||||||
content = templatefile("nginx_config.tftpl", {
|
content = templatefile("nginx_config.tftpl", {
|
||||||
name_site = each.key
|
name_site = each.key
|
||||||
name_service = each.value.service
|
name_service = each.value.service
|
||||||
proxy_cache = each.value.proxy_cache
|
proxy_cache = each.value.proxy_cache
|
||||||
extra-value = each.value.extra-value
|
extra-value = each.value.extra-value
|
||||||
http2_bool = each.value.http2_bool
|
http2_bool = each.value.http2_bool
|
||||||
proxy_pass_https = each.value.proxy_pass_https
|
proxy_pass_https = each.value.proxy_pass_https
|
||||||
authentication_required = each.value.authentication_required
|
authentication_required = each.value.authentication_required
|
||||||
})
|
})
|
||||||
|
|
||||||
filename = "../conf.d/${each.key}.tryton.geeraert.eu.conf"
|
filename = "../conf.d/${each.key}.tryton.geeraert.eu.conf"
|
||||||
file_permission = "0600"
|
file_permission = "0600"
|
||||||
|
|
||||||
provisioner "local-exec" {
|
provisioner "local-exec" {
|
||||||
command = "kubectl exec -it deploy/reverse-proxy -n reverse-proxy -- nginx -s reload"
|
# command = "kubectl exec -it deploy/reverse-proxy -n reverse-proxy -- nginx -s reload"
|
||||||
quiet = true
|
command = "kubectl get pods -n reverse-proxy -o name | xargs -I{} kubectl exec -n reverse-proxy {} -- nginx -s reload"
|
||||||
}
|
quiet = true
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
output "Nginx_status" {
|
|
||||||
value = "Nginx pod restarted"
|
#resource "kubernetes_config_map" "automatic-configmap" {
|
||||||
}
|
# metadata {
|
||||||
|
# name = "sites-terraform"
|
||||||
|
# namespace = "reverse-proxy"
|
||||||
|
# }
|
||||||
|
# for_each = { for key, value in var.nginx_sites : key => value if value.enabled == true }
|
||||||
|
# dynamic "data" {
|
||||||
|
# for_each = each.value.enabled == true ? [""] : []
|
||||||
|
# # for_each = { for key, value in var.nginx_sites : key => value if value.enabled == true }
|
||||||
|
# content {
|
||||||
|
# key = (templatefile("nginx_config.tftpl", {
|
||||||
|
# name_site = each.key
|
||||||
|
# name_service = each.value.service
|
||||||
|
# proxy_cache = each.value.proxy_cache
|
||||||
|
# extra-value = each.value.extra-value
|
||||||
|
# http2_bool = each.value.http2_bool
|
||||||
|
# proxy_pass_https = each.value.proxy_pass_https
|
||||||
|
# authentication_required = each.value.authentication_required
|
||||||
|
# }))
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
#}
|
||||||
|
|
||||||
|
resource "kubernetes_config_map" "automatic-configmap" {
|
||||||
|
metadata {
|
||||||
|
name = "sites-terraform"
|
||||||
|
namespace = "reverse-proxy"
|
||||||
|
}
|
||||||
|
|
||||||
|
data = {
|
||||||
|
for key, value in var.nginx_sites :
|
||||||
|
"${key}.conf" => templatefile("nginx_config.tftpl", {
|
||||||
|
name_site = key
|
||||||
|
name_service = value.service
|
||||||
|
proxy_cache = value.proxy_cache
|
||||||
|
extra-value = value.extra-value
|
||||||
|
http2_bool = value.http2_bool
|
||||||
|
proxy_pass_https = value.proxy_pass_https
|
||||||
|
authentication_required = value.authentication_required
|
||||||
|
}) if value.enabled == true
|
||||||
|
}
|
||||||
|
|
||||||
|
provisioner "local-exec" {
|
||||||
|
command = "kubectl get pods -n reverse-proxy -o name | xargs -I{} kubectl delete -n reverse-proxy {}"
|
||||||
|
quiet = true
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#resource "null_resource" "cluster" {
|
||||||
|
# provisioner "local-exec" {
|
||||||
|
# command = "kubectl get pods -n reverse-proxy -o name | xargs -I{} kubectl delete -n reverse-proxy {}"
|
||||||
|
# }
|
||||||
|
#}
|
||||||
|
|
||||||
|
#https://github.com/stakater/Reloader
|
||||||
|
|
||||||
|
|
||||||
|
output "Nginx_status" {
|
||||||
|
value = "Nginx pod restarted"
|
||||||
|
}
|
||||||
provider "kubernetes" {
|
provider "kubernetes" {
|
||||||
config_path = "~/.kube/config"
|
config_path = "~/.kube/config"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user