Skip to content

Commit 4d4b2ad

Browse files
author
Jacob Woffenden
authored
Add wrapper script
Add scenario Signed-off-by: GitHub <noreply@github.com>
1 parent 79c2eba commit 4d4b2ad

File tree

7 files changed

+58
-4
lines changed

7 files changed

+58
-4
lines changed

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 "$@"

features/test/terraform/no_wrapper.sh

+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

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@ docker build \
77
--tag ghcr.io/ministryofjustice/devcontainer-base:local-feature-test \
88
images/base
99

10-
devcontainer features test \
10+
# devcontainer features test \
1111
--project-folder features \
1212
--features "${FEATURE_TO_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)