You are working on terraform code and want to ensure your documentation is updated after you made some changes. Why don't you use git-hooks for that?
A long time ago I wrote about git-hooks, today I want to give you a practicle example on how I ensure my terraform documetation stays up-to-date.
terraform-docs
Not sure if you every heard of terraform-docs, but it’s a tool which generates terraform modules documentation in various formats. You can define a config file .terraform-docs.yml which defines how your documentations shall look like. My $HOME\.terraform-docs.yml looks as follows:
A practical example
If you are using terraform-docs you may actually want to ensure, that the docs are created before you commit changes to git. This can be achieved by githooks
I define a path where my script like
Create the folder
In that folder I create a file - in this case for the pre-commit-hook- named pre-commit
I make it executable and add the following code
So now when you do a git commit in a terraform related repo, it will create the docu automatically:
What’s next?
Rather than copying code around, setup a repo for your team where you store all shared git hooks. Mine can be found at here.