Skip to main content
Knowledge Base

Seamless removal of resources through CI ?

Answer

Hi there To create resources with our Gitlab CI we just add the folder/subfolder/terragrunt.hcl. During the MR phase, the pipeline will run-all plan, once merged it'll run-all apply, all good. But how do we remove resources ? If we make a MR removing the folder, then nothing happens, the plan-all / run-all will juste ignore the folder/subfolder/terraform.tfstate (we're using the `key = "${path_relative_to_include()}/terraform.tfstate" ` configuration) in our S3 remote state storage forever. So far we could think of three ways - Merge all the .tfstate, to work like raw terraform would I guess, with a single global state. Not ideal, would defeat one of the point of using Terragrunt. - Remove it manually, the MR just reflecting the live state of the infra. We will do that for a while, but we'ld really like to avoid operators doing stuff on their workstations, so it's just temporary. - Add a `create_stuff = true` argument to our terraform modules, and the removal takes place in 2 MRs, first `create_stuff = false`, then remove the file. Maybe the best solution, but it'll requires some work, and that's one more argument to propagate between modules & submodules etc. I read the documentation but I saw no recommended way for this. Did I missed something like a "compare my whole directory structure with the remote state bucket structure and destroy missing stuff" command ? Or a recommended CI workflow ? Maybe a third party tool like Atlantis is relevant here ? Thanks in advance for any suggestions

Here's a write-up of how we run `apply` and `destroy` in our pipelines: https://blog.gruntwork.io/a-ci-cd-pipeline-for-terraform-and-terragrunt-5fd346e90c89