Hello everyone! I have a question. How to enable ...
# atlantis-community
w
Hello everyone! I have a question. How to enable destory resource? I using atlantis with terragrunt, and when delete a file or comment the terraform, In git dont show files to destory.
✅ 1
p
you can run a destroy plan
atlantis plan -- -destroy
That will create a destroy plan, and then you can apply
w
Sure, but when I use -destroy not show destroy path to me. I used this structure:
And my
mysql/vmdbmysqlb2b-test/terragrunt.hcl
, use the modules like .tf. Exmple of content at
mysql/vmdbmysqlb2b-test/terragrunt.hcl
Copy code
terraform {
  source = "${path_relative_from_include()}../../../../modules/mysql"
}
And when I use the command
atlantis plan -- -destroy
, return this message
Copy code
Either you have not created any objects yet or the existing objects were
already deleted outside of OpenTofu.
p
so the infra and backend needs to exist and be applied before you destroy
if this is project base then you need to target the right project with
-p
I do not use terragrunt so I do not know if there is something special about running a destroy plan in terragrunt
w
@PePe Amengual, I'm debugging to find out why the destroy operation isn't working. I suspect the issue lies in saving the object to compare at the time of executing the destroy command. I'm unable to locate the directory where Atlantis saves my project when I run the plan or apply. Is there any configuration to preserve the old objects for comparison in the last execution?
p
enable debug an you will see the full path
w
In output log there are messages:
Copy code
{"level":"debug","ts":"2024-04-16T12:31:36.402Z","caller":"server/middleware.go:72","msg":"GET /healthz – respond HTTP 200","json":{}}
{"level":"info","ts":"2024-04-16T12:31:39.248Z","caller":"models/shell_command_runner.go:161","msg":"successfully ran \"terragrunt plan $(printf '%s' $COMMENT_ARGS | sed 's/,/ /g' | tr -d '\\\\\\\\') --terragrunt-tfpath tofu -out $PLANFILE\" in \"/atlantis-data/repos/infralabs/corporate/cloud-platform/gitops/infra-as-a-code/azure/16/default/INFRAC-HML/mysql/vmdbmysqlb2b-test\"","json":{"repo":"infralabs/corporate/cloud-platform/gitops/infra-as-a-code/azure","pull":"16","duration":3.171896037}}
{"level":"debug","ts":"2024-04-16T12:31:39.248Z","caller":"models/shell_command_runner.go:95","msg":"starting \"terragrunt show --terragrunt-tfpath tofu -json $PLANFILE > plan.json\" in \"/atlantis-data/repos/infralabs/corporate/cloud-platform/gitops/infra-as-a-code/azure/16/default/INFRAC-HML/mysql/vmdbmysqlb2b-test\"","json":{"repo":"infralabs/corporate/cloud-platform/gitops/infra-as-a-code/azure","pull":"16"}}
{"level":"info","ts":"2024-04-16T12:31:39.818Z","caller":"models/shell_command_runner.go:161","msg":"successfully ran \"terragrunt show --terragrunt-tfpath tofu -json $PLANFILE > plan.json\" in \"/atlantis-data/repos/infralabs/corporate/cloud-platform/gitops/infra-as-a-code/azure/16/default/INFRAC-HML/mysql/vmdbmysqlb2b-test\"","json":{"repo":"infralabs/corporate/cloud-platform/gitops/infra-as-a-code/azure","pull":"16","duration":0.569728388}}
{"level":"debug","ts":"2024-04-16T12:31:39.818Z","caller":"models/shell_command_runner.go:95","msg":"starting \"infracost breakdown --path=plan.json\" in \"/atlantis-data/repos/infralabs/corporate/cloud-platform/gitops/infra-as-a-code/azure/16/default/INFRAC-HML/mysql/vmdbmysqlb2b-test\"","json":{"repo":"infralabs/corporate/cloud-platform/gitops/infra-as-a-code/azure","pull":"16"}}
{"level":"info","ts":"2024-04-16T12:31:40.301Z","caller":"models/shell_command_runner.go:161","msg":"successfully ran \"infracost breakdown --path=plan.json\" in \"/atlantis-data/repos/infralabs/corporate/cloud-platform/gitops/infra-as-a-code/azure/16/default/INFRAC-HML/mysql/vmdbmysqlb2b-test\"","json":{"repo":"infralabs/corporate/cloud-platform/gitops/infra-as-a-code/azure","pull":"16","duration":0.482533474}}
{"level":"debug","ts":"2024-04-16T12:31:40.502Z","caller":"vcs/gitlab_client.go:442","msg":"GET /projects/infralabs/corporate/cloud-platform/gitops/infra-as-a-code/azure/merge_requests/16 returned: 200","json":{}}
{"level":"debug","ts":"2024-04-16T12:31:40.502Z","caller":"vcs/gitlab_client.go:411","msg":"Head pipeline found for merge request 16, source 'external'. refTarget 'destroy/test12'","json":{}}
{"level":"debug","ts":"2024-04-16T12:31:40.666Z","caller":"vcs/gitlab_client.go:434","msg":"POST /projects/infralabs/corporate/cloud-platform/gitops/infra-as-a-code/azure/statuses/d4ecdc1755908ca93b655a400a582252f3920cf3 returned: 201","json":{}}
{"level":"info","ts":"2024-04-16T12:31:40.666Z","caller":"events/instrumented_project_command_runner.go:88","msg":"plan success. output available at: <https://git.ifcshop.net/infralabs/corporate/cloud-platform/gitops/infra-as-a-code/azure/-/merge_requests/16>","json":{"repo":"infralabs/corporate/cloud-platform/gitops/infra-as-a-code/azure","pull":"16"}}
{"level":"debug","ts":"2024-04-16T12:31:41.014Z","caller":"vcs/gitlab_client.go:185","msg":"POST /projects/infralabs/corporate/cloud-platform/gitops/infra-as-a-code/azure/merge_requests/16/notes returned: 201","json":{}}
{"level":"debug","ts":"2024-04-16T12:31:41.014Z","caller":"events/db_updater.go:25","msg":"updating DB with pull results","json":{"repo":"infralabs/corporate/cloud-platform/gitops/infra-as-a-code/azure","pull":"16"}}
{"level":"debug","ts":"2024-04-16T12:31:41.266Z","caller":"vcs/gitlab_client.go:442","msg":"GET /projects/infralabs/corporate/cloud-platform/gitops/infra-as-a-code/azure/merge_requests/16 returned: 200","json":{}}
{"level":"debug","ts":"2024-04-16T12:31:41.266Z","caller":"vcs/gitlab_client.go:411","msg":"Head pipeline found for merge request 16, source 'external'. refTarget 'destroy/test12'","json":{}}
I'm doing a local test, and it's working correctly. But local don't delete .terragrunt-cache/ path to project.
When running a new PR in the GitLab with Atlantis server, it generates a new path with PR number on the server. Because of this, it doesn't identify a cache for comparison or destruction items
p
when Atlantis pull the pr code the it creates a dir structure and it saves the plan in that directory
it uses a saved plan so is not lost , unless you close the PR
w
Yes, but in my workflow, I can create a new infrastructure and then destroy it. Because of this, I've closed the PR, and in the future, I will create another PR specifically for the destruction process.
👍🏽 1
I understand now! 🙂 I needed to set in terraform a configuration for backend = local.