How can I automatically copy terraform state to local after run terraform apply

My terraform state stored in gcs bucket by default, how can I automatically copy the terraform state locally after run terraform apply, I know we could use terraform state pull command to pull the state, but I don’t want to send the request to gcs bucket again, is there other solution ?

Hi @shufanhao
What are you trying to achieve? Is this for backup purposes, or to enable you to also execute under a ‘local development’ scenario with the state, or something else?

If it is for backup/DR purposes then terraform state pull is appropriate, as would be just copying the bucket contents offline via another backup method.

If it is for ‘local development’ purposes then it is likely a partial backend configuration and using the -backend-config option or command-line key/value pairs during the local init is a better approach. This way the state remains in your bucket and is updated directly - rather than copying or pushing/pulling the state around between a local file system and the remove backend.

Hope that helps

Happy Terraforming