Skip to content

Commit

Permalink
chore(setup): pass secret name as variable
Browse files Browse the repository at this point in the history
  • Loading branch information
swiatekm committed Jun 17, 2024
1 parent ca1bce7 commit b4bb089
Show file tree
Hide file tree
Showing 27 changed files with 169 additions and 58 deletions.
4 changes: 3 additions & 1 deletion deploy/helm/sumologic/conf/cleanup/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export HTTPS_PROXY="${HTTPS_PROXY:=""}"
export NO_PROXY="${NO_PROXY:=""}"

readonly SUMOLOGIC_COLLECTOR_NAME="${SUMOLOGIC_COLLECTOR_NAME:?}"
readonly SUMOLOGIC_SECRET_NAME="${SUMOLOGIC_SECRET_NAME:?}"
readonly NAMESPACE="${NAMESPACE:?}"

# Set variables for terraform
export TF_VAR_collector_name="${SUMOLOGIC_COLLECTOR_NAME}"
Expand All @@ -26,7 +28,7 @@ terraform init -input=false -get=false || terraform init -input=false -upgrade
# shellcheck disable=SC1083
terraform import sumologic_collector.collector "${SUMOLOGIC_COLLECTOR_NAME}"
# shellcheck disable=SC1083
terraform import kubernetes_secret.sumologic_collection_secret {{ template "terraform.secret.fullname" . }}
terraform import kubernetes_secret.sumologic_collection_secret "${NAMESPACE}/${SUMOLOGIC_SECRET_NAME}"

terraform destroy -auto-approve

