Skip to content

Commit

Permalink
fix(helm): always create default metrics source if traces are enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek committed Mar 14, 2022
1 parent 6c94c5e commit f098cd2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 18 deletions.
21 changes: 15 additions & 6 deletions deploy/helm/sumologic/conf/setup/locals.tf
Original file line number Diff line number Diff line change
@@ -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 }}
}
42 changes: 30 additions & 12 deletions deploy/helm/sumologic/conf/setup/resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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 }}
}

Expand Down
7 changes: 7 additions & 0 deletions tests/helm/terraform/static/traces.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ data:
}
locals.tf: |
locals {
default_metrics_source = "(default-metrics)"
default_traces_source = "traces"
}
main.tf: |
Expand Down Expand Up @@ -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
Expand All @@ -166,6 +172,7 @@ data:
}
data = {
endpoint-metrics = sumologic_http_source.default_metrics_source.url
endpoint-traces = sumologic_http_source.default_traces_source.url
}
Expand Down

0 comments on commit f098cd2

Please sign in to comment.