Browse Source

Initial version of docker image

master
Drew Short 4 years ago
commit
f1c6698b32
  1. 1
      .dockerignore
  2. 0
      .gitignore
  3. 26
      Dockerfile
  4. 22
      README.md
  5. 43
      bin/tfw
  6. 0
      pipeline.yaml

1
.dockerignore

@ -0,0 +1 @@
pipeline.yaml

0
.gitignore

26
Dockerfile

@ -0,0 +1,26 @@
FROM docker.io/debian:buster-slim
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get -y upgrade \
&& apt-get -y install --no-install-recommends \
ca-certificates \
curl \
unzip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
ARG TERRAFORM_VERSION
ENV TERRAFORM_VERSION="${TERRAFORM_VERSION:-0.13.5}"
RUN useradd --create-home --shell /bin/bash terraform
USER terraform
COPY --chown=terraform:terraform . /home/terraform
RUN chmod +x /home/terraform/bin/* \
&& echo "export PATH=/home/terraform/bin:\${PATH}" >> "/home/terraform/.bashrc" \
&& /home/terraform/bin/tfw -version \
&& rm -f /home/terraform/.terraform/*.zip
VOLUME /home/terraform/source
WORKDIR /home/terraform/source
ENTRYPOINT ["/home/terraform/bin/tfw"]
CMD ["-help"]

22
README.md

@ -0,0 +1,22 @@
# Terraform Docker Image
This repository is for building a container image that uses a simple terraform
wrapper to work on terraform files mounted in the `/home/terraform/source`
directory. It is also the image base for creating custom terraform images
with special plugins preloaded onto the image.
## Building
Create a container with a specific version of terraform
```bash
docker build -t terraform:0.13.0 --build-arg TERRAFORM_VERSION=0.13.0 .
```
## Usage
Mount the current directory as the terraform source and run the show command
```bash
docker run -v $(pwd):/home/terrform/source terraform:0.13.0 show
```

43
bin/tfw

@ -0,0 +1,43 @@
#!/usr/bin/env bash
TERRAFORM_BIN_PATH="${TERRAFORM_BIN_PATH:-$HOME/.terraform}";
TERRAFORM_VERSION=${TERRAFORM_VERSION:-"0.13.5"}
platform='unknown'
platform_uname=$(uname)
if [[ "$platform_uname" == 'Linux' ]]; then
platform='linux'
elif [[ "$platform_uname" == 'FreeBSD' ]]; then
platform='freebsd'
elif [[ "$platform_uname" == 'Darwin' ]]; then
platform='darwin'
else
echo "[$platform_uname] is not recognized as a valid platform"
exit 1
fi
arch="unknown"
arch_uname=$(uname -m)
if [[ "$arch_uname" == 'x86_64' ]]; then
arch='amd64'
elif [[ "$arch_uname" == 'i686' ]]; then
arch='386'
else
echo "[$arch_uname] is not recognized as a valid arch"
exit 1
fi
TERRAFORM_URL="https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_${platform}_${arch}".zip
TERRAFORM_PATH="$TERRAFORM_BIN_PATH/$TERRAFORM_VERSION"
TERRAFORM_CMD="$TERRAFORM_PATH/terraform"
if ! type "$TERRAFORM_CMD" > /dev/null 2>&1; then
if [ ! -f "$TERRAFORM_PATH.zip" ]; then
echo "Downloading $TERRAFORM_URL"
mkdir -p "$TERRAFORM_PATH"
curl -ls "$TERRAFORM_URL" -o "$TERRAFORM_PATH.zip"
fi
cd "$TERRAFORM_PATH" && unzip "$TERRAFORM_PATH.zip" && cd - || exit 2
fi
# shellcheck disable=SC2068
$TERRAFORM_CMD $@

0
pipeline.yaml

Loading…
Cancel
Save