Expand Down
2 changes: 1 addition & 1 deletion deploy/helm/sumologic/conf/setup/resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resource "sumologic_collector" "collector" {

resource "kubernetes_secret" "sumologic_collection_secret" {
metadata {
name = "{{ template "terraform.secret.name" }}"
name = var.secret_name
namespace = var.namespace_name
}

Expand Down
7 changes: 5 additions & 2 deletions deploy/helm/sumologic/conf/setup/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
readonly DEBUG_MODE=${DEBUG_MODE:="false"}
readonly DEBUG_MODE_ENABLED_FLAG="true"
readonly SUMOLOGIC_COLLECTOR_NAME="${SUMOLOGIC_COLLECTOR_NAME:?}"
readonly NAMESPACE="${NAMESPACE:?}"
readonly SUMOLOGIC_SECRET_NAME="${SUMOLOGIC_SECRET_NAME:?}"

# Set variables for terraform
export TF_VAR_collector_name="${SUMOLOGIC_COLLECTOR_NAME}"
export TF_VAR_namespace_name="${NAMESPACE}"
export TF_VAR_secret_name="${SUMOLOGIC_SECRET_NAME}"
export TF_VAR_chart_version="${CHART_VERSION:?}"
export TF_VAR_namespace_name="${NAMESPACE:?}"

# Let's compare the variables ignoring the case with help of ${VARIABLE,,} which makes the string lowercased
# so that we don't have to deal with True vs true vs TRUE
Expand Down Expand Up @@ -149,7 +152,7 @@ terraform import sumologic_http_source.{{ template "terraform.sources.name" (dic
fi

# Kubernetes Secret
terraform import kubernetes_secret.sumologic_collection_secret {{ template "terraform.secret.fullname" . }}
terraform import kubernetes_secret.sumologic_collection_secret "${NAMESPACE}/${SUMOLOGIC_SECRET_NAME}"

# Apply planned changes
TF_LOG_PROVIDER=DEBUG terraform apply \
Expand Down
4 changes: 4 additions & 0 deletions deploy/helm/sumologic/conf/setup/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ variable "namespace_name" {
type = string
}

variable "secret_name" {
type = string
}

variable "create_fields" {
description = "If set, Terraform will attempt to create fields at Sumo Logic"
type = bool
Expand Down
12 changes: 0 additions & 12 deletions deploy/helm/sumologic/templates/_helpers/_setup.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@ Example usage:
{{ printf "%s" "sumologic" }}
{{- end -}}

{{/*
Returns the name of Kubernetes secret prefixed with release namespace.
Example usage:
{{ include "terraform.secret.fullname" }}

*/}}
{{- define "terraform.secret.fullname" -}}
{{ template "sumologic.namespace" . }}/{{ template "terraform.secret.name" . }}
{{- end -}}

{{/*
Convert source name to Terraform metric name:
* converts all `-` to `_`
Expand Down
2 changes: 2 additions & 0 deletions deploy/helm/sumologic/templates/cleanup/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ spec:
value: {{ include "terraform.collector.name" . }}
- name: CHART_VERSION
value: "{{ .Chart.Version }}"
- name: SUMOLOGIC_SECRET_NAME
value: "{{ template "terraform.secret.name" }}"
{{- include "proxy-env-variables" . | nindent 10 }}
securityContext:
runAsUser: 999
Expand Down
2 changes: 2 additions & 0 deletions deploy/helm/sumologic/templates/setup/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ spec:
{{- end }}
- name: SUMOLOGIC_COLLECTOR_NAME
value: {{ include "terraform.collector.name" . }}
- name: SUMOLOGIC_SECRET_NAME
value: "{{ template "terraform.secret.name" }}"
- name: CHART_VERSION
value: "{{ .Chart.Version }}"
{{- include "proxy-env-variables" . | nindent 8 -}}
Expand Down
2 changes: 2 additions & 0 deletions tests/helm/testdata/goldenfile/cleanup/basic.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ spec:
value: kubernetes
- name: CHART_VERSION
value: "%CURRENT_CHART_VERSION%"
- name: SUMOLOGIC_SECRET_NAME
value: "sumologic"

- name: NO_PROXY
value: kubernetes.default.svc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ spec:
value: kubernetes
- name: CHART_VERSION
value: "%CURRENT_CHART_VERSION%"
- name: SUMOLOGIC_SECRET_NAME
value: "sumologic"

- name: NO_PROXY
value: kubernetes.default.svc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ spec:
value: kubernetes
- name: CHART_VERSION
value: "%CURRENT_CHART_VERSION%"
- name: SUMOLOGIC_SECRET_NAME
value: "sumologic"

- name: NO_PROXY
value: kubernetes.default.svc
Expand Down
2 changes: 2 additions & 0 deletions tests/helm/testdata/goldenfile/setup/basic.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ spec:
value:
- name: SUMOLOGIC_COLLECTOR_NAME
value: kubernetes
- name: SUMOLOGIC_SECRET_NAME
value: "sumologic"
- name: CHART_VERSION
value: "%CURRENT_CHART_VERSION%"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ spec:
value: http://RELEASE-NAME-sumologic-mock.sumologic.svc.cluster.local.:3000/terraform/api/
- name: SUMOLOGIC_COLLECTOR_NAME
value: kubernetes
- name: SUMOLOGIC_SECRET_NAME
value: "sumologic"
- name: CHART_VERSION
value: "%CURRENT_CHART_VERSION%"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ spec:
value: http://RELEASE-NAME-sumologic-mock.sumologic.svc.cluster.local.:3000/terraform/api/
- name: SUMOLOGIC_COLLECTOR_NAME
value: kubernetes
- name: SUMOLOGIC_SECRET_NAME
value: "sumologic"
- name: CHART_VERSION
value: "%CURRENT_CHART_VERSION%"

Expand Down
13 changes: 10 additions & 3 deletions tests/helm/testdata/goldenfile/terraform/all_fields.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ data:
resource "kubernetes_secret" "sumologic_collection_secret" {
metadata {
name = "sumologic"
name = var.secret_name
namespace = var.namespace_name
}
Expand All @@ -354,11 +354,14 @@ data:
readonly DEBUG_MODE=${DEBUG_MODE:="false"}
readonly DEBUG_MODE_ENABLED_FLAG="true"
readonly SUMOLOGIC_COLLECTOR_NAME="${SUMOLOGIC_COLLECTOR_NAME:?}"
readonly NAMESPACE="${NAMESPACE:?}"
readonly SUMOLOGIC_SECRET_NAME="${SUMOLOGIC_SECRET_NAME:?}"
# Set variables for terraform
export TF_VAR_collector_name="${SUMOLOGIC_COLLECTOR_NAME}"
export TF_VAR_namespace_name="${NAMESPACE}"
export TF_VAR_secret_name="${SUMOLOGIC_SECRET_NAME}"
export TF_VAR_chart_version="${CHART_VERSION:?}"
export TF_VAR_namespace_name="${NAMESPACE:?}"
# Let's compare the variables ignoring the case with help of ${VARIABLE,,} which makes the string lowercased
# so that we don't have to deal with True vs true vs TRUE
Expand Down Expand Up @@ -499,7 +502,7 @@ data:
fi
# Kubernetes Secret
terraform import kubernetes_secret.sumologic_collection_secret sumologic/sumologic
terraform import kubernetes_secret.sumologic_collection_secret "${NAMESPACE}/${SUMOLOGIC_SECRET_NAME}"
# Apply planned changes
TF_LOG_PROVIDER=DEBUG terraform apply \
Expand Down Expand Up @@ -839,6 +842,10 @@ data:
type = string
}
variable "secret_name" {
type = string
}
variable "create_fields" {
description = "If set, Terraform will attempt to create fields at Sumo Logic"
type = bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ data:
resource "kubernetes_secret" "sumologic_collection_secret" {
metadata {
name = "sumologic"
name = var.secret_name
namespace = var.namespace_name
}
Expand All @@ -354,11 +354,14 @@ data:
readonly DEBUG_MODE=${DEBUG_MODE:="false"}
readonly DEBUG_MODE_ENABLED_FLAG="true"
readonly SUMOLOGIC_COLLECTOR_NAME="${SUMOLOGIC_COLLECTOR_NAME:?}"
readonly NAMESPACE="${NAMESPACE:?}"
readonly SUMOLOGIC_SECRET_NAME="${SUMOLOGIC_SECRET_NAME:?}"
# Set variables for terraform
export TF_VAR_collector_name="${SUMOLOGIC_COLLECTOR_NAME}"
export TF_VAR_namespace_name="${NAMESPACE}"
export TF_VAR_secret_name="${SUMOLOGIC_SECRET_NAME}"
export TF_VAR_chart_version="${CHART_VERSION:?}"
export TF_VAR_namespace_name="${NAMESPACE:?}"
# Let's compare the variables ignoring the case with help of ${VARIABLE,,} which makes the string lowercased
# so that we don't have to deal with True vs true vs TRUE
Expand Down Expand Up @@ -498,7 +501,7 @@ data:
fi
# Kubernetes Secret
terraform import kubernetes_secret.sumologic_collection_secret sumologic/sumologic
terraform import kubernetes_secret.sumologic_collection_secret "${NAMESPACE}/${SUMOLOGIC_SECRET_NAME}"
# Apply planned changes
TF_LOG_PROVIDER=DEBUG terraform apply \
Expand Down Expand Up @@ -742,6 +745,10 @@ data:
type = string
}
variable "secret_name" {
type = string
}
variable "create_fields" {
description = "If set, Terraform will attempt to create fields at Sumo Logic"
type = bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ data:
resource "kubernetes_secret" "sumologic_collection_secret" {
metadata {
name = "sumologic"
name = var.secret_name
namespace = var.namespace_name
}
Expand All @@ -354,11 +354,14 @@ data:
readonly DEBUG_MODE=${DEBUG_MODE:="false"}
readonly DEBUG_MODE_ENABLED_FLAG="true"
readonly SUMOLOGIC_COLLECTOR_NAME="${SUMOLOGIC_COLLECTOR_NAME:?}"
readonly NAMESPACE="${NAMESPACE:?}"
readonly SUMOLOGIC_SECRET_NAME="${SUMOLOGIC_SECRET_NAME:?}"
# Set variables for terraform
export TF_VAR_collector_name="${SUMOLOGIC_COLLECTOR_NAME}"
export TF_VAR_namespace_name="${NAMESPACE}"
export TF_VAR_secret_name="${SUMOLOGIC_SECRET_NAME}"
export TF_VAR_chart_version="${CHART_VERSION:?}"
export TF_VAR_namespace_name="${NAMESPACE:?}"
# Let's compare the variables ignoring the case with help of ${VARIABLE,,} which makes the string lowercased
# so that we don't have to deal with True vs true vs TRUE
Expand Down Expand Up @@ -483,7 +486,7 @@ data:
fi
# Kubernetes Secret
terraform import kubernetes_secret.sumologic_collection_secret sumologic/sumologic
terraform import kubernetes_secret.sumologic_collection_secret "${NAMESPACE}/${SUMOLOGIC_SECRET_NAME}"
# Apply planned changes
TF_LOG_PROVIDER=DEBUG terraform apply \
Expand Down Expand Up @@ -538,6 +541,10 @@ data:
type = string
}
variable "secret_name" {
type = string
}
variable "create_fields" {
description = "If set, Terraform will attempt to create fields at Sumo Logic"
type = bool
Expand Down
13 changes: 10 additions & 3 deletions tests/helm/testdata/goldenfile/terraform/custom.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ data:
resource "kubernetes_secret" "sumologic_collection_secret" {
metadata {
name = "sumologic"
name = var.secret_name
namespace = var.namespace_name
}
Expand All @@ -354,11 +354,14 @@ data:
readonly DEBUG_MODE=${DEBUG_MODE:="false"}
readonly DEBUG_MODE_ENABLED_FLAG="true"
readonly SUMOLOGIC_COLLECTOR_NAME="${SUMOLOGIC_COLLECTOR_NAME:?}"
readonly NAMESPACE="${NAMESPACE:?}"
readonly SUMOLOGIC_SECRET_NAME="${SUMOLOGIC_SECRET_NAME:?}"
# Set variables for terraform
export TF_VAR_collector_name="${SUMOLOGIC_COLLECTOR_NAME}"
export TF_VAR_namespace_name="${NAMESPACE}"
export TF_VAR_secret_name="${SUMOLOGIC_SECRET_NAME}"
export TF_VAR_chart_version="${CHART_VERSION:?}"
export TF_VAR_namespace_name="${NAMESPACE:?}"
# Let's compare the variables ignoring the case with help of ${VARIABLE,,} which makes the string lowercased
# so that we don't have to deal with True vs true vs TRUE
Expand Down Expand Up @@ -483,7 +486,7 @@ data:
fi
# Kubernetes Secret
terraform import kubernetes_secret.sumologic_collection_secret sumologic/sumologic
terraform import kubernetes_secret.sumologic_collection_secret "${NAMESPACE}/${SUMOLOGIC_SECRET_NAME}"
# Apply planned changes
TF_LOG_PROVIDER=DEBUG terraform apply \
Expand Down Expand Up @@ -538,6 +541,10 @@ data:
type = string
}
variable "secret_name" {
type = string
}
variable "create_fields" {
description = "If set, Terraform will attempt to create fields at Sumo Logic"
type = bool
Expand Down
13 changes: 10 additions & 3 deletions tests/helm/testdata/goldenfile/terraform/default.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ data:
resource "kubernetes_secret" "sumologic_collection_secret" {
metadata {
name = "sumologic"
name = var.secret_name
namespace = var.namespace_name
}
Expand All @@ -354,11 +354,14 @@ data:
readonly DEBUG_MODE=${DEBUG_MODE:="false"}
readonly DEBUG_MODE_ENABLED_FLAG="true"
readonly SUMOLOGIC_COLLECTOR_NAME="${SUMOLOGIC_COLLECTOR_NAME:?}"
readonly NAMESPACE="${NAMESPACE:?}"
readonly SUMOLOGIC_SECRET_NAME="${SUMOLOGIC_SECRET_NAME:?}"
# Set variables for terraform
export TF_VAR_collector_name="${SUMOLOGIC_COLLECTOR_NAME}"
export TF_VAR_namespace_name="${NAMESPACE}"
export TF_VAR_secret_name="${SUMOLOGIC_SECRET_NAME}"
export TF_VAR_chart_version="${CHART_VERSION:?}"
export TF_VAR_namespace_name="${NAMESPACE:?}"
# Let's compare the variables ignoring the case with help of ${VARIABLE,,} which makes the string lowercased
# so that we don't have to deal with True vs true vs TRUE
Expand Down Expand Up @@ -498,7 +501,7 @@ data:
fi
# Kubernetes Secret
terraform import kubernetes_secret.sumologic_collection_secret sumologic/sumologic
terraform import kubernetes_secret.sumologic_collection_secret "${NAMESPACE}/${SUMOLOGIC_SECRET_NAME}"
# Apply planned changes
TF_LOG_PROVIDER=DEBUG terraform apply \
Expand Down Expand Up @@ -739,6 +742,10 @@ data:
type = string
}
variable "secret_name" {
type = string
}
variable "create_fields" {
description = "If set, Terraform will attempt to create fields at Sumo Logic"
type = bool
Expand Down
Loading

0 comments on commit b4bb089

Please sign in to comment.