Skip to content

Commit

Permalink
Bundle terraform providers in kubernetes-fluentd image (#1145)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek-sumo committed Nov 23, 2020
1 parent 689e6aa commit 531479d
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 30 deletions.
2 changes: 2 additions & 0 deletions ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,13 @@ function build_docker_image() {

echo "Building docker image with ${tag}:local in $(pwd)..."
pushd ./deploy/docker || exit 1
cp ../helm/sumologic/conf/setup/main.tf . || exit 1
no_cache="--no-cache"
if [[ "${DOCKER_USE_CACHE}" == "true" ]]; then
no_cache=""
fi
docker build . -f ./Dockerfile -t "${tag}:local" ${no_cache:+"--no-cache"}
rm main.tf
rm -f ./gems/*.gem
popd || exit 1

Expand Down
17 changes: 12 additions & 5 deletions deploy/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,19 @@ RUN gem install \
fluent-plugin-rewrite-tag-filter:2.2.0 \
fluent-plugin-prometheus:1.6.1

# Install Terraform
ENV TERRAFORM_VERSION 0.12.26
# Install Terraform ...
ENV TERRAFORM_VERSION 0.12.29
RUN mkdir /tmp/terraform \
&& curl https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip -o /tmp/terraform/terraform.zip \
&& cd /tmp/terraform \
&& unzip terraform.zip \
&& mv terraform /bin/terraform \
&& chmod +x /bin/terraform \
&& rm -rf /tmp/terraform
&& chmod +x /bin/terraform

# ... and providers
COPY main.tf /tmp/terraform
RUN cd /tmp/terraform \
&& terraform init

# FluentD plugins from this repository
COPY gems/fluent-plugin*.gem ./
Expand All @@ -74,7 +78,7 @@ RUN apt-get update \

# Create directory for Terraform configuration
RUN mkdir -p /terraform /scripts \
&& chown -R fluent /terraform /scripts
&& chown -R fluent:fluent /terraform /scripts

COPY --from=builder /bin/terraform /bin/terraform
COPY --from=builder /usr/local/bundle /usr/local/bundle
Expand All @@ -85,3 +89,6 @@ COPY ./entrypoint.sh /bin/
RUN chown fluent /usr/local/bundle/*

USER fluent

COPY --from=builder --chown=fluent:fluent \
/tmp/terraform/.terraform /terraform/.terraform
3 changes: 2 additions & 1 deletion deploy/helm/sumologic/conf/cleanup/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export HTTP_PROXY=${HTTP_PROXY:=""}
export HTTPS_PROXY=${HTTPS_PROXY:=""}
export NO_PROXY=${NO_PROXY:=""}

cd /cleanup/ || exit 1
cp /etc/terraform/*.tf /terraform/
cd /terraform || exit 1

terraform init

Expand Down
2 changes: 1 addition & 1 deletion deploy/helm/sumologic/conf/setup/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
terraform {
required_providers {
sumologic = "~> 2.4.0"
sumologic = "~> 2.4"
kubernetes = "~> 1.13.0"
}
}
2 changes: 1 addition & 1 deletion deploy/helm/sumologic/conf/setup/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function should_create_fields() {
}

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

terraform init

Expand Down
12 changes: 6 additions & 6 deletions deploy/helm/sumologic/templates/cleanup/cleanup-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ spec:
initContainers:
- name: copy-files
image: busybox
command: ['sh', '-c', 'cp /configmap/* /cleanup']
command: ['sh', '-c', 'cp /configmap/* /etc/terraform']
volumeMounts:
- name: configmap
mountPath: /configmap
- name: cleanup
mountPath: /cleanup
mountPath: /etc/terraform
containers:
- name: cleanup
image: "hashicorp/terraform:0.12.29"
imagePullPolicy: IfNotPresent
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
volumeMounts:
- name: cleanup
mountPath: /cleanup
command: ["/cleanup/cleanup.sh"]
mountPath: /etc/terraform
command: ["/etc/terraform/cleanup.sh"]
{{- if .Values.sumologic.envFromSecret }}
envFrom:
- secretRef:
Expand Down
4 changes: 2 additions & 2 deletions tests/terraform/static/all_fields.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ data:
main.tf: |
terraform {
required_providers {
sumologic = "~> 2.4.0"
sumologic = "~> 2.4"
kubernetes = "~> 1.13.0"
}
}
Expand Down Expand Up @@ -299,7 +299,7 @@ data:
}
cp /etc/terraform/{locals,main,providers,resources,variables,fields}.tf /terraform/
cd /terraform
cd /terraform || exit 1
terraform init
Expand Down
4 changes: 2 additions & 2 deletions tests/terraform/static/collector_fields.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ data:
main.tf: |
terraform {
required_providers {
sumologic = "~> 2.4.0"
sumologic = "~> 2.4"
kubernetes = "~> 1.13.0"
}
}
Expand Down Expand Up @@ -254,7 +254,7 @@ data:
}
cp /etc/terraform/{locals,main,providers,resources,variables,fields}.tf /terraform/
cd /terraform
cd /terraform || exit 1
terraform init
Expand Down
4 changes: 2 additions & 2 deletions tests/terraform/static/conditional_sources.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ data:
main.tf: |
terraform {
required_providers {
sumologic = "~> 2.4.0"
sumologic = "~> 2.4"
kubernetes = "~> 1.13.0"
}
}
Expand Down Expand Up @@ -181,7 +181,7 @@ data:
}
cp /etc/terraform/{locals,main,providers,resources,variables,fields}.tf /terraform/
cd /terraform
cd /terraform || exit 1
terraform init
Expand Down
4 changes: 2 additions & 2 deletions tests/terraform/static/custom.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ data:
main.tf: |
terraform {
required_providers {
sumologic = "~> 2.4.0"
sumologic = "~> 2.4"
kubernetes = "~> 1.13.0"
}
}
Expand Down Expand Up @@ -181,7 +181,7 @@ data:
}
cp /etc/terraform/{locals,main,providers,resources,variables,fields}.tf /terraform/
cd /terraform
cd /terraform || exit 1
terraform init
Expand Down
4 changes: 2 additions & 2 deletions tests/terraform/static/default.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ data:
main.tf: |
terraform {
required_providers {
sumologic = "~> 2.4.0"
sumologic = "~> 2.4"
kubernetes = "~> 1.13.0"
}
}
Expand Down Expand Up @@ -252,7 +252,7 @@ data:
}
cp /etc/terraform/{locals,main,providers,resources,variables,fields}.tf /terraform/
cd /terraform
cd /terraform || exit 1
terraform init
Expand Down
4 changes: 2 additions & 2 deletions tests/terraform/static/disable_default_metrics.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ data:
main.tf: |
terraform {
required_providers {
sumologic = "~> 2.4.0"
sumologic = "~> 2.4"
kubernetes = "~> 1.13.0"
}
}
Expand Down Expand Up @@ -245,7 +245,7 @@ data:
}
cp /etc/terraform/{locals,main,providers,resources,variables,fields}.tf /terraform/
cd /terraform
cd /terraform || exit 1
terraform init
Expand Down
4 changes: 2 additions & 2 deletions tests/terraform/static/strip_extrapolation.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ data:
main.tf: |
terraform {
required_providers {
sumologic = "~> 2.4.0"
sumologic = "~> 2.4"
kubernetes = "~> 1.13.0"
}
}
Expand Down Expand Up @@ -253,7 +253,7 @@ data:
}
cp /etc/terraform/{locals,main,providers,resources,variables,fields}.tf /terraform/
cd /terraform
cd /terraform || exit 1
terraform init
Expand Down
4 changes: 2 additions & 2 deletions tests/terraform/static/traces.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ data:
main.tf: |
terraform {
required_providers {
sumologic = "~> 2.4.0"
sumologic = "~> 2.4"
kubernetes = "~> 1.13.0"
}
}
Expand Down Expand Up @@ -189,7 +189,7 @@ data:
}
cp /etc/terraform/{locals,main,providers,resources,variables,fields}.tf /terraform/
cd /terraform
cd /terraform || exit 1
terraform init
Expand Down

0 comments on commit 531479d

Please sign in to comment.