Skip to content

Commit

Permalink
Change web_internal_port to rule naming. Change app_name to service_name
Browse files Browse the repository at this point in the history
  • Loading branch information
bohdantverdyi committed Apr 12, 2021
1 parent b98b412 commit bd8bd7f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Terraform module for Kubernetes Ingress

## Usage (more in example direcotry)

With default labels, selector finds pods with `app` label which equal to `app_name`
With default labels, backend finds pods with `app` label which equal to `app_name`

### Example with ClusterIP
```
Expand All @@ -16,10 +16,10 @@ module "ingress" {
"kubernetes.io/ingress.class" = "nginx-custom" // Default: nginx
}
web_internal_port = [
rule = [
{
domain = local.url
internal_port = var.ports_mapping.0.internal_port // Service port
external_port = var.ports_mapping.0.external_port // Service port
}
]
tls_hosts = [
Expand Down
6 changes: 3 additions & 3 deletions example/main.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module "url_jenkins" {
source = "../"
domain_name = var.domain_name
app_name = var.app_name
app_namespace = var.app_namespace
web_internal_port = var.internal_web_port
service_name = var.service_name
service_namespace = var.service_namespace
rule = var.rule_ports
annotations = {
"kubernetes.io/ingress.class" = "nginx" // Require if used addional annontations. By default exist.
"nginx.ingress.kubernetes.io/whitelist-source-range" = "10.10.10.0/24, 30.0.0.10/25"
Expand Down
6 changes: 3 additions & 3 deletions example/variables.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
variable "internal_web_port" {
variable "rule_ports" {
default = [
{
sub_domain = "jenkins." //(Optional) ( subdomain must consist " . " in the end)
Expand All @@ -21,10 +21,10 @@ variable "domain_name" {
default = "example.com"
}

variable "app_name" {
variable "service_name" {
default = "jenkins"
}

variable "app_namespace" {
variable "service_namespace" {
default = "ci-tools"
}
15 changes: 7 additions & 8 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
resource "kubernetes_ingress" "ingress" {
metadata {
name = var.app_name
namespace = var.app_namespace
name = var.service_name
namespace = var.service_namespace
annotations = var.annotations
}
spec {
dynamic "rule" {
iterator = web_port
for_each = var.web_internal_port
for_each = var.rule
content {
host = "${lookup(web_port.value, "sub_domain", "")}${lookup(web_port.value, "domain", var.domain_name)}"
host = "${lookup(rule.value, "sub_domain", "")}${lookup(rule.value, "domain", var.domain_name)}"
http {
path {
path = lookup(web_port.value, "path", null)
path = lookup(rule.value, "path", null)
backend {
service_name = lookup(web_port.value, "service_name", var.app_name)
service_port = web_port.value.internal_port
service_name = lookup(rule.value, "service_name", var.service_name)
service_port = rule.value.external_port
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
variable "app_name" {
variable "service_name" {
type = string
description = "(Required) Application name for attach to ingress"
description = "(Required) Application name for attach to ingress. Service name."
}
variable "app_namespace" {
variable "service_namespace" {
type = string
description = "(Required) Namespace where located application"
description = "(Required) Namespace where located service"
}
variable "web_internal_port" {
description = "(Required) Container port, ingress will redirect request to this port. Also could add subdomain ( example: subdomain.domainname.com). And path for access ( example: domain.com/path ). And redefine domain."
variable "rule" {
description = "(Required) External Service port, ingress will redirect request to this service port. Also could add subdomain ( example: subdomain.domainname.com). And path for access ( example: domain.com/path ). And redefine domain."
}
variable "domain_name" {
type = string
Expand Down

0 comments on commit bd8bd7f

Please sign in to comment.