diff --git a/deploy/helm/sumologic/conf/setup/providers.tf b/deploy/helm/sumologic/conf/setup/providers.tf deleted file mode 100644 index 0951a81b74..0000000000 --- a/deploy/helm/sumologic/conf/setup/providers.tf +++ /dev/null @@ -1,26 +0,0 @@ -provider "sumologic" {} - -provider "kubernetes" { -{{- $ctx := .Values -}} -{{ $printf_str := "%-25s" }} -{{ range $key, $value := .Values.sumologic.cluster }} - {{ if eq $key "exec" }} - exec { - command = "{{ $ctx.sumologic.cluster.exec.command }}" - {{ if hasKey $ctx.sumologic.cluster.exec "api_version" }}{{ printf $printf_str "api_version" }} = "{{ $ctx.sumologic.cluster.exec.api_version }}"{{ end }} - {{ if hasKey $ctx.sumologic.cluster.exec "args" }} - {{ printf $printf_str "args" }} = {{ toJson $ctx.sumologic.cluster.exec.args }} - {{- end -}} - {{ if hasKey $ctx.sumologic.cluster.exec "env" }} - {{ printf $printf_str "env" }} = { - {{ range $key_env, $value_env := $ctx.sumologic.cluster.exec.env }} - {{ printf $printf_str $key_env }} = {{ include "terraform.print_value" $value_env }} - {{- end }} - } - {{ end }} - } - {{- else -}} - {{ printf " %-25s" $key }} = {{ include "terraform.print_value" $value }} - {{- end }} -{{- end }} -} \ No newline at end of file diff --git a/deploy/helm/sumologic/conf/setup/providers.tf.json b/deploy/helm/sumologic/conf/setup/providers.tf.json new file mode 100644 index 0000000000..f1a16134e8 --- /dev/null +++ b/deploy/helm/sumologic/conf/setup/providers.tf.json @@ -0,0 +1,5 @@ +{{- $kubernetesProvider := deepCopy .Values.sumologic.cluster -}} +{{- $sumoProvider := dict -}} +{{- $providers := dict "sumologic" $sumoProvider "kubernetes" $kubernetesProvider -}} +{{- $terraformData := dict "provider" $providers -}} +{{- toPrettyJson $terraformData | nindent 2 }} diff --git a/deploy/helm/sumologic/templates/_helpers/_setup.tpl b/deploy/helm/sumologic/templates/_helpers/_setup.tpl index 375f3e08bb..715581d7ee 100644 --- a/deploy/helm/sumologic/templates/_helpers/_setup.tpl +++ b/deploy/helm/sumologic/templates/_helpers/_setup.tpl @@ -147,29 +147,6 @@ Example usage: {{ $endpoint }} {{- end -}} -{{/* -Add or skip quotation denending on the value - -Examples: - - "${test}" will be printed as `test` - - "test" will be printed as `"test"` - -Example Usage: -{{ include "terraform.sources.config-map-variable" "${file(\"/var/test\")}" }} - -*/}} -{{- define "terraform.print_value" -}} -{{- if and (kindIs "string" .) -}} -{{- if (regexMatch "^\\$\\{[^\\$]*\\}$" .) -}} -{{ regexReplaceAll "^\\$\\{(.*)\\}$" . "${1}" }} -{{- else -}} -{{ printf "\"%s\"" . }} -{{- end -}} -{{- else -}} -{{ printf "\"%s\"" (toString .) }} -{{- end -}} -{{- end -}} - {{/* Check if component (source/events/logs/traces etc.) is enabled or not diff --git a/tests/helm/testdata/goldenfile/terraform/all_fields.output.yaml b/tests/helm/testdata/goldenfile/terraform/all_fields.output.yaml index 3160238d22..80265849b8 100644 --- a/tests/helm/testdata/goldenfile/terraform/all_fields.output.yaml +++ b/tests/helm/testdata/goldenfile/terraform/all_fields.output.yaml @@ -435,14 +435,16 @@ data: echo "You can (re)install them manually with:" echo "https://github.com/SumoLogic/terraform-sumologic-sumo-logic-monitor/tree/main/monitor_packages/kubernetes" fi - providers.tf: |- - provider "sumologic" {} - - provider "kubernetes" { - - cluster_ca_certificate = file("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt") - host = "https://kubernetes.default.svc" - token = file("/var/run/secrets/kubernetes.io/serviceaccount/token") + providers.tf.json: | + { + "provider": { + "kubernetes": { + "cluster_ca_certificate": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/ca.crt\")}", + "host": "https://kubernetes.default.svc", + "token": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/token\")}" + }, + "sumologic": {} + } } resources.tf: | resource "sumologic_collector" "collector" { diff --git a/tests/helm/testdata/goldenfile/terraform/collector_fields.output.yaml b/tests/helm/testdata/goldenfile/terraform/collector_fields.output.yaml index 0afa4b8bfe..df72e47bad 100644 --- a/tests/helm/testdata/goldenfile/terraform/collector_fields.output.yaml +++ b/tests/helm/testdata/goldenfile/terraform/collector_fields.output.yaml @@ -435,14 +435,16 @@ data: echo "You can (re)install them manually with:" echo "https://github.com/SumoLogic/terraform-sumologic-sumo-logic-monitor/tree/main/monitor_packages/kubernetes" fi - providers.tf: |- - provider "sumologic" {} - - provider "kubernetes" { - - cluster_ca_certificate = file("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt") - host = "https://kubernetes.default.svc" - token = file("/var/run/secrets/kubernetes.io/serviceaccount/token") + providers.tf.json: | + { + "provider": { + "kubernetes": { + "cluster_ca_certificate": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/ca.crt\")}", + "host": "https://kubernetes.default.svc", + "token": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/token\")}" + }, + "sumologic": {} + } } resources.tf: | resource "sumologic_collector" "collector" { diff --git a/tests/helm/testdata/goldenfile/terraform/conditional_sources.output.yaml b/tests/helm/testdata/goldenfile/terraform/conditional_sources.output.yaml index 902f40ebbe..4217730caa 100644 --- a/tests/helm/testdata/goldenfile/terraform/conditional_sources.output.yaml +++ b/tests/helm/testdata/goldenfile/terraform/conditional_sources.output.yaml @@ -435,14 +435,16 @@ data: echo "You can (re)install them manually with:" echo "https://github.com/SumoLogic/terraform-sumologic-sumo-logic-monitor/tree/main/monitor_packages/kubernetes" fi - providers.tf: |- - provider "sumologic" {} - - provider "kubernetes" { - - cluster_ca_certificate = file("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt") - host = "https://kubernetes.default.svc" - token = file("/var/run/secrets/kubernetes.io/serviceaccount/token") + providers.tf.json: | + { + "provider": { + "kubernetes": { + "cluster_ca_certificate": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/ca.crt\")}", + "host": "https://kubernetes.default.svc", + "token": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/token\")}" + }, + "sumologic": {} + } } resources.tf: | resource "sumologic_collector" "collector" { diff --git a/tests/helm/testdata/goldenfile/terraform/custom.output.yaml b/tests/helm/testdata/goldenfile/terraform/custom.output.yaml index 902f40ebbe..4217730caa 100644 --- a/tests/helm/testdata/goldenfile/terraform/custom.output.yaml +++ b/tests/helm/testdata/goldenfile/terraform/custom.output.yaml @@ -435,14 +435,16 @@ data: echo "You can (re)install them manually with:" echo "https://github.com/SumoLogic/terraform-sumologic-sumo-logic-monitor/tree/main/monitor_packages/kubernetes" fi - providers.tf: |- - provider "sumologic" {} - - provider "kubernetes" { - - cluster_ca_certificate = file("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt") - host = "https://kubernetes.default.svc" - token = file("/var/run/secrets/kubernetes.io/serviceaccount/token") + providers.tf.json: | + { + "provider": { + "kubernetes": { + "cluster_ca_certificate": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/ca.crt\")}", + "host": "https://kubernetes.default.svc", + "token": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/token\")}" + }, + "sumologic": {} + } } resources.tf: | resource "sumologic_collector" "collector" { diff --git a/tests/helm/testdata/goldenfile/terraform/default.output.yaml b/tests/helm/testdata/goldenfile/terraform/default.output.yaml index b56c258e6d..14e3167e29 100644 --- a/tests/helm/testdata/goldenfile/terraform/default.output.yaml +++ b/tests/helm/testdata/goldenfile/terraform/default.output.yaml @@ -435,14 +435,16 @@ data: echo "You can (re)install them manually with:" echo "https://github.com/SumoLogic/terraform-sumologic-sumo-logic-monitor/tree/main/monitor_packages/kubernetes" fi - providers.tf: |- - provider "sumologic" {} - - provider "kubernetes" { - - cluster_ca_certificate = file("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt") - host = "https://kubernetes.default.svc" - token = file("/var/run/secrets/kubernetes.io/serviceaccount/token") + providers.tf.json: | + { + "provider": { + "kubernetes": { + "cluster_ca_certificate": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/ca.crt\")}", + "host": "https://kubernetes.default.svc", + "token": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/token\")}" + }, + "sumologic": {} + } } resources.tf: | resource "sumologic_collector" "collector" { diff --git a/tests/helm/testdata/goldenfile/terraform/disable_default_metrics.output.yaml b/tests/helm/testdata/goldenfile/terraform/disable_default_metrics.output.yaml index d66de13a65..82d18af7ee 100644 --- a/tests/helm/testdata/goldenfile/terraform/disable_default_metrics.output.yaml +++ b/tests/helm/testdata/goldenfile/terraform/disable_default_metrics.output.yaml @@ -435,14 +435,16 @@ data: echo "You can (re)install them manually with:" echo "https://github.com/SumoLogic/terraform-sumologic-sumo-logic-monitor/tree/main/monitor_packages/kubernetes" fi - providers.tf: |- - provider "sumologic" {} - - provider "kubernetes" { - - cluster_ca_certificate = file("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt") - host = "https://kubernetes.default.svc" - token = file("/var/run/secrets/kubernetes.io/serviceaccount/token") + providers.tf.json: | + { + "provider": { + "kubernetes": { + "cluster_ca_certificate": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/ca.crt\")}", + "host": "https://kubernetes.default.svc", + "token": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/token\")}" + }, + "sumologic": {} + } } resources.tf: | resource "sumologic_collector" "collector" { diff --git a/tests/helm/testdata/goldenfile/terraform/disabled_dashboards.output.yaml b/tests/helm/testdata/goldenfile/terraform/disabled_dashboards.output.yaml index a1d46ab9b5..91ab53bb4a 100644 --- a/tests/helm/testdata/goldenfile/terraform/disabled_dashboards.output.yaml +++ b/tests/helm/testdata/goldenfile/terraform/disabled_dashboards.output.yaml @@ -435,14 +435,16 @@ data: echo "You can (re)install them manually with:" echo "https://github.com/SumoLogic/terraform-sumologic-sumo-logic-monitor/tree/main/monitor_packages/kubernetes" fi - providers.tf: |- - provider "sumologic" {} - - provider "kubernetes" { - - cluster_ca_certificate = file("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt") - host = "https://kubernetes.default.svc" - token = file("/var/run/secrets/kubernetes.io/serviceaccount/token") + providers.tf.json: | + { + "provider": { + "kubernetes": { + "cluster_ca_certificate": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/ca.crt\")}", + "host": "https://kubernetes.default.svc", + "token": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/token\")}" + }, + "sumologic": {} + } } resources.tf: | resource "sumologic_collector" "collector" { diff --git a/tests/helm/testdata/goldenfile/terraform/disabled_monitors.output.yaml b/tests/helm/testdata/goldenfile/terraform/disabled_monitors.output.yaml index b9cdd00a2e..f1a19d8376 100644 --- a/tests/helm/testdata/goldenfile/terraform/disabled_monitors.output.yaml +++ b/tests/helm/testdata/goldenfile/terraform/disabled_monitors.output.yaml @@ -435,14 +435,16 @@ data: echo "You can (re)install them manually with:" echo "https://github.com/SumoLogic/terraform-sumologic-sumo-logic-monitor/tree/main/monitor_packages/kubernetes" fi - providers.tf: |- - provider "sumologic" {} - - provider "kubernetes" { - - cluster_ca_certificate = file("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt") - host = "https://kubernetes.default.svc" - token = file("/var/run/secrets/kubernetes.io/serviceaccount/token") + providers.tf.json: | + { + "provider": { + "kubernetes": { + "cluster_ca_certificate": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/ca.crt\")}", + "host": "https://kubernetes.default.svc", + "token": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/token\")}" + }, + "sumologic": {} + } } resources.tf: | resource "sumologic_collector" "collector" { diff --git a/tests/helm/testdata/goldenfile/terraform/logs_fields.output.yaml b/tests/helm/testdata/goldenfile/terraform/logs_fields.output.yaml index 88a8d32cb8..e08ccfdc5d 100644 --- a/tests/helm/testdata/goldenfile/terraform/logs_fields.output.yaml +++ b/tests/helm/testdata/goldenfile/terraform/logs_fields.output.yaml @@ -461,14 +461,16 @@ data: echo "You can (re)install them manually with:" echo "https://github.com/SumoLogic/terraform-sumologic-sumo-logic-monitor/tree/main/monitor_packages/kubernetes" fi - providers.tf: |- - provider "sumologic" {} - - provider "kubernetes" { - - cluster_ca_certificate = file("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt") - host = "https://kubernetes.default.svc" - token = file("/var/run/secrets/kubernetes.io/serviceaccount/token") + providers.tf.json: | + { + "provider": { + "kubernetes": { + "cluster_ca_certificate": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/ca.crt\")}", + "host": "https://kubernetes.default.svc", + "token": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/token\")}" + }, + "sumologic": {} + } } resources.tf: | resource "sumologic_collector" "collector" { diff --git a/tests/helm/testdata/goldenfile/terraform/monitors_with_email_notifications.output.yaml b/tests/helm/testdata/goldenfile/terraform/monitors_with_email_notifications.output.yaml index b8e30c4f95..3731f2e0e1 100644 --- a/tests/helm/testdata/goldenfile/terraform/monitors_with_email_notifications.output.yaml +++ b/tests/helm/testdata/goldenfile/terraform/monitors_with_email_notifications.output.yaml @@ -441,14 +441,16 @@ data: echo "You can (re)install them manually with:" echo "https://github.com/SumoLogic/terraform-sumologic-sumo-logic-monitor/tree/main/monitor_packages/kubernetes" fi - providers.tf: |- - provider "sumologic" {} - - provider "kubernetes" { - - cluster_ca_certificate = file("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt") - host = "https://kubernetes.default.svc" - token = file("/var/run/secrets/kubernetes.io/serviceaccount/token") + providers.tf.json: | + { + "provider": { + "kubernetes": { + "cluster_ca_certificate": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/ca.crt\")}", + "host": "https://kubernetes.default.svc", + "token": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/token\")}" + }, + "sumologic": {} + } } resources.tf: | resource "sumologic_collector" "collector" { diff --git a/tests/helm/testdata/goldenfile/terraform/monitors_with_single_email.output.yaml b/tests/helm/testdata/goldenfile/terraform/monitors_with_single_email.output.yaml index 67326d5aa5..c7e929c7ae 100644 --- a/tests/helm/testdata/goldenfile/terraform/monitors_with_single_email.output.yaml +++ b/tests/helm/testdata/goldenfile/terraform/monitors_with_single_email.output.yaml @@ -441,14 +441,16 @@ data: echo "You can (re)install them manually with:" echo "https://github.com/SumoLogic/terraform-sumologic-sumo-logic-monitor/tree/main/monitor_packages/kubernetes" fi - providers.tf: |- - provider "sumologic" {} - - provider "kubernetes" { - - cluster_ca_certificate = file("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt") - host = "https://kubernetes.default.svc" - token = file("/var/run/secrets/kubernetes.io/serviceaccount/token") + providers.tf.json: | + { + "provider": { + "kubernetes": { + "cluster_ca_certificate": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/ca.crt\")}", + "host": "https://kubernetes.default.svc", + "token": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/token\")}" + }, + "sumologic": {} + } } resources.tf: | resource "sumologic_collector" "collector" { diff --git a/tests/helm/testdata/goldenfile/terraform/strip_extrapolation.output.yaml b/tests/helm/testdata/goldenfile/terraform/strip_extrapolation.output.yaml index 6a7f502658..3da55332f3 100644 --- a/tests/helm/testdata/goldenfile/terraform/strip_extrapolation.output.yaml +++ b/tests/helm/testdata/goldenfile/terraform/strip_extrapolation.output.yaml @@ -435,15 +435,17 @@ data: echo "You can (re)install them manually with:" echo "https://github.com/SumoLogic/terraform-sumologic-sumo-logic-monitor/tree/main/monitor_packages/kubernetes" fi - providers.tf: |- - provider "sumologic" {} - - provider "kubernetes" { - - cluster_ca_certificate = file("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt") - extrapolation = "${file("/var/run/secrets/kubernetes.io/serviceaccount/token")}/${test}" - host = "https://kubernetes.default.svc" - token = file("/var/run/secrets/kubernetes.io/serviceaccount/token") + providers.tf.json: | + { + "provider": { + "kubernetes": { + "cluster_ca_certificate": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/ca.crt\")}", + "extrapolation": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/token\")}/${test}", + "host": "https://kubernetes.default.svc", + "token": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/token\")}" + }, + "sumologic": {} + } } resources.tf: | resource "sumologic_collector" "collector" { diff --git a/tests/helm/testdata/goldenfile/terraform/traces.output.yaml b/tests/helm/testdata/goldenfile/terraform/traces.output.yaml index d225640dfb..62cb032f66 100644 --- a/tests/helm/testdata/goldenfile/terraform/traces.output.yaml +++ b/tests/helm/testdata/goldenfile/terraform/traces.output.yaml @@ -435,14 +435,16 @@ data: echo "You can (re)install them manually with:" echo "https://github.com/SumoLogic/terraform-sumologic-sumo-logic-monitor/tree/main/monitor_packages/kubernetes" fi - providers.tf: |- - provider "sumologic" {} - - provider "kubernetes" { - - cluster_ca_certificate = file("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt") - host = "https://kubernetes.default.svc" - token = file("/var/run/secrets/kubernetes.io/serviceaccount/token") + providers.tf.json: | + { + "provider": { + "kubernetes": { + "cluster_ca_certificate": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/ca.crt\")}", + "host": "https://kubernetes.default.svc", + "token": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/token\")}" + }, + "sumologic": {} + } } resources.tf: | resource "sumologic_collector" "collector" { diff --git a/tests/helm/testdata/goldenfile/terraform/tracing-metrics-disabled.output.yaml b/tests/helm/testdata/goldenfile/terraform/tracing-metrics-disabled.output.yaml index b56c258e6d..14e3167e29 100644 --- a/tests/helm/testdata/goldenfile/terraform/tracing-metrics-disabled.output.yaml +++ b/tests/helm/testdata/goldenfile/terraform/tracing-metrics-disabled.output.yaml @@ -435,14 +435,16 @@ data: echo "You can (re)install them manually with:" echo "https://github.com/SumoLogic/terraform-sumologic-sumo-logic-monitor/tree/main/monitor_packages/kubernetes" fi - providers.tf: |- - provider "sumologic" {} - - provider "kubernetes" { - - cluster_ca_certificate = file("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt") - host = "https://kubernetes.default.svc" - token = file("/var/run/secrets/kubernetes.io/serviceaccount/token") + providers.tf.json: | + { + "provider": { + "kubernetes": { + "cluster_ca_certificate": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/ca.crt\")}", + "host": "https://kubernetes.default.svc", + "token": "${file(\"/var/run/secrets/kubernetes.io/serviceaccount/token\")}" + }, + "sumologic": {} + } } resources.tf: | resource "sumologic_collector" "collector" {