Route /images to an S3 Bucket using Terraform
Route requests with a URI path starting with /images
to a specific AWS S3 bucket with Cloud Connector using Terraform.
The following example defines a single Cloud Connector rule for a zone using Terraform. The rule routes requests to /images
on your domain to an AWS S3 bucket.
resource "cloudflare_cloud_connector_rules" "serve_images_in_aws" { zone_id = "<ZONE_ID>" rules { description = "Route images to AWS S3 bucket" enabled = true expression = "http.request.full_uri wildcard \"https://<YOUR_HOSTNAME>/images/*\"" provider = "aws_s3" parameters { host = "<BUCKET_NAME>.s3.amazonaws.com" } }}
For additional guidance on using Terraform with Cloudflare, refer to the following resources:
- Terraform documentation
- Cloudflare Provider for Terraform ↗ (reference documentation)