github.com/eliastor/durgaform@v0.0.0-20220816172711-d0ab2d17673e/website/docs/language/settings/backends/cos.mdx (about) 1 --- 2 page_title: 'Backend Type: cos' 3 description: >- 4 Terraform can store the state remotely, making it easier to version and work 5 with in a team. 6 --- 7 8 # COS 9 10 Stores 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). 11 12 This backend supports [state locking](/language/state/locking). 13 14 ~> **Warning!** It is highly recommended that you enable [Object Versioning](https://intl.cloud.tencent.com/document/product/436/19883) 15 on the COS bucket to allow for state recovery in the case of accidental deletions and human error. 16 17 ## Example Configuration 18 19 ```hcl 20 terraform { 21 backend "cos" { 22 region = "ap-guangzhou" 23 bucket = "bucket-for-terraform-state-1258798060" 24 prefix = "terraform/state" 25 } 26 } 27 ``` 28 29 This 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`, 30 Terraform state will be written into the file `terraform/state/terraform.tfstate`. 31 32 ## Data Source Configuration 33 34 To make use of the COS remote state in another configuration, use the [`terraform_remote_state` data source](/language/state/remote-state-data). 35 36 ```hcl 37 data "terraform_remote_state" "foo" { 38 backend = "cos" 39 40 config = { 41 region = "ap-guangzhou" 42 bucket = "bucket-for-terraform-state-1258798060" 43 prefix = "terraform/state" 44 } 45 } 46 ``` 47 48 ## Configuration Variables 49 50 !> **Warning:** We recommend using environment variables to supply credentials and other sensitive data. If you use `-backend-config` or hardcode these values directly in your configuration, Terraform will include these values in both the `.terraform` subdirectory and in plan files. Refer to [Credentials and Sensitive Data](/language/settings/backends/configuration#credentials-and-sensitive-data) for details. 51 52 The 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`.