If I store Terraform state locally, then I delete the local .tfstate files, Terraform won’t know what resources I’ve created in AWS/other providers. I actually experienced this while I was setting up my Terraform workstation with Ansible. I hadn’t setup a terraform destroy step before deleting an instance and ended up needing to delete some VPCs in the AWS console, which is a bit of a slog!

I wanted to manage my state somewhere else, so I decided to try an account on Hashicorp. After creating an account, organization, and CLI workspace, grabbed the provided backend code and an API key and copied them into my Terraform setup.

This backend code goes into backends.tf:

terraform {
  cloud {
    organization = "sd-test-org"

    workspaces {
      name = "test-workspace"
    }
  }
}

And I logged into Terraform with:

terraform login

…which allowed me to enter my API key. The key is plaintext, but I have good control over this instance.