diff --git a/LICENSE b/LICENSE index 0205a95..7d752b1 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 AIGIS +Copyright (c) 2021 AIGIS UK (Lotus Labs Ltd) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md new file mode 100644 index 0000000..87afbb8 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Terraform DigitalOcean Traefik Module +A Terraform module to provision Traefik (v2.x) on a Kubernetes cluster via the [helm terraform provider](https://registry.terraform.io/providers/hashicorp/helm/latest). \ No newline at end of file diff --git a/chart.tf b/chart.tf new file mode 100644 index 0000000..cb82661 --- /dev/null +++ b/chart.tf @@ -0,0 +1,21 @@ +# Install traefik helm_chart +resource "helm_release" "traefik" { + namespace = var.namespace + name = "traefik-v${replace(var.traefik_chart_version, ".", "-")}" + repository = "https://helm.traefik.io/traefik" + chart = "traefik" + version = var.traefik_chart_version + + # If default_values == "" then apply default values from the chart if its anything else + # then apply values file using the values_file input variable + values = [var.default_values == "" ? var.default_values : file("${path.root}/${var.values_file}")] + + set { + name = "deployment.replicas" + value = var.replica_count + } + + depends_on = [ + kubernetes_namespace.traefik_namespace + ] +} \ No newline at end of file diff --git a/namespace.tf b/namespace.tf new file mode 100644 index 0000000..e753942 --- /dev/null +++ b/namespace.tf @@ -0,0 +1,6 @@ +# Create traefik namespace +resource "kubernetes_namespace" "traefik_namespace" { + metadata { + name = var.namespace + } +} \ No newline at end of file diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..6f98381 --- /dev/null +++ b/variables.tf @@ -0,0 +1,29 @@ +variable "namespace" { + description = "Namespace to install traefik chart into" + type = string + default = "traefik" +} + +variable "traefik_chart_version" { + description = "Version of Traefik chart to install" + type = string + default = "10.7.1" # See https://artifacthub.io/packages/helm/traefik/traefik for latest version(s) +} + +variable "replica_count" { + description = "Number of replica pods to create" + type = number + default = 1 +} + +variable "default_values" { + description = "Specifies whether to use the traefik default values.yaml, or if set to anything else then to use your own custom values" + type = string + default = "" +} + +variable "values_file" { + description = "The name of the traefik helmchart values file to use" + type = string + default = "values.yaml" +} \ No newline at end of file diff --git a/versions.tf b/versions.tf new file mode 100644 index 0000000..d07d61e --- /dev/null +++ b/versions.tf @@ -0,0 +1,13 @@ +terraform { + required_providers { + kubernetes = { + source = "hashicorp/kubernetes" + version = ">= 2.0.0" + } + helm = { + source = "hashicorp/helm" + version = ">= 2.0.1" + } + } + required_version = ">= 0.15" +} \ No newline at end of file