Compare commits
1 Commits
main
...
feature/sv
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b53fa3eac |
@@ -17,6 +17,9 @@ variable "protocol_provider" {
|
|||||||
variable "dns_name" {
|
variable "dns_name" {
|
||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
variable "app_name" {
|
||||||
|
type = string
|
||||||
|
}
|
||||||
variable "sub_groups" {
|
variable "sub_groups" {
|
||||||
type = list(string)
|
type = list(string)
|
||||||
default = []
|
default = []
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
locals {
|
locals {
|
||||||
forward_outpost_providers = jsondecode(data.http.get_forward_outpost.response_body).results[0].providers
|
forward_outpost_providers = jsondecode(data.http.get_forward_outpost.response_body).results[0].providers
|
||||||
forward_outpost_pk = jsondecode(data.http.get_forward_outpost.response_body).results[0].pk
|
forward_outpost_pk = jsondecode(data.http.get_forward_outpost.response_body).results[0].pk
|
||||||
app_name = var.component == var.instance ? var.instance : format("%s-%s", var.component, var.instance)
|
app_slug = "${var.instance}${var.component==""?"":"-"}${var.component}"
|
||||||
main_group = format("app-%s", local.app_name)
|
forward_labels = merge(var.labels, {
|
||||||
|
"app.kubernetes.io/component" = "authentik-forward"
|
||||||
|
})
|
||||||
|
main_group = format("app-%s", var.app_name)
|
||||||
external_url = format("https://%s", var.dns_names[0])
|
external_url = format("https://%s", var.dns_names[0])
|
||||||
rules_icons = [for v in var.dns_names : {
|
rules_icons = [for v in var.dns_names : {
|
||||||
"host" = "${v}"
|
"host" = "${v}"
|
||||||
@@ -24,9 +27,9 @@ resource "kubectl_manifest" "prj_ingress_icon" {
|
|||||||
apiVersion: "networking.k8s.io/v1"
|
apiVersion: "networking.k8s.io/v1"
|
||||||
kind: "Ingress"
|
kind: "Ingress"
|
||||||
metadata:
|
metadata:
|
||||||
name: "${var.instance}-icons"
|
name: "${local.app_slug}-icons"
|
||||||
namespace: "${var.namespace}"
|
namespace: "${var.namespace}"
|
||||||
labels: ${jsonencode(var.labels)}
|
labels: ${jsonencode(local.forward_labels)}
|
||||||
spec:
|
spec:
|
||||||
ingressClassName: "${var.ingress_class}"
|
ingressClassName: "${var.ingress_class}"
|
||||||
rules: ${jsonencode(local.rules_icons)}
|
rules: ${jsonencode(local.rules_icons)}
|
||||||
@@ -41,7 +44,7 @@ data "authentik_flow" "default-authorization-flow" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource "authentik_provider_proxy" "prj_forward" {
|
resource "authentik_provider_proxy" "prj_forward" {
|
||||||
name = local.app_name
|
name = local.app_slug
|
||||||
external_host = local.external_url
|
external_host = local.external_url
|
||||||
authorization_flow = data.authentik_flow.default-authorization-flow.id
|
authorization_flow = data.authentik_flow.default-authorization-flow.id
|
||||||
mode = "forward_single"
|
mode = "forward_single"
|
||||||
@@ -74,9 +77,9 @@ resource "kubectl_manifest" "prj_middleware" {
|
|||||||
apiVersion: traefik.containo.us/v1alpha1
|
apiVersion: traefik.containo.us/v1alpha1
|
||||||
kind: Middleware
|
kind: Middleware
|
||||||
metadata:
|
metadata:
|
||||||
name: "forward-${local.app_name}"
|
name: "${local.app_slug}-forward"
|
||||||
namespace: "${var.namespace}"
|
namespace: "${var.namespace}"
|
||||||
labels: ${jsonencode(var.labels)}
|
labels: ${jsonencode(local.forward_labels)}
|
||||||
spec:
|
spec:
|
||||||
forwardAuth:
|
forwardAuth:
|
||||||
address: http://ak-outpost-forward.${var.domain}-auth.svc:9000/outpost.goauthentik.io/auth/traefik
|
address: http://ak-outpost-forward.${var.domain}-auth.svc:9000/outpost.goauthentik.io/auth/traefik
|
||||||
|
|||||||
@@ -3,5 +3,9 @@ output "provider-id" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
output "sso_logout" {
|
output "sso_logout" {
|
||||||
value = "https://${data.kubernetes_ingress_v1.authentik.spec[0].rule[0].host}/o/${var.component}-${var.instance}/end-session/"
|
value = "https://${data.kubernetes_ingress_v1.authentik.spec[0].rule[0].host}/o/${local.app_slug}/end-session/"
|
||||||
|
}
|
||||||
|
|
||||||
|
output "middleware" {
|
||||||
|
value = "${local.app_slug}-forward"
|
||||||
}
|
}
|
||||||
@@ -1,33 +1,48 @@
|
|||||||
variable "component" {
|
variable "component" {
|
||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "instance" {
|
variable "instance" {
|
||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "icon" {
|
variable "icon" {
|
||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "domain" {
|
variable "domain" {
|
||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "namespace" {
|
variable "namespace" {
|
||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "ingress_class" {
|
variable "ingress_class" {
|
||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "labels" {
|
variable "labels" {
|
||||||
type = map(string)
|
type = map(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "dns_names" {
|
variable "dns_names" {
|
||||||
type = list(string)
|
type = list(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "access_token_validity" {
|
variable "access_token_validity" {
|
||||||
type = string
|
type = string
|
||||||
default = "hours=10" // ;minutes=10
|
default = "hours=10" // ;minutes=10
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "app_name" {
|
||||||
|
type = string
|
||||||
|
default = ""
|
||||||
|
}
|
||||||
|
|
||||||
variable "service" {
|
variable "service" {
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "request_headers" {
|
variable "request_headers" {
|
||||||
type = map(string)
|
type = map(string)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
|
|
||||||
locals {
|
locals {
|
||||||
name = "${var.instance}${var.component == "" ? "" : "-"}${var.component}"
|
app_slug = "${var.instance}${var.component==""?"":"-"}${var.component}"
|
||||||
|
pres_labels = merge(var.labels, {
|
||||||
|
"app.kubernetes.io/component" = "presentation"
|
||||||
|
})
|
||||||
rules = [for v in var.dns_names : {
|
rules = [for v in var.dns_names : {
|
||||||
"host" = "${v}"
|
"host" = "${v}"
|
||||||
"http" = {
|
"http" = {
|
||||||
@@ -15,12 +18,12 @@ locals {
|
|||||||
}]
|
}]
|
||||||
tls = var.enforce_tls ? [
|
tls = var.enforce_tls ? [
|
||||||
{
|
{
|
||||||
secretName = var.cert_name != "" ? var.cert_name : "${local.name}-cert"
|
secretName = var.cert_name != "" ? var.cert_name : "${local.app_slug}-cert"
|
||||||
hosts = var.dns_names
|
hosts = var.dns_names
|
||||||
}
|
}
|
||||||
] : []
|
] : []
|
||||||
middlewares = concat(
|
middlewares = concat(
|
||||||
var.create_redirect ? ["${local.name}-https"] : [],
|
var.create_redirect ? ["${local.app_slug}-https"] : [],
|
||||||
var.middlewares
|
var.middlewares
|
||||||
)
|
)
|
||||||
annotations = merge(
|
annotations = merge(
|
||||||
@@ -39,11 +42,11 @@ resource "kubectl_manifest" "prj_certificate" {
|
|||||||
apiVersion: "cert-manager.io/v1"
|
apiVersion: "cert-manager.io/v1"
|
||||||
kind: "Certificate"
|
kind: "Certificate"
|
||||||
metadata:
|
metadata:
|
||||||
name: "${local.name}"
|
name: "${local.app_slug}"
|
||||||
namespace: "${var.namespace}"
|
namespace: "${var.namespace}"
|
||||||
labels: ${jsonencode(var.labels)}
|
labels: ${jsonencode(local.pres_labels)}
|
||||||
spec:
|
spec:
|
||||||
secretName: "${local.name}-cert"
|
secretName: "${local.app_slug}-cert"
|
||||||
dnsNames: ${jsonencode(var.dns_names)}
|
dnsNames: ${jsonencode(var.dns_names)}
|
||||||
issuerRef:
|
issuerRef:
|
||||||
kind: "ClusterIssuer"
|
kind: "ClusterIssuer"
|
||||||
@@ -58,9 +61,9 @@ resource "kubectl_manifest" "prj_https_redirect" {
|
|||||||
apiVersion: "traefik.containo.us/v1alpha1"
|
apiVersion: "traefik.containo.us/v1alpha1"
|
||||||
kind: "Middleware"
|
kind: "Middleware"
|
||||||
metadata:
|
metadata:
|
||||||
name: "${local.name}-https"
|
name: "${local.app_slug}-https"
|
||||||
namespace: "${var.namespace}"
|
namespace: "${var.namespace}"
|
||||||
labels: ${jsonencode(var.labels)}
|
labels: ${jsonencode(local.pres_labels)}
|
||||||
spec:
|
spec:
|
||||||
redirectScheme:
|
redirectScheme:
|
||||||
scheme: "https"
|
scheme: "https"
|
||||||
@@ -74,9 +77,9 @@ resource "kubectl_manifest" "prj_ingress" {
|
|||||||
apiVersion: "networking.k8s.io/v1"
|
apiVersion: "networking.k8s.io/v1"
|
||||||
kind: "Ingress"
|
kind: "Ingress"
|
||||||
metadata:
|
metadata:
|
||||||
name: "${local.name}"
|
name: "${local.app_slug}"
|
||||||
namespace: "${var.namespace}"
|
namespace: "${var.namespace}"
|
||||||
labels: ${jsonencode(var.labels)}
|
labels: ${jsonencode(local.pres_labels)}
|
||||||
annotations: ${jsonencode(local.annotations)}
|
annotations: ${jsonencode(local.annotations)}
|
||||||
spec:
|
spec:
|
||||||
ingressClassName: "${var.ingress_class}"
|
ingressClassName: "${var.ingress_class}"
|
||||||
|
|||||||
@@ -1,17 +1,21 @@
|
|||||||
locals {
|
locals {
|
||||||
mysql_host = "${var.instance}-${var.component}-db.${var.namespace}.svc"
|
mysql_labels = merge(var.labels, {
|
||||||
mysql_username = data.kubernetes_secret_v1.prj_mysql_secret.data["rootUser"]
|
"app.kubernetes.io/component" = "mysql"
|
||||||
mysql_password = data.kubernetes_secret_v1.prj_mysql_secret.data["rootPassword"]
|
})
|
||||||
|
app_slug = "${var.instance}${var.component == "" ? "" : "-"}${var.component}"
|
||||||
|
mysql_host = "${local.app_slug}-mysql.${var.namespace}.svc"
|
||||||
|
mysql_username = data.kubernetes_secret_v1.mysql_secret.data["rootUser"]
|
||||||
|
mysql_password = data.kubernetes_secret_v1.mysql_secret.data["rootPassword"]
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "kubectl_manifest" "prj_mysql_secret" {
|
resource "kubectl_manifest" "mysql_secret" {
|
||||||
yaml_body = <<-EOF
|
yaml_body = <<-EOF
|
||||||
apiVersion: "secretgenerator.mittwald.de/v1alpha1"
|
apiVersion: "secretgenerator.mittwald.de/v1alpha1"
|
||||||
kind: "StringSecret"
|
kind: "StringSecret"
|
||||||
metadata:
|
metadata:
|
||||||
name: "${var.instance}-${var.component}-db"
|
name: "${local.app_slug}-mysql"
|
||||||
namespace: "${var.namespace}"
|
namespace: "${var.namespace}"
|
||||||
labels: ${jsonencode(var.labels)}
|
labels: ${jsonencode(local.mysql_labels)}
|
||||||
spec:
|
spec:
|
||||||
forceRegenerate: false
|
forceRegenerate: false
|
||||||
data:
|
data:
|
||||||
@@ -27,19 +31,26 @@ resource "kubectl_manifest" "prj_mysql_secret" {
|
|||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "kubectl_manifest" "prj_mysql" {
|
data "kubernetes_secret_v1" "mysql_secret" {
|
||||||
depends_on = [kubectl_manifest.prj_mysql_secret]
|
depends_on = [kubectl_manifest.mysql_secret]
|
||||||
|
metadata {
|
||||||
|
name = "${local.app_slug}-mysql"
|
||||||
|
namespace = var.namespace
|
||||||
|
labels = local.mysql_labels
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "kubectl_manifest" "mysql" {
|
||||||
yaml_body = <<-EOF
|
yaml_body = <<-EOF
|
||||||
apiVersion: mysql.oracle.com/v2
|
apiVersion: mysql.oracle.com/v2
|
||||||
kind: InnoDBCluster
|
kind: InnoDBCluster
|
||||||
metadata:
|
metadata:
|
||||||
name: "${var.instance}-${var.component}-db"
|
name: "${local.app_slug}-mysql"
|
||||||
namespace: "${var.namespace}"
|
namespace: "${var.namespace}"
|
||||||
labels: ${jsonencode(var.labels)}
|
labels: ${jsonencode(local.mysql_labels)}
|
||||||
spec:
|
spec:
|
||||||
secretName: ${kubectl_manifest.prj_mysql_secret.name}
|
secretName: ${data.kubernetes_secret_v1.mysql_secret.metadata[0].name}
|
||||||
tlsUseSelfSigned: true
|
tlsUseSelfSigned: true
|
||||||
# tlsSecretName: "${var.instance}-db-cert"
|
|
||||||
instances: 1
|
instances: 1
|
||||||
router:
|
router:
|
||||||
instances: 1
|
instances: 1
|
||||||
@@ -55,38 +66,29 @@ resource "kubectl_manifest" "prj_mysql" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource "time_sleep" "wait_mysql_ready" {
|
resource "time_sleep" "wait_mysql_ready" {
|
||||||
depends_on = [kubectl_manifest.prj_mysql_secret, kubectl_manifest.prj_mysql]
|
depends_on = [kubectl_manifest.mysql]
|
||||||
create_duration = "45s"
|
create_duration = "45s"
|
||||||
}
|
}
|
||||||
|
|
||||||
data "kubernetes_secret_v1" "prj_mysql_secret" {
|
|
||||||
depends_on = [kubectl_manifest.prj_mysql_secret, kubectl_manifest.prj_mysql, time_sleep.wait_mysql_ready]
|
|
||||||
metadata {
|
|
||||||
name = "${var.instance}-${var.component}-db"
|
|
||||||
namespace = var.namespace
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "mysql_database" "app" {
|
resource "mysql_database" "app" {
|
||||||
depends_on = [kubectl_manifest.prj_mysql_secret, kubectl_manifest.prj_mysql, time_sleep.wait_mysql_ready]
|
depends_on = [
|
||||||
|
kubectl_manifest.mysql,
|
||||||
|
time_sleep.wait_mysql_ready
|
||||||
|
]
|
||||||
name = var.database
|
name = var.database
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "mysql_user" "app_user" {
|
resource "mysql_user" "app_user" {
|
||||||
depends_on = [kubectl_manifest.prj_mysql_secret, kubectl_manifest.prj_mysql, time_sleep.wait_mysql_ready]
|
depends_on = [
|
||||||
host = data.kubernetes_secret_v1.prj_mysql_secret.data["userHost"]
|
time_sleep.wait_mysql_ready,
|
||||||
user = data.kubernetes_secret_v1.prj_mysql_secret.data["username"]
|
mysql_database.app,
|
||||||
plaintext_password = data.kubernetes_secret_v1.prj_mysql_secret.data["password"]
|
]
|
||||||
|
host = data.kubernetes_secret_v1.mysql_secret.data["userHost"]
|
||||||
|
user = data.kubernetes_secret_v1.mysql_secret.data["username"]
|
||||||
|
plaintext_password = data.kubernetes_secret_v1.mysql_secret.data["password"]
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "mysql_grant" "app_user_grant" {
|
resource "mysql_grant" "app_user_grant" {
|
||||||
depends_on = [
|
|
||||||
kubectl_manifest.prj_mysql_secret,
|
|
||||||
kubectl_manifest.prj_mysql,
|
|
||||||
time_sleep.wait_mysql_ready,
|
|
||||||
mysql_database.app,
|
|
||||||
mysql_user.app_user
|
|
||||||
]
|
|
||||||
user = mysql_user.app_user.user
|
user = mysql_user.app_user.user
|
||||||
host = mysql_user.app_user.host
|
host = mysql_user.app_user.host
|
||||||
database = mysql_database.app.name
|
database = mysql_database.app.name
|
||||||
|
|||||||
12
mysql/outpost.tf
Normal file
12
mysql/outpost.tf
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
output "dns_names" {
|
||||||
|
value = [
|
||||||
|
"${local.app_slug}-mysql",
|
||||||
|
"${local.app_slug}-mysql-instances"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
output "mysql_host" {
|
||||||
|
value =" ${local.app_slug}-mysql"
|
||||||
|
}
|
||||||
|
output "secret_name" {
|
||||||
|
value = "${local.app_slug}-db"
|
||||||
|
}
|
||||||
@@ -1,12 +1,18 @@
|
|||||||
|
locals {
|
||||||
|
app_slug = "${var.instance}${var.component==""?"":"-"}${var.component}"
|
||||||
|
oauth2_labels = merge(var.labels, {
|
||||||
|
"app.kubernetes.io/component" = "authentik-oauth2"
|
||||||
|
})
|
||||||
|
}
|
||||||
resource "kubectl_manifest" "oauth2-secret" {
|
resource "kubectl_manifest" "oauth2-secret" {
|
||||||
ignore_fields = ["metadata.annotations"]
|
ignore_fields = ["metadata.annotations"]
|
||||||
yaml_body = <<-EOF
|
yaml_body = <<-EOF
|
||||||
apiVersion: "secretgenerator.mittwald.de/v1alpha1"
|
apiVersion: "secretgenerator.mittwald.de/v1alpha1"
|
||||||
kind: "StringSecret"
|
kind: "StringSecret"
|
||||||
metadata:
|
metadata:
|
||||||
name: "${var.component}-${var.instance}-id"
|
name: "${local.app_slug}-id"
|
||||||
namespace: "${var.namespace}"
|
namespace: "${var.namespace}"
|
||||||
labels: ${jsonencode(var.labels)}
|
labels: ${jsonencode(local.oauth2_labels)}
|
||||||
spec:
|
spec:
|
||||||
forceRegenerate: false
|
forceRegenerate: false
|
||||||
fields:
|
fields:
|
||||||
@@ -19,6 +25,7 @@ data "kubernetes_secret_v1" "oauth2-client-id" {
|
|||||||
metadata {
|
metadata {
|
||||||
name = kubectl_manifest.oauth2-secret.name
|
name = kubectl_manifest.oauth2-secret.name
|
||||||
namespace = var.namespace
|
namespace = var.namespace
|
||||||
|
labels = local.oauth2_labels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +48,7 @@ data "authentik_flow" "default-authentication-flow" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource "authentik_provider_oauth2" "oauth2" {
|
resource "authentik_provider_oauth2" "oauth2" {
|
||||||
name = "${var.component}-${var.instance}"
|
name = "${local.app_slug}"
|
||||||
client_id = data.kubernetes_secret_v1.oauth2-client-id.data["client-id"]
|
client_id = data.kubernetes_secret_v1.oauth2-client-id.data["client-id"]
|
||||||
authentication_flow = data.authentik_flow.default-authentication-flow.id
|
authentication_flow = data.authentik_flow.default-authentication-flow.id
|
||||||
authorization_flow = data.authentik_flow.default-authorization-flow.id
|
authorization_flow = data.authentik_flow.default-authorization-flow.id
|
||||||
@@ -56,9 +63,9 @@ resource "authentik_provider_oauth2" "oauth2" {
|
|||||||
|
|
||||||
resource "kubernetes_secret_v1" "oauth2-client-secret" {
|
resource "kubernetes_secret_v1" "oauth2-client-secret" {
|
||||||
metadata {
|
metadata {
|
||||||
name = "${var.component}-${var.instance}-secret"
|
name = "${local.app_slug}-secret"
|
||||||
namespace = var.namespace
|
namespace = var.namespace
|
||||||
labels = var.labels
|
labels = local.oauth2_labels
|
||||||
}
|
}
|
||||||
data = {
|
data = {
|
||||||
client-secret = authentik_provider_oauth2.oauth2.client_secret
|
client-secret = authentik_provider_oauth2.oauth2.client_secret
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ output "provider-id" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
output "sso_configuration_url" {
|
output "sso_configuration_url" {
|
||||||
value = "https://${data.kubernetes_ingress_v1.authentik.spec[0].rule[0].host}/application/o/${var.component}-${var.instance}"
|
value = "https://${data.kubernetes_ingress_v1.authentik.spec[0].rule[0].host}/application/o/${local.app_slug}/"
|
||||||
}
|
}
|
||||||
|
|||||||
16
saml/saml.tf
16
saml/saml.tf
@@ -1,3 +1,9 @@
|
|||||||
|
locals{
|
||||||
|
app_slug = "${var.instance}${var.component==""?"":"-"}${var.component}"
|
||||||
|
saml_labels = merge(var.labels, {
|
||||||
|
"app.kubernetes.io/component" = "authentik-saml"
|
||||||
|
})
|
||||||
|
}
|
||||||
data "authentik_flow" "default-authorization-flow" {
|
data "authentik_flow" "default-authorization-flow" {
|
||||||
slug = "default-provider-authorization-implicit-consent"
|
slug = "default-provider-authorization-implicit-consent"
|
||||||
}
|
}
|
||||||
@@ -30,21 +36,21 @@ resource "kubectl_manifest" "saml_certificate" {
|
|||||||
apiVersion: "cert-manager.io/v1"
|
apiVersion: "cert-manager.io/v1"
|
||||||
kind: "Certificate"
|
kind: "Certificate"
|
||||||
metadata:
|
metadata:
|
||||||
name: "${var.instance}-${var.component}-saml"
|
name: "${local.app_slug}-saml"
|
||||||
namespace: "${var.namespace}"
|
namespace: "${var.namespace}"
|
||||||
labels: ${jsonencode(var.labels)}
|
labels: ${jsonencode(local.saml_labels)}
|
||||||
spec:
|
spec:
|
||||||
secretName: "${var.instance}-${var.component}-saml"
|
secretName: "${local.app_slug}-saml"
|
||||||
dnsNames: ${jsonencode(var.dns_names)}
|
dnsNames: ${jsonencode(var.dns_names)}
|
||||||
issuerRef:
|
issuerRef:
|
||||||
name: "self-sign"
|
name: "${var.issuer}"
|
||||||
kind: "ClusterIssuer"
|
kind: "ClusterIssuer"
|
||||||
group: "cert-manager.io"
|
group: "cert-manager.io"
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "authentik_provider_saml" "prj" {
|
resource "authentik_provider_saml" "prj" {
|
||||||
name = "${var.component}-${var.instance}-saml"
|
name = "${local.app_slug}-saml"
|
||||||
authentication_flow = data.authentik_flow.default-authentication-flow.id
|
authentication_flow = data.authentik_flow.default-authentication-flow.id
|
||||||
authorization_flow = data.authentik_flow.default-authorization-flow.id
|
authorization_flow = data.authentik_flow.default-authorization-flow.id
|
||||||
acs_url = "https://${var.dns_names[0]}/${var.acs_path}"
|
acs_url = "https://${var.dns_names[0]}/${var.acs_path}"
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ variable "component" {
|
|||||||
variable "instance" {
|
variable "instance" {
|
||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
variable "issuer" {
|
||||||
|
type = string
|
||||||
|
}
|
||||||
variable "dns_names" {
|
variable "dns_names" {
|
||||||
type = list(string)
|
type = list(string)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,36 @@
|
|||||||
locals {
|
locals {
|
||||||
|
app_slug = "${var.instance}${var.component==""?"":"-"}${var.component}"
|
||||||
cluster_ports = var.svc_type == "ClusterIP" ? [for idx, target in var.targets : {
|
cluster_ports = var.svc_type == "ClusterIP" ? [for idx, target in var.targets : {
|
||||||
"name" = target
|
"name" = target
|
||||||
"port" = var.ports[idx]
|
"port" = var.ports[idx]
|
||||||
"protocol" = var.protocols[idx]
|
"protocol" = var.protocols[idx]
|
||||||
"targetPort" = target
|
"targetPort" = target
|
||||||
}] : []
|
}] : []
|
||||||
|
ext_ports = var.svc_type == "ExternalName" ? [for idx, target in var.targets : {
|
||||||
|
"name" = target
|
||||||
|
"port" = var.ports[idx]
|
||||||
|
"protocol" = var.protocols[idx]
|
||||||
|
"targetPort" = var.ports[idx]
|
||||||
|
}] : []
|
||||||
|
lb_ports = var.svc_type == "LoadBalancer" ? [for idx, port in var.lb_ports : {
|
||||||
|
"port" = port
|
||||||
|
"targetPort" = var.ports[idx]
|
||||||
|
}] : []
|
||||||
node_ports = var.svc_type == "NodePort" ? [for idx, port in var.ports : {
|
node_ports = var.svc_type == "NodePort" ? [for idx, port in var.ports : {
|
||||||
"port" = port
|
"port" = port
|
||||||
"targetPort" = port
|
"targetPort" = port
|
||||||
"nodePort" = var.node_ports[idx]
|
"nodePort" = var.node_ports[idx]
|
||||||
}] : []
|
}] : []
|
||||||
|
metadata = merge(
|
||||||
|
{
|
||||||
|
"name"= "${local.app_slug}"
|
||||||
|
"namespace"= var.namespace
|
||||||
|
"labels"= var.labels
|
||||||
|
},
|
||||||
|
length(var.annotations) > 0 ? {
|
||||||
|
"annotations"= var.annotations
|
||||||
|
} : {}
|
||||||
|
)
|
||||||
spec = {
|
spec = {
|
||||||
"ClusterIP" = {
|
"ClusterIP" = {
|
||||||
type = "ClusterIP"
|
type = "ClusterIP"
|
||||||
@@ -19,11 +40,18 @@ locals {
|
|||||||
"ExternalName" = {
|
"ExternalName" = {
|
||||||
type = "ExternalName"
|
type = "ExternalName"
|
||||||
externalName = var.target_host
|
externalName = var.target_host
|
||||||
|
ports = local.ext_ports
|
||||||
},
|
},
|
||||||
"NodePort" = {
|
"NodePort" = {
|
||||||
type = "NodePort"
|
type = "NodePort"
|
||||||
selector = var.labels
|
selector = var.labels
|
||||||
ports = local.node_ports
|
ports = local.node_ports
|
||||||
|
},
|
||||||
|
"LoadBalancer" = {
|
||||||
|
type = "LoadBalancer"
|
||||||
|
selector = var.labels
|
||||||
|
ports = local.lb_ports
|
||||||
|
externalTrafficPolicy = var.lb_policy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,10 +59,7 @@ resource "kubectl_manifest" "service" {
|
|||||||
yaml_body = <<-EOF
|
yaml_body = <<-EOF
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Service
|
kind: Service
|
||||||
metadata:
|
metadata: ${jsonencode(local.metadata)}
|
||||||
name: "${var.instance}-${var.component}"
|
|
||||||
namespace: "${var.namespace}"
|
|
||||||
labels: ${jsonencode(var.labels)}
|
|
||||||
spec: ${jsonencode(local.spec[var.svc_type])}
|
spec: ${jsonencode(local.spec[var.svc_type])}
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,12 +10,16 @@ variable "namespace" {
|
|||||||
variable "labels" {
|
variable "labels" {
|
||||||
type = map(string)
|
type = map(string)
|
||||||
}
|
}
|
||||||
|
variable "annotations" {
|
||||||
|
type = map(string)
|
||||||
|
default = {}
|
||||||
|
}
|
||||||
variable "svc_type" {
|
variable "svc_type" {
|
||||||
type = string
|
type = string
|
||||||
default = "ClusterIP"
|
default = "ClusterIP"
|
||||||
validation {
|
validation {
|
||||||
condition = contains(["ClusterIP", "ExternalName", "NodePort"], var.svc_type)
|
condition = contains(["ClusterIP", "ExternalName", "NodePort", "LoadBalancer"], var.svc_type)
|
||||||
error_message = "Only ClusterIP or ExternalName is allowed"
|
error_message = "Only ClusterIP, ExternalName, NodePort or LoadBalancer is allowed"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
variable "ports" {
|
variable "ports" {
|
||||||
@@ -46,3 +50,15 @@ variable "node_ports" {
|
|||||||
error_message = "The range of valid ports is 30000-32767"
|
error_message = "The range of valid ports is 30000-32767"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
variable "lb_ports" {
|
||||||
|
type = list(number)
|
||||||
|
default = [8080]
|
||||||
|
}
|
||||||
|
variable "lb_policy" {
|
||||||
|
type = string
|
||||||
|
default = "Cluster"
|
||||||
|
validation {
|
||||||
|
condition = contains(["Cluster", "Local"], var.lb_policy)
|
||||||
|
error_message = "Only Cluster or Local is allowed"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user