Skip to content

Commit

Permalink
Added create_namespace to make it possible to install prometheus into…
Browse files Browse the repository at this point in the history
… an existing namespace.
  • Loading branch information
zawac002 committed Sep 12, 2023
1 parent 10caacd commit 425bde9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
19 changes: 18 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@

resource "kubernetes_namespace" "ns" {
count = var.create_namespace == true ? 1 : 0

metadata {
name = var.namespace
labels = {
istio-injection = "enabled"
}
}
}

data "kubernetes_namespace" "existing-ns" {
count = var.create_namespace == true ? 0 : 1

metadata {
name = var.namespace
}
}

locals {
ns = try(kubernetes_namespace.ns[0].metadata[0].name, data.kubernetes_namespace.existing-ns[0].metadata[0].name)
}

resource "helm_release" "prometheus" {
chart = "prometheus"
name = "prometheus"
namespace = kubernetes_namespace.ns.metadata[0].name
namespace = local.ns
version = var.prometheus_chart_version
repository = "https://prometheus-community.github.io/helm-charts"

Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ variable "namespace" {
default = "prometheus"
}

variable "create_namespace" {
description = "Indicates whether the `namespace` needs to be created ('true') or already exists (not `true`)"
type = bool
default = true
}

# helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
# helm search repo prometheus-community/prometheus | head -2
variable "prometheus_chart_version" {
Expand Down

0 comments on commit 425bde9

Please sign in to comment.