From 5c07c5a88aafefe1825bdd48994290d200e97886 Mon Sep 17 00:00:00 2001 From: Bjorn Olsen Date: Wed, 27 Nov 2024 12:58:21 +0000 Subject: [PATCH] fixup devcontainer --- .devcontainer/devcontainer.json | 3 ++- .github/CONTRIBUTING.md | 4 +++- .vscode/extensions.json | 5 +++++ Dockerfile | 40 ++++++++++++++++++++++----------- 4 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 .vscode/extensions.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 1e29a75..fb91361 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -6,7 +6,8 @@ // Update 'VARIANT' to pick an Ubuntu version: jammy / ubuntu-22.04, focal / ubuntu-20.04, bionic /ubuntu-18.04 // Use ubuntu-22.04 or ubuntu-18.04 on local arm64/Apple Silicon. "args": { - "VARIANT": "ubuntu-22.04" + "TAG": "latest", + "USER": "vscode" } }, diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 236db5f..5e2be62 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -12,7 +12,9 @@ Please note we have a code of conduct, please follow it in all your interactions 1. Update the README.md with details of changes including example hcl blocks and [example files](./examples) if appropriate. 2. Add appropriate tests. 3. Run pre-commit hooks `pre-commit run -a`. -4. Once all outstanding comments and checklist items have been addressed, your contribution will be merged! Merged PRs will be included in the next release. The terraform-aws-vpc maintainers take care of updating the CHANGELOG as they merge. +4. Once all outstanding comments and checklist items have been addressed, your contribution will be merged! + +Merged PRs will be included in the next release. ## Checklists for contributions diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..87749a8 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "ms-vscode-remote.remote-containers" + ] +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e95b6e2..04473a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,33 @@ -# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/ubuntu/.devcontainer/base.Dockerfile +# Docker image for executing Terraform static code analysis tools and pre-commit hooks +# This may be run as a devcontainer in VSCode or as a standalone container for tests +# Inspired by https://github.com/alastairhm/docker-terraform-check -# [Choice] Ubuntu version (use ubuntu-22.04 or ubuntu-18.04 on local arm64/Apple Silicon): ubuntu-22.04, ubuntu-20.04, ubuntu-18.04 -ARG VARIANT="jammy" -FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT} +ARG TAG=latest -# Install additional OS packages. -RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install --no-install-recommends python3 python3-pip cloud-init +FROM ubuntu:${TAG} as this + +ARG USER=user -COPY requirements.txt . -RUN pip install -r requirements.txt +ARG TFSEC_VER=v1.28.1 +ARG TFLINT_VER=v0.43.0 +ARG TFDOCS_VER=v0.19.0 -COPY .pre-commit-config.yaml . -RUN git init . && pre-commit install-hooks +# Install additional OS packages. +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && \ + apt-get -y install --no-install-recommends \ + bash ca-certificates wget git unzip tar python3 python3-venv && \ + update-ca-certificates -f +# Install Terraform static code analysis tools. +COPY .tflint.hcl . +COPY .tfsec-config.yml . COPY .tfdocs-config.yml . -ADD https://github.com/terraform-docs/terraform-docs/releases/download/v0.16.0/terraform-docs-v0.16.0-linux-amd64.tar.gz ./terraform-docs.tar.gz -RUN tar -xzf terraform-docs.tar.gz && chmod +x terraform-docs && mv terraform-docs /usr/local/bin/terraform-docs +RUN wget https://github.com/aquasecurity/tfsec/releases/download/${TFSEC_VER}/tfsec-linux-amd64 -O /usr/bin/tfsec && chmod +x /usr/bin/tfsec && \ + wget https://github.com/terraform-linters/tflint/releases/download/${TFLINT_VER}/tflint_linux_amd64.zip && unzip tflint_linux_amd64.zip && mv tflint /usr/bin && rm tflint_linux_amd64.zip && \ + tflint --config .tflint.hcl --init && \ + wget https://github.com/terraform-docs/terraform-docs/releases/download/${TFDOCS_VER}/terraform-docs-${TFDOCS_VER}-linux-amd64.tar.gz -O terraform-docs.tar.gz && \ + tar -xzf terraform-docs.tar.gz && chmod +x terraform-docs && mv terraform-docs /usr/bin && rm terraform-docs.tar.gz + +# For dev container in VSCode, create a non-root user. +RUN useradd -ms /bin/bash ${USER} +USER ${USER}