diff --git a/features/src/terraform/CHANGELOG.md b/features/src/terraform/CHANGELOG.md index 3930110..6f5b520 100644 --- a/features/src/terraform/CHANGELOG.md +++ b/features/src/terraform/CHANGELOG.md @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.1.0] - 2024-08-22 + +### Changed + +- Added `tflint` + ## [1.0.0] - 2024-05-13 ### Changed diff --git a/features/src/terraform/devcontainer-feature.json b/features/src/terraform/devcontainer-feature.json index 36dca70..ee4ca19 100644 --- a/features/src/terraform/devcontainer-feature.json +++ b/features/src/terraform/devcontainer-feature.json @@ -1,15 +1,21 @@ { "id": "terraform", - "version": "1.0.0", + "version": "1.1.0", "name": "Terraform", "documentationURL": "https://github.com/ministryofjustice/.devcontainer/tree/main/features/src/terraform", - "description": "Installs the Terraform CLI", + "description": "Installs the Terraform CLI and tflint", "options": { "terraformCliVersion": { "type": "string", "description": "Version of the Terraform CLI to install", "proposals": ["latest"], "default": "latest" + }, + "tflintVersion": { + "type": "string", + "description": "Version of the tflint to install", + "proposals": ["latest"], + "default": "latest" } }, "customizations": { diff --git a/features/src/terraform/install-tflint.sh b/features/src/terraform/install-tflint.sh new file mode 100644 index 0000000..9b9d0a4 --- /dev/null +++ b/features/src/terraform/install-tflint.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +set -e + +# shellcheck source=/dev/null +# file not accessible until being built +source /usr/local/bin/devcontainer-utils + +get_system_architecture + +GITHUB_REPOSITORY="terraform-linters/tflint" +VERSION="${TFLINTVERSION:-"latest"}" + +if [[ "${VERSION}" == "latest" ]]; then + get_github_latest_tag "${GITHUB_REPOSITORY}" + VERSION="${GITHUB_LATEST_TAG}" + VERSION_STRIP_V="${GITHUB_LATEST_TAG_STRIP_V}" +else + # shellcheck disable=SC2034 + VERSION_STRIP_V="${VERSION#v}" +fi + +curl --fail-with-body --location "https://github.com/terraform-linters/tflint/releases/download/${VERSION}/tflint_linux_${ARCHITECTURE}.zip" \ + --output "tflint_${VERSION_STRIP_V}_linux_${ARCHITECTURE}.zip" + +unzip "tflint_${VERSION_STRIP_V}_linux_${ARCHITECTURE}.zip" + +install --owner=vscode --group=vscode --mode=775 tflint /usr/local/bin/tflint + +rm --recursive --force tflint "tflint_${VERSION_STRIP_V}_linux_${ARCHITECTURE}.zip" diff --git a/features/src/terraform/install.sh b/features/src/terraform/install.sh index 3da3a03..4036090 100644 --- a/features/src/terraform/install.sh +++ b/features/src/terraform/install.sh @@ -6,3 +6,6 @@ source /usr/local/bin/devcontainer-utils logger "info" "Installing Terraform CLI (version: ${TERRAFORMCLIVERSION})" bash "$(dirname "${0}")"/install-terraform-cli.sh + +logger "info" "Installing tflint (version: ${TFLINTVERSION})" +bash "$(dirname "${0}")"/install-tflint.sh diff --git a/features/test/terraform/test.sh b/features/test/terraform/test.sh index 1620de0..a62a950 100644 --- a/features/test/terraform/test.sh +++ b/features/test/terraform/test.sh @@ -9,4 +9,6 @@ source dev-container-features-test-lib check "terraform version" terraform version check "terraform featurerc existence" stat /home/vscode/.devcontainer/featurerc.d/terraform-cli.sh +check "tflint version" tflint --version + reportResults