Skip to content

Commit

Permalink
Add support IngressClass. Add new variables. Update chart. Add versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Bohdan Tverdyi committed Nov 4, 2021
1 parent 36eaf29 commit 0e261a8
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 7 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ Terraform module used to create nginx ingress controller in Kubernetes via Helm.

## Usage

#### For activate controller in ingress resource, please add this annotation to ingress:
"kubernetes.io/ingress.class" = "nginx"
### IngressClass
By default, all new ingresses use this controller as default.

If you have already default IngressClass specified, please set `ingress_class_is_default=false`. \
In this case you should specify `ingressClassName` to your ingress manually.

#### GCP
```terraform
Expand Down Expand Up @@ -47,6 +50,9 @@ module "nginx-controller" {
|------|-------------|------|---------|:--------:|
| name | Name of created helm release | `string` | `ingress-nginx` | no |
| namespace\_name | Name of namespace where nginx controller should be deployed | `string` | `kube-system` | no |
| chart\_version | HELM Chart Version for controller ( It is not recommended to change )| `string` | `4.0.6` | no |
| ingress\_class\_name | IngressClass resource name | `string` | `nginx` | no |
| ingress\_class\_is_default | IngressClass resource default for cluster | `bool` | `true` | no |
| ip_address | External Static Address for loadbalancer (Doesn't work with AWS) | `string` | n/a | no |
| controller_kind | Controller type: DaemonSet, Deployment etc.. | `string` | `DaemonSet` | no |
| controller_daemonset_useHostPort | Also use host ports(80,443) for pods. Node Ports in services will be untouched | `bool` | `false` | no |
Expand All @@ -65,10 +71,13 @@ module "nginx-controller" {
|------|:-----------:|
| name | Namespace used by nginx controller |
| namespace | Namespace used by nginx controller |
| ingress\_class\_name | IngressClass name for this controller |

## Terraform Requirements

| Name | Version |
|------|---------|
| terraform | >= 0.13.0 |
| helm | >= 2.1.0 |

## Kubernetes version: `>=1.19`
1 change: 0 additions & 1 deletion locals.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
locals {
helm_chart = "ingress-nginx"
helm_repository = "https://kubernetes.github.io/ingress-nginx"
helm_template_version = "3.36.0"

loadBalancerIP = var.ip_address == null ? [] : [
{
Expand Down
12 changes: 9 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ resource "helm_release" "application" {
chart = local.helm_chart
namespace = var.namespace
repository = local.helm_repository
version = local.helm_template_version

wait = "false"
version = var.chart_version

values = [var.disable_heavyweight_metrics ? file("${path.module}/templates/metrics-disable.yaml") : ""]

set {
name = "controller.kind"
value = var.controller_kind
}
set {
name = "controller.ingressClassResource.name"
value = var.ingress_class_name
}
set {
name = "controller.ingressClassResource.default"
value = var.ingress_class_is_default
}
set {
name = "controller.daemonset.useHostPort"
value = var.controller_daemonset_useHostPort
Expand Down
3 changes: 3 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ output "name" {
}
output "namespace" {
value = var.namespace
}
output "ingress_class_name" {
value = var.ingress_class_name
}
20 changes: 19 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ variable "namespace" {
default = "kube-system"
}

variable "chart_version" {
type = string
description = "HELM Chart Version for nginx controller"
default = "4.0.6"
}

variable "ingress_class_name" {
type = string
description = "IngressClass resource name"
default = "nginx"
}

variable "ingress_class_is_default" {
type = bool
description = "IngressClass resource default for cluster"
default = true
}

variable "ip_address" {
type = string
description = "External Static Address for loadbalancer (Doesn't work with AWS)"
Expand Down Expand Up @@ -60,7 +78,7 @@ variable "service_nodePort_https" {

variable "metrics_enabled" {
type = bool
description = ""
description = "Allow exposing metrics for prometheus-operator"
default = false
}
variable "disable_heavyweight_metrics" {
Expand Down
7 changes: 7 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
terraform {
required_version = ">= 0.13.0"

required_providers {
helm = ">= 2.1.0"
}
}

0 comments on commit 0e261a8

Please sign in to comment.