1--- 2layout: "language" 3page_title: "Backend Type: cos" 4sidebar_current: "docs-backends-types-standard-cos" 5description: |- 6 Terraform can store the state remotely, making it easier to version and work with in a team. 7--- 8 9# COS 10 11**Kind: Standard (with locking)** 12 13Stores the state as an object in a configurable prefix in a given bucket on [Tencent Cloud Object Storage](https://intl.cloud.tencent.com/product/cos) (COS). 14This backend also supports [state locking](/docs/language/state/locking.html). 15 16~> **Warning!** It is highly recommended that you enable [Object Versioning](https://intl.cloud.tencent.com/document/product/436/19883) 17on the COS bucket to allow for state recovery in the case of accidental deletions and human error. 18 19## Example Configuration 20 21```hcl 22terraform { 23 backend "cos" { 24 region = "ap-guangzhou" 25 bucket = "bucket-for-terraform-state-1258798060" 26 prefix = "terraform/state" 27 } 28} 29``` 30 31This assumes we have a [COS Bucket](https://registry.terraform.io/providers/tencentcloudstack/tencentcloud/latest/docs/resources/cos_bucket) created named `bucket-for-terraform-state-1258798060`, 32Terraform state will be written into the file `terraform/state/terraform.tfstate`. 33 34## Data Source Configuration 35 36To make use of the COS remote state in another configuration, use the [`terraform_remote_state` data source](/docs/language/state/remote-state-data.html). 37 38```hcl 39data "terraform_remote_state" "foo" { 40 backend = "cos" 41 42 config = { 43 region = "ap-guangzhou" 44 bucket = "bucket-for-terraform-state-1258798060" 45 prefix = "terraform/state" 46 } 47} 48``` 49 50## Configuration variables 51 52The following configuration options or environment variables are supported: 53 54 * `secret_id` - (Optional) Secret id of Tencent Cloud. It supports environment variables `TENCENTCLOUD_SECRET_ID`. 55 * `secret_key` - (Optional) Secret key of Tencent Cloud. It supports environment variables `TENCENTCLOUD_SECRET_KEY`. 56 * `region` - (Optional) The region of the COS bucket. It supports environment variables `TENCENTCLOUD_REGION`. 57 * `bucket` - (Required) The name of the COS bucket. You shall manually create it first. 58 * `prefix` - (Optional) The directory for saving the state file in bucket. Default to "env:". 59 * `key` - (Optional) The path for saving the state file in bucket. Defaults to `terraform.tfstate`. 60 * `encrypt` - (Optional) Whether to enable server side encryption of the state file. If it is true, COS will use 'AES256' encryption algorithm to encrypt state file. 61 * `acl` - (Optional) Object ACL to be applied to the state file, allows `private` and `public-read`. Defaults to `private`. 62