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
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:
- Import by name (slug) – used if the resource has no
type
field - 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 thesymflow
CLI.
Below are all Sym resources and a template command showing how to import each one:
Resource | Import Format |
---|---|
sym_environment | terraform import sym_environment.TERRAFORM_NAME SLUG |
sym_error_logger | terraform import sym_error_logger.TERRAFORM_NAME SLUG |
sym_flow | terraform import sym_flow.TERRAFORM_NAME SLUG |
sym_integration | terraform import sym_integration.TERRAFORM_NAME TYPE:SLUG |
sym_log_destination | terraform import sym_log_destination.TERRAFORM_NAME TYPE:SLUG |
sym_runtime | terraform import sym_runtime.TERRAFORM_NAME SLUG |
sym_secret | terraform import sym_secret.TERRAFORM_NAME SLUG |
sym_secrets | terraform import sym_secrets.TERRAFORM_NAME TYPE:SLUG |
sym_strategy | terraform import sym_strategy.TERRAFORM_NAME TYPE:SLUG |
sym_target | terraform import sym_target.TERRAFORM_NAME TYPE:SLUG |
Updated about 1 year ago