Skip to content

Commit

Permalink
docs(readme): add terraform docs automation (#83)
Browse files Browse the repository at this point in the history
* docs(readme): add terraform docs automation
Add terraform docs script along with makefile target and gihub action for same

Signed-off-by: Timothy MacDonald <tim.macdonald@lacework.net>

* docs(readme): automate update and testing of README.md by terraform-docs
Add github action to test that README.md has been update. Also add update of README.md to /scripts/release.sh prepare

Signed-off-by: Timothy MacDonald <tim.macdonald@lacework.net>

---------

Signed-off-by: Timothy MacDonald <tim.macdonald@lacework.net>
  • Loading branch information
tmac1973 authored Oct 10, 2023
1 parent aa927fb commit 6deaa09
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 3 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/terraform_docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Test that terraform docs has been run
on: push
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Install terraform-docs
run: curl -L https://github.com/terraform-docs/terraform-docs/releases/download/v0.16.0/terraform-docs-v0.16.0-linux-amd64.tar.gz | (cd /usr/local/bin; tar zxvf -; chmod +x /usr/local/bin/terraform-docs)
- name: store hash of orig README.md
id: old_hash
run: echo "README_HASH=$(md5sum README.md)" >> $GITHUB_OUTPUT
- name: Update README.md using terraform-docs make target
run: make terraform-docs
- name: store hash of new README.md
id: new_hash
run: echo "README_HASH=$(md5sum README.md)" >> $GITHUB_OUTPUT
- name: echo hashes
run: |
echo ${{ steps.old_hash.outputs.README_HASH }}
echo ${{ steps.new_hash.outputs.README_HASH }}
- name: test to see of hashs are the same
if: ${{ steps.old_hash.outputs.README_HASH != steps.new_hash.outputs.README_HASH }}
uses: actions/github-script@v6
with:
script: |
core.setFailed('Please run "make terraform-docs" and try again')
4 changes: 4 additions & 0 deletions .terraform-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
formatter: "markdown"
version: "0.16.0"
output:
file: README.md
5 changes: 5 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ ci: ## *CI ONLY* Runs tests on CI pipeline
.PHONY: release
release: ci ## *CI ONLY* Prepares a release of the Terraform module
scripts/release.sh prepare

.PHONY: terraform-docs
terraform-docs:
scripts/terraform-docs.sh

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ storage-component.googleapis.com
cloudasset.googleapis.com
essentialcontacts.googleapis.com
```

<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
Expand Down Expand Up @@ -111,7 +111,7 @@ essentialcontacts.googleapis.com
| <a name="input_required_config_apis"></a> [required\_config\_apis](#input\_required\_config\_apis) | n/a | `map(any)` | <pre>{<br> "bigquery": "bigquery.googleapis.com",<br> "cloudasset_inventory": "cloudasset.googleapis.com",<br> "compute": "compute.googleapis.com",<br> "containers": "container.googleapis.com",<br> "dns": "dns.googleapis.com",<br> "essentialcontacts": "essentialcontacts.googleapis.com",<br> "iam": "iam.googleapis.com",<br> "kms": "cloudkms.googleapis.com",<br> "logging": "logging.googleapis.com",<br> "pubsub": "pubsub.googleapis.com",<br> "resourcemanager": "cloudresourcemanager.googleapis.com",<br> "serviceusage": "serviceusage.googleapis.com",<br> "sqladmin": "sqladmin.googleapis.com",<br> "storage_component": "storage-component.googleapis.com"<br>}</pre> | no |
| <a name="input_service_account_name"></a> [service\_account\_name](#input\_service\_account\_name) | The Service Account name (required when use\_existing\_service\_account is set to true). This can also be used to specify the new service account name when use\_existing\_service\_account is set to false | `string` | `""` | no |
| <a name="input_service_account_private_key"></a> [service\_account\_private\_key](#input\_service\_account\_private\_key) | The private key in JSON format, base64 encoded (required when use\_existing\_service\_account is set to true) | `string` | `""` | no |
| <a name="input_skip_iam_grants"></a> [skip\_iam\_grants](#input\_skip\_iam\_grants) | Skip generation of custom role, and IAM grants to the Service Account, for customers who use IAM policy-as-code external to the Lacework module. WARNING - integration will fail if grants are not in place prior to execution. 'use_existing_service_account' must also be set to `true` | `bool` | `false` | no |
| <a name="input_skip_iam_grants"></a> [skip\_iam\_grants](#input\_skip\_iam\_grants) | Skip generation of custom role, and IAM grants to the Service Account, for customers who use IAM policy-as-code external to the Lacework module. WARNING - integration will fail if grants are not in place prior to execution. 'use\_existing\_service\_account' must also be set to `true` | `bool` | `false` | no |
| <a name="input_use_existing_service_account"></a> [use\_existing\_service\_account](#input\_use\_existing\_service\_account) | Set this to true to use an existing Service Account | `bool` | `false` | no |
| <a name="input_wait_time"></a> [wait\_time](#input\_wait\_time) | Amount of time to wait before the next resource is provisioned | `string` | `"10s"` | no |

Expand All @@ -121,3 +121,4 @@ essentialcontacts.googleapis.com
|------|-------------|
| <a name="output_service_account_name"></a> [service\_account\_name](#output\_service\_account\_name) | The Service Account name |
| <a name="output_service_account_private_key"></a> [service\_account\_private\_key](#output\_service\_account\_private\_key) | The private key in JSON format, base64 encoded |
<!-- END_TF_DOCS -->
7 changes: 6 additions & 1 deletion scripts/release_helpers.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Name:: release_helpers.sh
# Description:: A set of helper funtions to be used by our release.sh script
# Description:: A set of helper functions to be used by our release.sh script
# Author:: Salim Afiune Maya (<afiune@lacework.net>)
#

Expand Down Expand Up @@ -137,6 +137,7 @@ prepare_release() {
prerequisites
remove_tag_version
check_for_minor_version_bump
generate_readme
generate_release_notes
update_changelog
push_release
Expand Down Expand Up @@ -192,6 +193,10 @@ generate_release_notes() {
echo "$(cat CHANGES.md)" >> RELEASE_NOTES.md
}

generate_readme() {
make terraform-docs
}

load_list_of_changes() {
latest_version=$(find_latest_version)
local _list_of_changes=$(git log --no-merges --pretty="* %s (%an)([%h](https://github.com/${org_name}/${project_name}/commit/%H))" ${latest_version}..${main_branch})
Expand Down
13 changes: 13 additions & 0 deletions scripts/terraform-docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

if which terraform-docs >/dev/null; then
terraform-docs .
elif which docker >/dev/null; then
echo "## terraform-docs not found in PATH, but docker was found"
echo "## running terraform-docs in docker"
terraform_docs_version=$(cat .terraform-docs.yml | grep version | cut -d\" -f 2)
docker run --rm -v `pwd`:/data cytopia/terraform-docs:${terraform_docs_version} terraform-docs .
else
echo "## terraform-docs not found in PATH, neither was docker"
echo "## please install terraform-docs or docker"
exit 1
fi

0 comments on commit 6deaa09

Please sign in to comment.