Skip to content

Remote State with Cloudflare R2

The following is an example of how to use Cloudflare R2 as a remote state backend for Terraform. This allows you to store your Terraform state files in Cloudflare's object storage service, providing durability and accessibility.

hcl
terraform {
  backend "s3" {
    bucket = "<BUCKET_NAME>"
    key    = "<UNIQUE_APP>/terraform.tfstate"

    endpoints = {
      s3 = "https://<BUCKET_ID>.r2.cloudflarestorage.com"
    }

    region                      = "auto"
    skip_credentials_validation = true
    skip_metadata_api_check     = true
    skip_region_validation      = true
    skip_requesting_account_id  = true
    skip_s3_checksum            = true
    use_path_style              = true
  }
}