Uninstalling the blueprint
This page shows how to remove Hosty from an AWS account completely: the IAM users and groups, the Route53 zone, the S3 buckets and the storage of the OpenTofu state. It's the reverse of Applying Hosty blueprint, and it can't be undone.
Before you start
- Delete every cluster first.
- Make sure tofu plan shows no changes.
- Download whatever you want to keep from the S3 buckets, above all backups.database.<hosted zone> and backups.files.<hosted zone>. Once they're gone, so are the backups of every project.
1. Switch to a temporary user
Uninstalling deletes all IAM users that Hosty created, including yours. So you need an IAM user that isn't managed by Hosty, like when you applied the blueprint.
- In the AWS Console, open IAM > Users and click Create user. Enter any name, for example temp.admin.
- On Set permissions, choose Attach policies directly, select AdministratorAccess, and create the user.
- Open the user, go to Security credentials > Access keys, and create an access key with the use case Other.
- In the Hosty container (make cli), save the key as a separate profile and use it in this shell:
aws configure --profile=hosty.temp
export AWS_PROFILE=hosty.tempRun all the following commands in this shell.
2. Clean up the IAM users
OpenTofu can't delete an IAM user that has a console password, an MFA device or access keys. For every user in users of main.tf, open IAM > Users > the user > Security credentials, and:
- disable console access;
- remove the MFA devices;
- delete the access keys.
3. Move the state back to your computer
The state of OpenTofu is in the S3 bucket and the DynamoDB table that you are about to delete, so it has to move to a local file first.
- In terraform/main.tf, comment out the backend "s3" block.
- Move the state, and answer yes when OpenTofu asks to copy it:
cd /src/terraform
tofu init -migrate-state- The state is now in terraform/terraform.tfstate. Don't delete it until the end.
- In the AWS Console, open DynamoDB > Tables > tf-remote-state-lock, and turn off deletion protection (Actions > Turn off deletion protection).
4. Empty the S3 buckets
OpenTofu doesn't delete a bucket with files in it, so that data isn't lost by mistake. Only the logs bucket is emptied automatically. In S3, empty these buckets with the Empty button, which also removes the previous versions of files:
- tfstate.<hosted zone>, the old copy of the state;
- backups.database.<hosted zone>;
- backups.files.<hosted zone>;
- vpn.<hosted zone>, if anything is left in it.
5. Uninstall
tofu destroyCheck the list of resources and type yes to confirm.
If it fails on the Route53 zone, the zone still has records that OpenTofu didn't create. Delete them in Route53 and run tofu destroy again.
6. Clean up
- Remove the name servers of the deleted Route53 zone from the registrar of your domain, or from the DNS of the parent domain.
- Sign in to the AWS Console as the root user and delete the temporary user.
- Remove the [hosty.temp] section from ~/.aws/credentials and the [profile hosty.temp] section from ~/.aws/config on your computer.
- Delete the local terraform/terraform.tfstate.