Skip to content

Commit

Permalink
Add terraform-backend-git feature
Browse files Browse the repository at this point in the history
  • Loading branch information
schroedan committed Jan 23, 2025
1 parent 19adb29 commit 167c269
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
matrix:
features:
- infisical-cli
- terraform-backend-git
baseImage:
- alpine:latest
- debian:latest
Expand Down Expand Up @@ -43,6 +44,7 @@ jobs:
matrix:
features:
- infisical-cli
- terraform-backend-git

steps:
- name: Checkout
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
...
Expand Down
20 changes: 20 additions & 0 deletions src/terraform-backend-git/README.md
Original file line number Diff line number Diff line change
@@ -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`._
10 changes: 10 additions & 0 deletions src/terraform-backend-git/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
37 changes: 37 additions & 0 deletions src/terraform-backend-git/install.sh
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions test/terraform-backend-git/alpine.sh
Original file line number Diff line number Diff line change
@@ -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 <LABEL> <cmd> [args...]
check "distro" test "${ID}" = "alpine"
check "check for terraform-backend-git" terraform-backend-git --version

# Report results
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults
21 changes: 21 additions & 0 deletions test/terraform-backend-git/debian.sh
Original file line number Diff line number Diff line change
@@ -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 <LABEL> <cmd> [args...]
check "distro" test "${ID}" = "debian"
check "check for terraform-backend-git" terraform-backend-git --version

# Report results
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults
21 changes: 21 additions & 0 deletions test/terraform-backend-git/fedora.sh
Original file line number Diff line number Diff line change
@@ -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 <LABEL> <cmd> [args...]
check "distro" test "${ID}" = "fedora"
check "check for terraform-backend-git" terraform-backend-git --version

# Report results
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults
26 changes: 26 additions & 0 deletions test/terraform-backend-git/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"alpine": {
"image": "alpine:latest",
"features": {
"terraform-backend-git-cli": {}
}
},
"debian": {
"image": "debian:latest",
"features": {
"terraform-backend-git-cli": {}
}
},
"fedora": {
"image": "fedora:latest",
"features": {
"terraform-backend-git-cli": {}
}
},
"ubuntu": {
"image": "ubuntu:latest",
"features": {
"terraform-backend-git-cli": {}
}
}
}
17 changes: 17 additions & 0 deletions test/terraform-backend-git/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/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

# Feature-specific tests
# The 'check' command comes from the dev-container-features-test-lib. Syntax is...
# check <LABEL> <cmd> [args...]
check "check for terraform-backend-git" terraform-backend-git --version

# Report results
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults
21 changes: 21 additions & 0 deletions test/terraform-backend-git/ubuntu.sh
Original file line number Diff line number Diff line change
@@ -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 <LABEL> <cmd> [args...]
check "distro" test "${ID}" = "ubuntu"
check "check for terraform-backend-git" terraform-backend-git --version

# Report results
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults

0 comments on commit 167c269

Please sign in to comment.