Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

add terraform-docs to azure-terraform #1529

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions containers/azure-terraform/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
1 change: 1 addition & 0 deletions containers/azure-terraform/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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}"
Expand All @@ -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!"
11 changes: 10 additions & 1 deletion containers/azure-terraform/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}
]
}
6 changes: 4 additions & 2 deletions containers/azure-terraform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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`)
Expand Down