Tear down an environment
This guide will walk you through the steps to tear down a lower environment.
WARNING
You should really know what you are doing before doing this. You can't undo this, and it will delete all data in the environment.
Prerequisites
To tear down a lower environment, you will need:
- Administrator access to the AWS account where the environment is hosted.
- Terraform v1.3.1 install locally, or pair with someone who does.
Things to keep
Most of what we will be deleting is CloudFormation stacks, but you should keep the environment variables configuration, as you may want to rebuild the environment in the future. This configuration is in the samconfig.toml files for services and .env-cmdrc for clients, so just leave these files in the repository.
1. Delete all CloudFormation stacks
Essentially we are going to delete all CloudFormation stacks for the environment. These include clients, services, infrastructure, and core deployment stacks. I mean do what you want, but I would recommend a Google sheet to keep track of what you are deleting, particularly around resources that need to be manually deleted.
Simple to do, just a lot of clicking in AWS and waiting. In cloudformation, select a stack and click on the delete button.
The order to delete stacks is:
TIP
I know this is obvious, but make sure you are deleting the correct stack, its very easy to delete a stack in the wrong environment.
Totally not speaking from experience.
Deleting Services
Services stacks are named in the format ENVIRONMENT-SERVICENAME-service.
Most elements will be destroyed automatically, but there are a few items are are marked for retention and will need to be manually deleted, these include:
- S3 buckets
- DynamoDb tables
- Lambda Layers
- cloudwatch logs (see section below)
Once a stack is in status DELETE_COMPLETE, Switch to the Resources tab, resources requiring manual deletion will be marked as 'DELETE_SKIPPED' as shown in the image below.

Order to delete services
Most services are independent of each other. But best to start with out more loose services such as Janitor, slack chatbot etc. before moving onto core services like engagements, opportunities, etc.
There are a few that do rely on others, I'll just mention the ones I had issues with:
Andirelies onconfigservice, so deleteAndifirstopportunitiesrelies onorganisationsservice, so deleteopportunitiesfirstfinance-gatewayrelies onexpensesso deletefinance-gatewaybeforeexpenses- Most services rely on the
Authservice, so best to delete this last
Deleting Clients
Services stacks are named in the format ENVIRONMENT-CLIENTNAME-client. S3 buckets associated with the client will be deleted in stack provided they are empty before stack deletion. So make sure to empty the bucket before deleting the stack.
Order to delete clients
Most clients are independent of each other, but micro frontends clients (end in -mfa) depend on the luna-front-end, so deleted this first.
Deleting Infrastructure
Services stacks are named in the format ENVIRONMENT-NAME-infrastructure. Should be relatively straightforward, depending on the environment some stack such as redshift may have no resources to delete.
Deleting platform
This is the last stack to delete, as it contains the core deployment resources.
There is a manually created role that needs to be deleted as well. The role is called ENVIRONMENT-iam-role-deployer-platform.
2. Delete all CloudWatch Log Groups
It costs money to store logs in CloudWatch, so make sure to delete all log groups associated with the environment. Simple enough to do, just go to CloudWatch, search the environment name and delete all log groups.
3. Remove references to environment Terraform
In the platform/core-infrastructure/targets/development/main.tf:
- Remove the environment from the
domains_map.additional_auth_callbackslist - Under domain_map, if there is a chatbot url for the environment, remove it
Then run plan and apply, but probably best to speak to someone from the platform team before doing this.
