Search code examples
terraform

How to list resources when using remote state?


I am using terraform 0.12.9 and state is saved on s3 bucket. I'd like to list all resources by terraform state list. Based on this document, https://www.terraform.io/docs/commands/state/list.html, it says -state=path - Path to the state file. Defaults to "terraform.tfstate". Ignored when remote state is used.. How can I pass the state file if it is on remote s3 bucket?


Solution

  • You need to configure the tfstate bucket path in your terraform.tf file:

    terraform {
      backend "s3" {
        bucket = "bucket_name"
        key    = "my/key/location/terraform.tfstate"
        region = "bucket region"
      }
    }
    

    and later you need to run terraform init so that terraform would fetch the state from the remote bucket