Skip to content

Tensho/terraform-kubernetes-gateway

Repository files navigation

Kubernetes Gateway Terraform Module

Terraform module to manage Kubernetes Gateway resource (GKE batteries included).

Usage

module "example" {
  source  = "Tensho/gateway/kubernetes"
  version = "0.4.1"

  name       = "example"
  namespace  = "gateway-system"
  class_name = "gke-l7-global-external-managed"
  
  addresses = [
    {
      type  = "NamedAddress"
      value = "example-ingress-static-ip"
    }
  ]
  
  annotations = {
    "networking.gke.io/certmap" = "example"
  }
  
  listeners = [
    {
      name     = "http"
      protocol = "HTTP"
      port     = 80
    },
    {
      name     = "https"
      protocol = "HTTPS"
      port     = 443
    }
  ]
  
  ssl_policy = "example"
  
  http_to_https_redirect = true
}

Requirements

Name Version
terraform >= 1.7.0
kubernetes >= 2.0

Providers

Name Version
kubernetes 2.36.0

Modules

No modules.

Resources

Name Type
kubernetes_manifest.default resource
kubernetes_manifest.gcp_gateway_policy resource
kubernetes_manifest.redirect_http_to_https_route resource

Inputs

Name Description Type Default Required
addresses List of addresses for the Gateway. Supports type: IPAddress, NamedAddress, Hostname.
list(object({
type = string
value = string
}))
null no
annotations Gateway annotations map(string) {} no
class_name Gateway class name string n/a yes
http_to_https_redirect Redirect HTTP traffic from an infrastructure namespace string false no
listeners Gateway listeners any n/a yes
name Gateway name string "main" no
namespace Kubernetes namespace string "default" no
ssl_policy GKE GCPGatewayPolicy SSL policy name string null no

Outputs

Name Description
kubernetes_gateway Kubernetes Gateway resource

Contributing

This project uses conventional commits.

Prerequisites

Tools Installation

Consider all necessary tools installation via mise:

mise install

Pre-Commit Hooks Installation

pre-commit install

Provider Authentication

Note

The current test setup targets GCP/GKE. You need GKE cluster to run the tests.

Consider environment variables management for Terraform provider authentication via .env file, which mise picks up automatically:

GOOGLE_PROJECT=terraform-test
GOOGLE_REGION=europe-west2
KUBE_CONFIG_PATHS=~/.kube/config
Google Cloud Platform
gcloud auth application-default login
export GOOGLE_PROJECT=terraform-test
export GOOGLE_REGION=europe-west2
Kubernetes
gcloud container clusters get-credentials playground --region europe-west2 --project terraform-test
export KUBE_CONFIG_PATHS=~/.kube/config

Development & Testing

The terraform test command looks for *.tftest.hcl files in both root directory and tests directory.

terraform init
terraform test # run all tests
terraform test -filter test/gke.tftest.hcl -verbose # run specific test

About

Terraform module to manage Kubernetes Gateway resources

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages