From f098cd287775bd609fdf6c5de0cefec0cd2cdcea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Mon, 14 Mar 2022 18:36:16 +0100 Subject: [PATCH] fix(helm): always create default metrics source if traces are enabled --- deploy/helm/sumologic/conf/setup/locals.tf | 21 +++++++--- deploy/helm/sumologic/conf/setup/resources.tf | 42 +++++++++++++------ .../helm/terraform/static/traces.output.yaml | 7 ++++ 3 files changed, 52 insertions(+), 18 deletions(-) diff --git a/deploy/helm/sumologic/conf/setup/locals.tf b/deploy/helm/sumologic/conf/setup/locals.tf index bdeea24b3c..31cd99ef50 100644 --- a/deploy/helm/sumologic/conf/setup/locals.tf +++ b/deploy/helm/sumologic/conf/setup/locals.tf @@ -1,12 +1,21 @@ locals { {{- $ctx := .Values }} {{- range $type, $sources := .Values.sumologic.collector.sources }} -{{- if eq (include "terraform.sources.component_enabled" (dict "Context" $ctx "Type" $type)) "true" }} -{{- range $key, $source := $sources }} -{{- if eq (include "terraform.sources.to_create" (dict "Context" $ctx "Type" $type "Name" $key)) "true" }} + {{- if eq (include "terraform.sources.component_enabled" (dict "Context" $ctx "Type" $type)) "true" }} + {{- range $key, $source := $sources }} + {{- if eq (include "terraform.sources.to_create" (dict "Context" $ctx "Type" $type "Name" $key)) "true" }} {{ template "terraform.sources.local" (dict "Name" (include "terraform.sources.name" (dict "Name" $key "Type" $type)) "Value" $source.name) }} -{{- end }} -{{- end }} -{{- end }} + {{- end }} + {{- end }} + {{- else if and (eq $type "metrics") $ctx.sumologic.traces.enabled }} + {{- /* + If traces are enabled and metrics are disabled, create default metrics source anyway + */}} + {{- range $key, $source := $sources }} + {{- if eq $key "default" }} + {{ template "terraform.sources.local" (dict "Name" (include "terraform.sources.name" (dict "Name" $key "Type" $type)) "Value" $source.name) }} + {{- end }} + {{- end }} + {{- end }} {{- end }} } diff --git a/deploy/helm/sumologic/conf/setup/resources.tf b/deploy/helm/sumologic/conf/setup/resources.tf index 495357f3aa..1b25bb7e50 100644 --- a/deploy/helm/sumologic/conf/setup/resources.tf +++ b/deploy/helm/sumologic/conf/setup/resources.tf @@ -11,13 +11,22 @@ resource "sumologic_collector" "collector" { {{- $ctx := .Values }} {{- range $type, $sources := .Values.sumologic.collector.sources }} -{{- if eq (include "terraform.sources.component_enabled" (dict "Context" $ctx "Type" $type)) "true" }} -{{- range $key, $source := $sources }} -{{- if eq (include "terraform.sources.to_create" (dict "Context" $ctx "Type" $type "Name" $key)) "true" }} + {{- if eq (include "terraform.sources.component_enabled" (dict "Context" $ctx "Type" $type)) "true" }} + {{- range $key, $source := $sources }} + {{- if eq (include "terraform.sources.to_create" (dict "Context" $ctx "Type" $type "Name" $key)) "true" }} {{ include "terraform.sources.resource" (dict "Name" (include "terraform.sources.name" (dict "Name" $key "Type" $type)) "Source" $source "Context" $ctx) | nindent 2 }} -{{- end }} -{{- end }} -{{- end }} + {{- end }} + {{- end }} + {{- else if and (eq $type "metrics") $ctx.sumologic.traces.enabled }} + {{- /* + If traces are enabled and metrics are disabled, create default metrics source anyway + */}} + {{- range $key, $source := $sources }} + {{- if eq $key "default"}} +{{ include "terraform.sources.resource" (dict "Name" (include "terraform.sources.name" (dict "Name" $key "Type" $type)) "Source" $source "Context" $ctx) | nindent 2 }} + {{- end }} + {{- end }} + {{- end }} {{- end }} resource "kubernetes_secret" "sumologic_collection_secret" { @@ -29,13 +38,22 @@ resource "kubernetes_secret" "sumologic_collection_secret" { data = { {{- $ctx := .Values }} {{- range $type, $sources := .Values.sumologic.collector.sources }} - {{- if eq (include "terraform.sources.component_enabled" (dict "Context" $ctx "Type" $type)) "true" }} - {{- range $key, $source := $sources }} - {{- if eq (include "terraform.sources.to_create" (dict "Context" $ctx "Type" $type "Name" $key)) "true" }} + {{- if eq (include "terraform.sources.component_enabled" (dict "Context" $ctx "Type" $type)) "true" }} + {{- range $key, $source := $sources }} + {{- if eq (include "terraform.sources.to_create" (dict "Context" $ctx "Type" $type "Name" $key)) "true" }} {{ include "terraform.sources.data" (dict "Endpoint" (include "terraform.sources.config-map-variable" (dict "Type" $type "Context" $ctx "Name" $key)) "Name" (include "terraform.sources.name" (dict "Name" $key "Type" $type))) }} - {{- end }} - {{- end }} - {{- end }} + {{- end }} + {{- end }} + {{- else if and (eq $type "metrics") $ctx.sumologic.traces.enabled }} + {{- /* + If traces are enabled and metrics are disabled, create default metrics source anyway + */}} + {{- range $key, $source := $sources }} + {{- if eq $key "default"}} + {{ include "terraform.sources.data" (dict "Endpoint" (include "terraform.sources.config-map-variable" (dict "Type" $type "Context" $ctx "Name" $key)) "Name" (include "terraform.sources.name" (dict "Name" $key "Type" $type))) }} + {{- end }} + {{- end }} + {{- end }} {{- end }} } diff --git a/tests/helm/terraform/static/traces.output.yaml b/tests/helm/terraform/static/traces.output.yaml index aed8adbfc0..c478946762 100644 --- a/tests/helm/terraform/static/traces.output.yaml +++ b/tests/helm/terraform/static/traces.output.yaml @@ -120,6 +120,7 @@ data: } locals.tf: | locals { + default_metrics_source = "(default-metrics)" default_traces_source = "traces" } main.tf: | @@ -153,6 +154,11 @@ data: } } + resource "sumologic_http_source" "default_metrics_source" { + name = local.default_metrics_source + collector_id = sumologic_collector.collector.id + } + resource "sumologic_http_source" "default_traces_source" { name = local.default_traces_source collector_id = sumologic_collector.collector.id @@ -166,6 +172,7 @@ data: } data = { + endpoint-metrics = sumologic_http_source.default_metrics_source.url endpoint-traces = sumologic_http_source.default_traces_source.url }