christianlempa-boilerplates/terraform/templates/kubernetes-automation-example/nginx1.tf

154 lines
2.7 KiB
Terraform
Raw Normal View History

2022-04-01 09:25:19 +02:00
# NGINX 1 Test Deployment
#
# TODO: Change your-domain according to your DNS record that you want to create
# TODO: Change your-zone-id according to your DNS zone ID in Cloudflare
# ---
2022-03-17 13:09:48 +01:00
resource "kubernetes_namespace" "nginx1" {
2022-04-01 09:25:19 +02:00
depends_on = [
time_sleep.wait_for_kubernetes
]
2022-03-17 13:09:48 +01:00
metadata {
name = "nginx1"
}
}
2022-04-01 09:25:19 +02:00
2022-03-17 13:09:48 +01:00
resource "kubernetes_deployment" "nginx1" {
2022-04-01 09:25:19 +02:00
depends_on = [
kubernetes_namespace.nginx1
]
2022-03-17 13:09:48 +01:00
metadata {
name = "nginx1"
namespace = "nginx1"
labels = {
app = "nginx1"
}
}
spec {
replicas = 1
selector {
match_labels = {
app = "nginx1"
}
}
template {
metadata {
labels = {
app = "nginx1"
}
}
spec {
container {
image = "nginx:latest"
name = "nginx"
port {
container_port = 80
}
}
}
}
}
}
2022-04-01 09:25:19 +02:00
2022-03-17 13:09:48 +01:00
resource "kubernetes_service" "nginx1" {
2022-04-01 09:25:19 +02:00
depends_on = [
kubernetes_namespace.nginx1
]
2022-03-17 13:09:48 +01:00
metadata {
name = "nginx1"
namespace = "nginx1"
}
spec {
selector = {
app = "nginx1"
}
port {
port = 80
}
type = "ClusterIP"
}
}
2022-04-01 09:25:19 +02:00
2022-03-17 13:09:48 +01:00
resource "kubectl_manifest" "nginx1-certificate" {
depends_on = [kubernetes_namespace.nginx1, time_sleep.wait_for_clusterissuer]
yaml_body = <<YAML
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: nginx1
namespace: nginx1
spec:
secretName: nginx1
issuerRef:
name: cloudflare-prod
kind: ClusterIssuer
dnsNames:
2022-04-01 09:25:19 +02:00
- 'your-domain'
2022-03-17 13:09:48 +01:00
YAML
}
2022-04-01 09:25:19 +02:00
2022-03-17 13:09:48 +01:00
resource "kubernetes_ingress_v1" "nginx1" {
depends_on = [kubernetes_namespace.nginx1]
metadata {
name = "nginx1"
namespace = "nginx1"
}
spec {
rule {
2022-04-01 09:25:19 +02:00
host = "your-domain"
2022-03-17 13:09:48 +01:00
http {
path {
path = "/"
backend {
service {
name = "nginx1"
port {
number = 80
}
}
}
}
}
}
tls {
secret_name = "nginx1"
2022-04-01 09:25:19 +02:00
hosts = ["your-domain"]
2022-03-17 13:09:48 +01:00
}
}
2022-04-01 09:25:19 +02:00
}
resource "cloudflare_record" "clcreative-main-cluster" {
zone_id = "your-zone-id"
name = "your-domain"
value = data.civo_loadbalancer.traefik_lb.public_ip
type = "A"
proxied = false
}