Skip to content

Latest commit

 

History

History
94 lines (75 loc) · 2.32 KB

README-docker.md

File metadata and controls

94 lines (75 loc) · 2.32 KB

Running aws2tf using a container

Note: you do not need to clone this repo to run aws2tf using a container - just follow these instructions instead

Pre-requisites

  • docker installed and available - see here

Make the required sub directories

mkdir -p aws2tf/generated
cd aws2tf

Create the Dockerfile (tip: use the copy icon, top right)

cat << 'EOF' > Dockerfile.aws2tf
FROM python:3.12.5-alpine3.20
RUN apk update \
    && apk add curl zip git unzip

# Get Terraform
ARG TF_VERSION=latest
RUN set -eux \
	&& if [ "${TF_VERSION}" = "latest" ]; then \
		VERSION="$( curl -sS https://releases.hashicorp.com/terraform/ \
			| tac | tac \
			| grep -Eo '/terraform/[.0-9]+/\"' \
			| grep -Eo '[.0-9]+' \
			| sort -V \
			| tail -1 )"; \
	else \
		VERSION="$( curl -sS https://releases.hashicorp.com/terraform/ \
			| tac | tac \
			| grep -Eo "/terraform/${TF_VERSION}\.[.0-9]+/\"" \
			| grep -Eo '[.0-9]+' \
			| sort -V \
			| tail -1 )"; \
	fi \
	\
	# Get correct architecture
	&& if [ "$(dpkg --print-architecture | awk -F'-' '{print $NF}' )" = "i386" ]; then\
		ARCH=386; \
	elif [ "$(uname -m)" = "x86_64" ]; then \
		ARCH=amd64; \
	elif [ "$(uname -m)" = "aarch64" ]; then \
		ARCH=arm64; \
	elif [ "$(uname -m)" = "armv7l" ]; then \
		ARCH=arm; \
	fi \
	\
	&& curl --fail -sS -L -O \
		https://releases.hashicorp.com/terraform/${VERSION}/terraform_${VERSION}_linux_${ARCH}.zip \
	&& unzip terraform_${VERSION}_linux_${ARCH}.zip -d /usr/bin \
	&& chmod +x /usr/bin/terraform \
    && rm -f terraform_${VERSION}_linux_${ARCH}.zip

RUN adduser -D aws2tf
RUN git clone -b python https://github.com/aws-samples/aws2tf.git /aws2tf
RUN chown -R aws2tf /aws2tf
USER aws2tf
WORKDIR /aws2tf
#install dependencies
RUN pip install -r requirements.txt
ENV PYTHONUNBUFFERED=1
# Set the entrypoint
ENTRYPOINT ["python", "aws2tf.py"]
CMD []
EOF

build the container from the newly created Dockerfile.aws2tf

docker build -f Dockerfile.aws2tf --no-cache -t aws2tf . 

Create an alias ro run the aws2tf container

alias aws2tf.py="docker run --security-opt=no-new-privileges --name aws2tf --rm -it -v $(pwd)/generated:/aws2tf/generated -v ~/.aws:/home/aws2tf/.aws:ro aws2tf"

run aws2tf using the alias to the container:

aws2tf.py -t vpc