Recovering Terraform State

Uh oh.

So you made a typo and terraform rm'd the wrong resource. Or you accidentally deleted S3 bucket terraform-111111011 instead of terraform-10111111 and your entire Terraform state is lost. It's ok! We've all done it, and there's a way out.

Using terraform import

All Sym Terraform resources include support for the terraform import command.

📘

Note: this requires Sym Terraform provider v1.10.0 or greater

There are two types of imports:

  1. Import by name (slug) – used if the resource has no type field
  2. Import by name (slug) and type – used if the resource has a type field

For example, if you have a sym_environment and a sym_integration:

resource "sym_environment" "this" {
  name                = "prod"
  runtime_id          = sym_runtime.other.id

  integrations = {
    slack_id = sym_integration.this.id
  }
}

resource "sym_integration" "this" {
  type        = "slack"
  name        = "prod-workspace"
  external_id = "T12345"
}

Then those resources could be imported with the following commands:

$ terraform import sym_environment.this prod
$ terraform import sym_integration.this slack:prod-workspace

📘

Not sure what slug to use?

Some resources, like sym_secret, have autogenerated slugs that won't be defined in Terraform. For these resources, you can list them and their slugs using the symflow CLI.

Below are all Sym resources and a template command showing how to import each one:

ResourceImport Format
sym_environmentterraform import sym_environment.TERRAFORM_NAME SLUG
sym_error_loggerterraform import sym_error_logger.TERRAFORM_NAME SLUG
sym_flowterraform import sym_flow.TERRAFORM_NAME SLUG
sym_integrationterraform import sym_integration.TERRAFORM_NAME TYPE:SLUG
sym_log_destinationterraform import sym_log_destination.TERRAFORM_NAME TYPE:SLUG
sym_runtimeterraform import sym_runtime.TERRAFORM_NAME SLUG
sym_secretterraform import sym_secret.TERRAFORM_NAME SLUG
sym_secretsterraform import sym_secrets.TERRAFORM_NAME TYPE:SLUG
sym_strategyterraform import sym_strategy.TERRAFORM_NAME TYPE:SLUG
sym_targetterraform import sym_target.TERRAFORM_NAME TYPE:SLUG