Additional destroy tasks

Hi all.

Situation is this: We are deploying landscapes via terraform and create documentation via github provisioner with data from the created landscapes.

The problem is: when we destroy the landscape and the pull request for the landscape is already merged, the terraform destroy will not touch the documentation in git since the PR was already deleted.

My idea would be to have an additional task during the terraform destroy to create a new PR to remove the landscape documentation for git. Is this possible? Is there may be a more elegant way?

Thanks in advance

Hi @thomas.bemme,

I don’t think this is something that Terraform alone can solve, because Terraform is not designed to deal with this sort of workflow.

However, I could imagine implementing it alongside Terraform like this:

  • Whenever a PR is opened, trigger a program that regenerates the docs using the proposed new configuration and then either adds a new commit to the PR to include those doc updates, or returns an error if the updated docs don’t match what was already in the PR.

    (With the second possibility, the idea would be to require the person proposing the change to run the doc update step themselves before committing the change, in which case the triggered program is only to verify that they did it correctly, similar to verifying that tests are passing.)

  • If the PR is merged then the doc updates get merged immediately along with the configuration changes, so the documentation will be updated slightly before the infrastructure is updated to match, rather than after.

  • If the PR is not merged then the doc updates in the PR are discarded along with the code changes that prompted them.

What I described above is something you’d implement using your VCS platform’s automation system, rather than using Terraform. Terraform does not integrate with version control and is not designed to orchestrate updates to your version control system.