diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1d20707..b0594a7 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -16,6 +16,7 @@ jobs: matrix: features: - infisical-cli + - terraform-backend-git baseImage: - alpine:latest - debian:latest @@ -43,6 +44,7 @@ jobs: matrix: features: - infisical-cli + - terraform-backend-git steps: - name: Checkout diff --git a/README.md b/README.md index 3d8b13a..c4b1c8a 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ This repository contains a _collection_ of dev container Features. Please take a closer look at the detailed instructions for the individual features: - [Infisical CLI](src/infisical-cli) +- [Terraform State management using Git](src/terraform-backend-git) ## Repo and Feature Structure @@ -19,6 +20,9 @@ Each Feature has its own sub-folder, containing at least a `devcontainer-feature │ ├── infisical-cli │ │ ├── devcontainer-feature.json │ │ └── install.sh +│ ├── terraform-backend-git +│ │ ├── devcontainer-feature.json +│ │ └── install.sh | ├── ... │ │ ├── devcontainer-feature.json │ │ └── install.sh @@ -29,6 +33,9 @@ Each Feature has its own sub-folder, containing at least a `devcontainer-feature │ ├── infisical-cli │ │ ├── scenarios.json │ │ └── test.sh +│ ├── terraform-backend-git +│ │ ├── scenarios.json +│ │ └── test.sh | ├── ... │ │ └── test.sh ... diff --git a/src/terraform-backend-git/README.md b/src/terraform-backend-git/README.md new file mode 100644 index 0000000..0b54c53 --- /dev/null +++ b/src/terraform-backend-git/README.md @@ -0,0 +1,20 @@ + +# Terraform State management using Git (terraform-backend-git) + +Installs terraform-backend-git binary. + +## Example Usage + +```json +"features": { + "ghcr.io/skriptfabrik/devcontainer-features/terraform-backend-git:1": {} +} +``` + + + + + +--- + +_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/skriptfabrik/devcontainer-features/blob/main/src/terraform-backend-git/devcontainer-feature.json). Add additional notes to a `NOTES.md`._ diff --git a/src/terraform-backend-git/devcontainer-feature.json b/src/terraform-backend-git/devcontainer-feature.json new file mode 100644 index 0000000..410be52 --- /dev/null +++ b/src/terraform-backend-git/devcontainer-feature.json @@ -0,0 +1,10 @@ +{ + "id": "terraform-backend-git", + "version": "1.0.0", + "name": "Terraform State management using Git", + "documentationURL": "https://github.com/skriptfabrik/devcontainer-features/tree/main/src/terraform-backend-git", + "description": "Installs terraform-backend-git binary.", + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils" + ] +} diff --git a/src/terraform-backend-git/install.sh b/src/terraform-backend-git/install.sh new file mode 100644 index 0000000..6625b5d --- /dev/null +++ b/src/terraform-backend-git/install.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +set -e + +VERSION="${VERSION:-"latest"}" + +# Checks if packages are installed and installs them if not +check_packages() { + if ! dpkg -s "$@" > /dev/null 2>&1; then + apt_get_update + apt-get -y install --no-install-recommends "$@" + fi +} + +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +# Install dependencies if missing +check_packages curl ca-certificates + +# Fetch latest version if needed +if [ "${VERSION}" = "latest" ]; then + export VERSION=$(curl -s https://api.github.com/repos/plumber-cd/terraform-backend-git/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4)}') +fi + +# Install ARM or x86 version of hugo based on current machine architecture +if [ "$(uname -m)" = "aarch64" ]; then + ARCH="arm64" +else + ARCH="amd64" +fi + +curl -sSLo /usr/local/bin/terraform-backend-git "https://github.com/plumber-cd/terraform-backend-git/releases/download/v${VERSION}/terraform-backend-git-linux-${ARCH}" + +chmod +x /usr/local/bin/terraform-backend-git diff --git a/test/terraform-backend-git/alpine.sh b/test/terraform-backend-git/alpine.sh new file mode 100644 index 0000000..3dfb204 --- /dev/null +++ b/test/terraform-backend-git/alpine.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib +# Provides the 'check' and 'reportResults' commands. +source dev-container-features-test-lib + +# Definition specific tests +. /etc/os-release + +# Scenario-specific tests +# The 'check' command comes from the dev-container-features-test-lib. Syntax is... +# check