Skip to content

Commit

Permalink
Merge pull request #44 from cloudandthings/2024-codebuild
Browse files Browse the repository at this point in the history
feat!: Replace EC2+Autoscaling with AWS CodeBuild
  • Loading branch information
baolsen authored Nov 27, 2024
2 parents 1d1abe5 + 008acf8 commit d2277e4
Show file tree
Hide file tree
Showing 59 changed files with 642 additions and 2,102 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},

Expand Down
4 changes: 3 additions & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
pip install -r requirements.txt
else
pip install pre-commit
pip install checkov
fi
- name: Run
run: |
Expand All @@ -55,42 +56,3 @@ jobs:
- name: cat pre-commit log
if: failure()
run: cat ~/.cache/pre-commit/pre-commit.log

#--------------------------------------------------------------
# TESTS
#--------------------------------------------------------------
tests:
needs: [pre_commit]
name: ✅ tests
# For public repos use runs-on: ubuntu-latest
# For private repos use runs-on: self-hosted
runs-on: ubuntu-latest
container: bjorncloudandthings/terraform-aws-github:latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v2
- uses: hashicorp/setup-terraform@v2
- uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: ${{ env.AWS_REGION }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
role-to-assume: ${{ env.AWS_ROLE_ARN }}
role-duration-seconds: 3600
- name: Install requirements
run: |
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
- name: Run
run: |
source .venv/bin/activate
cat <<- EOF > .pytest_config.yaml
variables:
run_id: ${{ github.run_id }}
EOF
echo "::echo::off"
pytest --error-for-skips
env:
PYTEST_ADDOPTS: "--color=yes"
timeout-minutes: 30
4 changes: 0 additions & 4 deletions .tfdocs-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ content: |-
```hcl
{{ include "examples/advanced/main.tf" }}
```
### Software packs
```hcl
{{ include "modules/software/software_packs.tf" }}
```
----
{{ .Inputs }}
Expand Down
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"ms-vscode-remote.remote-containers"
]
}
40 changes: 27 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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}
Loading

0 comments on commit d2277e4

Please sign in to comment.