Skip to content

Commit

Permalink
Create fields automatically in setup job
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek committed Nov 3, 2020
1 parent 5ad3ef0 commit d46d2e8
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 4 deletions.
47 changes: 47 additions & 0 deletions deploy/helm/sumologic/conf/setup/fields/fields.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
resource "sumologic_field" "cluster" {
field_name = "cluster"
data_type = "String"
state = "Enabled"
}

resource "sumologic_field" "container" {
field_name = "container"
data_type = "String"
state = "Enabled"
}

resource "sumologic_field" "deployment" {
field_name = "deployment"
data_type = "String"
state = "Enabled"
}

resource "sumologic_field" "host" {
field_name = "host"
data_type = "String"
state = "Enabled"
}

resource "sumologic_field" "namespace" {
field_name = "namespace"
data_type = "String"
state = "Enabled"
}

resource "sumologic_field" "node" {
field_name = "node"
data_type = "String"
state = "Enabled"
}

resource "sumologic_field" "pod" {
field_name = "pod"
data_type = "String"
state = "Enabled"
}

resource "sumologic_field" "service" {
field_name = "service"
data_type = "String"
state = "Enabled"
}
5 changes: 5 additions & 0 deletions deploy/helm/sumologic/conf/setup/fields/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
terraform {
required_providers {
sumologic = "~> 2.3.0"
}
}
29 changes: 26 additions & 3 deletions deploy/helm/sumologic/conf/setup/setup.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
#!/bin/bash
cp /etc/terraform/{locals,main,providers,resources,variables}.tf /terraform
cd /terraform

# Fix URL to remove "v1" or "v1/"
export SUMOLOGIC_BASE_URL=${SUMOLOGIC_BASE_URL%v1*}

# Support proxy for terraform
export HTTP_PROXY=${HTTP_PROXY:=""}
export HTTPS_PROXY=${HTTPS_PROXY:=""}
export NO_PROXY=${NO_PROXY:=""}

function remaining_fields() {
readonly RESPONSE="$(curl -XGET -s \
-u "${SUMOLOGIC_ACCESSID}:${SUMOLOGIC_ACCESSKEY}" \
"${SUMOLOGIC_BASE_URL}"v1/fields/quota)"

echo "${RESPONSE}" | jq '.remaining'
}

cp /etc/terraform/{locals,main,providers,resources,variables}.tf /terraform/
mkdir /terraform/fields/
cp /etc/terraform/fields/{main,fields}.tf /terraform/fields/
cd /terraform

COLLECTOR_NAME="{{- if .Values.sumologic.collectorName }}{{ .Values.sumologic.collectorName }}{{- else}}{{ .Values.sumologic.clusterName }}{{- end}}"

terraform init
Expand All @@ -32,6 +42,19 @@ terraform import kubernetes_secret.sumologic_collection_secret {{ .Release.Names

terraform apply -auto-approve

# Fields
#
# Check if we have at least 10 fields remaining after we would
# create 8 additional fields for the collection
readonly REMAINING=$(remaining_fields)
if [[ $(( REMAINING - 8 )) -ge -10 ]] ; then
echo "Creating fields..."
( cd fields && terraform destroy -auto-approve )
else
printf "Couldn't automatically create fields\n"
printf "There's only %s remaining and collection requires at least 8\n" "${REMAINING}"
fi

# Cleanup env variables
export SUMOLOGIC_BASE_URL=
export SUMOLOGIC_ACCESSKEY=
Expand Down
6 changes: 5 additions & 1 deletion deploy/helm/sumologic/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ Check the release status by running:

{{- if eq .Values.fluentd.persistence.enabled false }}
WARNING: File persistence for fluentd is disabled. This might lead to loss of data in case of memory buffer overflow. We recommend turning this property on for production environments by setting fluentd.persistence.enabled=true
{{- end }}
{{- end }}

We've tried to automatically create fields. In an unlikely scenario that this
fails please refer to the following to create them manually:
https://github.com/SumoLogic/sumologic-kubernetes-collection/blob/2b3ca63/deploy/docs/Installation_with_Helm.md#prerequisite

0 comments on commit d46d2e8

Please sign in to comment.