diff --git a/containers/azure-terraform/.devcontainer/Dockerfile b/containers/azure-terraform/.devcontainer/Dockerfile index c34e941289..aeb3e649c9 100644 --- a/containers/azure-terraform/.devcontainer/Dockerfile +++ b/containers/azure-terraform/.devcontainer/Dockerfile @@ -35,11 +35,12 @@ RUN if [ "${INSTALL_AZURE_CLI}" = "true" ]; then bash /tmp/library-scripts/azcli fi \ && rm -rf /var/lib/apt/lists/* -# Install Terraform, tflint, Terragrunt +# Install Terraform, tflint, Terragrunt, terraform-docs ARG TERRAFORM_VERSION=0.12.16 ARG TFLINT_VERSION=0.8.2 ARG TERRAGRUNT_VERSION=0.28.1 -RUN bash /tmp/library-scripts/terraform-debian.sh "${TERRAFORM_VERSION}" "${TFLINT_VERSION}" "${TERRAGRUNT_VERSION}" \ +ARG TERRAFORM_DOCS_VERSION=0.14.1 +RUN bash /tmp/library-scripts/terraform-debian.sh "${TERRAFORM_VERSION}" "${TFLINT_VERSION}" "${TERRAGRUNT_VERSION}" "${TERRAFORM_DOCS_VERSION}" \ && rm -rf /tmp/library-scripts diff --git a/containers/azure-terraform/.devcontainer/devcontainer.json b/containers/azure-terraform/.devcontainer/devcontainer.json index 554683d866..6c0cd6b0fc 100644 --- a/containers/azure-terraform/.devcontainer/devcontainer.json +++ b/containers/azure-terraform/.devcontainer/devcontainer.json @@ -6,6 +6,7 @@ "TERRAFORM_VERSION": "0.14.5", "TFLINT_VERSION": "0.24.1", "TERRAGRUNT_VERSION": "0.28.1", + "TERRAFORM_DOCS_VERSION": "0.16.0", "INSTALL_AZURE_CLI": "true", "INSTALL_DOCKER": "true", "NODE_VERSION": "lts/*" diff --git a/containers/azure-terraform/.devcontainer/library-scripts/terraform-debian.sh b/containers/azure-terraform/.devcontainer/library-scripts/terraform-debian.sh index f2614aeb8c..3b0e138ed5 100755 --- a/containers/azure-terraform/.devcontainer/library-scripts/terraform-debian.sh +++ b/containers/azure-terraform/.devcontainer/library-scripts/terraform-debian.sh @@ -14,9 +14,11 @@ set -e TERRAFORM_VERSION="${1:-"latest"}" TFLINT_VERSION="${2:-"latest"}" TERRAGRUNT_VERSION="${3:-"latest"}" -TERRAFORM_SHA256="${4:-"automatic"}" -TFLINT_SHA256="${5:-"automatic"}" -TERRAGRUNT_SHA256="${6:-"automatic"}" +TERRAFORM_DOCS_VERSION="${4:-"latest"}" +TERRAFORM_SHA256="${5:-"automatic"}" +TFLINT_SHA256="${6:-"automatic"}" +TERRAGRUNT_SHA256="${7:-"automatic"}" +TERRAFORM_DOCS_SHA256="${8:-"automatic"}" TERRAFORM_GPG_KEY="72D7468F" TFLINT_GPG_KEY_URI="https://raw.githubusercontent.com/terraform-linters/tflint/master/8CE69160EB3F2FE9.key" @@ -156,11 +158,12 @@ fi find_version_from_git_tags TERRAFORM_VERSION 'https://github.com/hashicorp/terraform' find_version_from_git_tags TFLINT_VERSION 'https://github.com/terraform-linters/tflint' find_version_from_git_tags TERRAGRUNT_VERSION 'https://github.com/gruntwork-io/terragrunt' +find_version_from_git_tags TERRAFORM_DOCS_VERSION 'https://github.com/terraform-docs/terraform-docs' mkdir -p /tmp/tf-downloads cd /tmp/tf-downloads -# Install Terraform, tflint, Terragrunt +# Install Terraform, tflint, Terragrunt, terraform-docs echo "Downloading terraform..." terraform_filename="terraform_${TERRAFORM_VERSION}_linux_${architecture}.zip" curl -sSL -o ${terraform_filename} "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/${terraform_filename}" @@ -198,6 +201,7 @@ if [ "${TFLINT_VERSION}" != "none" ]; then unzip /tmp/tf-downloads/${TFLINT_FILENAME} mv -f tflint /usr/local/bin/ fi + if [ "${TERRAGRUNT_VERSION}" != "none" ]; then echo "Downloading Terragrunt..." terragrunt_filename="terragrunt_linux_${architecture}" @@ -214,5 +218,21 @@ if [ "${TERRAGRUNT_VERSION}" != "none" ]; then mv -f /tmp/tf-downloads/${terragrunt_filename} /usr/local/bin/terragrunt fi +if [ "${TERRAFORM_DOCS_VERSION}" != "none" ]; then + echo "Downloading terraform-docs..." + terraform_docs_filename="terraform-docs-v${TERRAFORM_DOCS_VERSION}-linux-${architecture}.tar.gz" + curl -sSL -o "/tmp/tf-downloads/${terraform_docs_filename}" "https://github.com/terraform-docs/terraform-docs/releases/download/v${TERRAFORM_DOCS_VERSION}/${terraform_docs_filename}" + if [ "${TERRAFORM_DOCS_SHA256}" != "dev-mode" ]; then + if [ "${TERRAFORM_DOCS_SHA256}" = "automatic" ]; then + curl -sSL -o terraform_docs_sha256sum "https://github.com/terraform-docs/terraform-docs/releases/download/v${TERRAFORM_DOCS_VERSION}/terraform-docs-v${TERRAFORM_DOCS_VERSION}.sha256sum" + else + echo "${TERRAFORM_DOCS_SHA256} *${terraform_docs_filename}" > terraform_docs_sha256sum + fi + sha256sum --ignore-missing -c terraform_docs_sha256sum + fi + tar -zxvof "/tmp/tf-downloads/${terraform_docs_filename}" + mv -f "/tmp/tf-downloads/terraform-docs" /usr/local/bin/ +fi + rm -rf /tmp/tf-downloads ${GNUPGHOME} echo "Done!" diff --git a/containers/azure-terraform/.vscode/tasks.json b/containers/azure-terraform/.vscode/tasks.json index 67dedd4ef6..e546c8b360 100644 --- a/containers/azure-terraform/.vscode/tasks.json +++ b/containers/azure-terraform/.vscode/tasks.json @@ -52,6 +52,15 @@ }, "command": "tflint", "problemMatcher": [] - } + }, + { + "label": "terraform docs", + "type": "shell", + "options": { + "cwd": "${workspaceFolder}/test-project/templates" + }, + "command": "terraform-docs markdown table --output-file README.md ./", + "problemMatcher": [] + } ] } diff --git a/containers/azure-terraform/README.md b/containers/azure-terraform/README.md index f4dd4f739c..e0168048d4 100644 --- a/containers/azure-terraform/README.md +++ b/containers/azure-terraform/README.md @@ -29,9 +29,10 @@ You can also choose the specific version of Terraform installed by updating the ```Dockerfile "arg": { - "TERRAFORM_VERSION": "0.14.5" + "TERRAFORM_VERSION": "0.14.5", "TFLINT_VERSION": "0.24.1", - "TERRAGRUNT_VERSION": "0.28.1" + "TERRAGRUNT_VERSION": "0.28.1", + "TERRAFORM_DOCS_VERSION": "0.16.0", "INSTALL_AZURE_CLI": "true", "INSTALL_DOCKER": "true", "NODE_VERSION": "lts" @@ -80,6 +81,7 @@ Once the environment settings are configured with the `.devcontainer/devcontaine - `terraform init`: installs plugins and connect to terraform remote backend - `terraform format`: fix formatting issues - `terraform lint`: fix linting issues +- `terraform docs`: generate terraform module documentation For additional terraform commands, you can use the [Azure Terraform extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azureterraform). - Navigate to the directory where the templates are located (`test-project/templates`)