Skip to content

Commit 20e7702

Browse files
author
Jacob Woffenden
authored
🤗 Add Terraform wrapper script (#146)
Signed-off-by: Jacob Woffenden <jacob.woffenden@digital.justice.gov.uk>
1 parent 9cc1908 commit 20e7702

File tree

8 files changed

+60
-6
lines changed

8 files changed

+60
-6
lines changed

‎.github/workflows/features.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ jobs:
155155
file: images/base/Dockerfile
156156
context: images/base
157157
load: true
158-
tags: ghcr.io/ministryofjustice/devcontainer-base:local-feature-test-${{ github.sha }}
158+
tags: ghcr.io/ministryofjustice/devcontainer-base:local-feature-test
159159

160160
- name: Testing ${{ matrix.feature }}
161161
id: test_feature
@@ -165,7 +165,7 @@ jobs:
165165
--skip-scenarios \
166166
--project-folder features \
167167
--features ${{ matrix.feature }} \
168-
--base-image ghcr.io/ministryofjustice/devcontainer-base:local-feature-test-${{ github.sha }}
168+
--base-image ghcr.io/ministryofjustice/devcontainer-base:local-feature-test
169169
170170
- name: Testing ${{ matrix.feature }} scenarios
171171
id: test_feature_scenarios
@@ -175,7 +175,7 @@ jobs:
175175
--features ${{ matrix.feature }} \
176176
--skip-autogenerated \
177177
--skip-duplicated \
178-
--base-image ghcr.io/ministryofjustice/devcontainer-base:local-feature-test-${{ github.sha }}
178+
--base-image ghcr.io/ministryofjustice/devcontainer-base:local-feature-test
179179
180180
validate:
181181
needs: [detect-changes]

‎features/src/terraform/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
## [Unreleased]
1111

12+
## [1.2.0] - 2024-10-17
13+
14+
### Added
15+
16+
- Default to installing wrapper script that sets `TF_DATA_DIR` to `/tmp/terraform/${currentDirectory}` ([#140](https://github.com/ministryofjustice/.devcontainer/issues/140))
17+
1218
## [1.1.0] - 2024-08-22
1319

1420
### Changed

‎features/src/terraform/devcontainer-feature.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"id": "terraform",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"name": "Terraform",
55
"documentationURL": "https://github.com/ministryofjustice/.devcontainer/tree/main/features/src/terraform",
6-
"description": "Installs the Terraform CLI and tflint",
6+
"description": "Installs the Terraform CLI, tflint and a wrapper script to aid with permissions issues on macOS",
77
"options": {
88
"terraformCliVersion": {
99
"type": "string",
@@ -16,6 +16,11 @@
1616
"description": "Version of the tflint to install",
1717
"proposals": ["latest"],
1818
"default": "latest"
19+
},
20+
"installTerraformWrapper": {
21+
"type": "boolean",
22+
"description": "Install a Terraform wrapper to help with this permissions bug (https://github.com/ministryofjustice/.devcontainer/issues/140)",
23+
"default": true
1924
}
2025
},
2126
"customizations": {

‎features/src/terraform/install-terraform-cli.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ get_system_architecture
1010

1111
GITHUB_REPOSITORY="hashicorp/terraform"
1212
VERSION="${TERRAFORMCLIVERSION:-"latest"}"
13+
INSTALL_TERRAFORM_WRAPPER="${INSTALLTERRAFORMWRAPPER:-"true"}"
1314

1415
if [[ "${VERSION}" == "latest" ]]; then
1516
get_github_latest_tag "${GITHUB_REPOSITORY}"
@@ -25,7 +26,12 @@ curl --fail-with-body --location "https://releases.hashicorp.com/terraform/${VER
2526

2627
unzip "terraform_${VERSION_STRIP_V}_linux_${ARCHITECTURE}.zip"
2728

28-
install --owner=vscode --group=vscode --mode=775 terraform /usr/local/bin/terraform
29+
if [[ "${INSTALL_TERRAFORM_WRAPPER}" == "true" ]]; then
30+
install --owner=vscode --group=vscode --mode=775 "$(dirname "${0}")"/src/usr/local/bin/terraform /usr/local/bin/terraform
31+
install --owner=vscode --group=vscode --mode=775 terraform /usr/local/bin/terraform-bin
32+
else
33+
install --owner=vscode --group=vscode --mode=775 terraform /usr/local/bin/terraform
34+
fi
2935

3036
install --owner=vscode --group=vscode --mode=775 "$(dirname "${0}")"/src/home/vscode/.devcontainer/featurerc.d/terraform-cli.sh /home/vscode/.devcontainer/featurerc.d/terraform-cli.sh
3137

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
# If current directory contains .tf files, set TF_DATA_DIR to /tmp/terraform/${currentDirectory} otherwise use default
4+
if ls -- *.tf &>/dev/null; then
5+
currentDirectory="$(basename "$(pwd)")"
6+
export TF_DATA_DIR="/tmp/terraform/${currentDirectory}"
7+
fi
8+
9+
exec /usr/local/bin/terraform-bin "$@"
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# shellcheck source=/dev/null
6+
# file only accessible when using devcontainer CLI
7+
source dev-container-features-test-lib
8+
9+
check "terraform version" terraform version
10+
11+
reportResults
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"no_wrapper": {
3+
"image": "ghcr.io/ministryofjustice/devcontainer-base:local-feature-test",
4+
"features": {
5+
"terraform": {
6+
"installTerraformWrapper": false
7+
}
8+
}
9+
}
10+
}

‎scripts/features/test.sh

+7
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@ devcontainer features test \
1313
--skip-scenarios \
1414
--skip-duplicated \
1515
--base-image ghcr.io/ministryofjustice/devcontainer-base:local-feature-test
16+
17+
devcontainer features test \
18+
--project-folder features \
19+
--features "${FEATURE_TO_TEST}" \
20+
--skip-autogenerated \
21+
--skip-duplicated \
22+
--base-image ghcr.io/ministryofjustice/devcontainer-base:local-feature-test

0 commit comments

Comments
 (0)