Can terraform save the state file both remotely and locally

Hi team,

Could you please tell me whether I can save the state file both remotely and locally? I made a try but gave me an error:

terraform {
  backend "local" {
    path = "/data/terraform.tfstate"
  backend "oss" {
    bucket = "xxx"
    prefix   = "xxx"
    key   = "version-1.tfstate"
    region = "xxx"

No, Terraform does not offer this feature.

You would have to store it remotely and additionally fetch a copy yourself outside of Terraform.

One way to fetch a local copy after a run would be to run a command like this:

terraform state pull >example.tfstate

This retrieves the latest state snapshot in Terraform’s internal format, so anything reading this file should treat is as opaque data whose format is subject to change in future versions of Terraform.

If you instead want to use this data as input to some other software, you can ask Terraform to emit its documented external integration format:

terraform show -json
1 Like