Skip to content

Instantly share code, notes, and snippets.

@butnaruandrei
Created January 13, 2021 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save butnaruandrei/022d5c440159cfc86d442b1b5bea8a6f to your computer and use it in GitHub Desktop.
Save butnaruandrei/022d5c440159cfc86d442b1b5bea8a6f to your computer and use it in GitHub Desktop.
# variables.tf
variable "security_group_id" {
default = ""
definition = "ID of the Security Group that we want to attach to the Kubernetes ingress"
}
# main.tf
locals {
ingress_annotations_required = {
"kubernetes.io/ingress.class" = "alb"
"alb.ingress.kubernetes.io/scheme" = "internet-facing"
"alb.ingress.kubernetes.io/target-type" = "ip"
"alb.ingress.kubernetes.io/listen-ports" = [{ "HTTP": 80 }, { "HTTPS": 443 }]
}
ingress_annotations_optional = {
security_group = var.security_group_id == "" ? {} : { "alb.ingress.kubernetes.io/security-groups" = var.security_group_id }
}
ingress_annotations = merge(
local.ingress_annotations_required,
local.ingress_annotations_optional["security_group"]
)
}
resource "kubernetes_ingress" "ingress" {
[...]
metadata {
[...]
annotations = local.ingress_annotations
}
[...]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment