Skip to content

Instantly share code, notes, and snippets.

@cmackenzie1
Last active May 11, 2022 17:55
Show Gist options
  • Save cmackenzie1/a6370c189b4f9d6d4e5d0fdc1d6ce8dc to your computer and use it in GitHub Desktop.
Save cmackenzie1/a6370c189b4f9d6d4e5d0fdc1d6ce8dc to your computer and use it in GitHub Desktop.
Cloudflare + Terraform example for configuring Logpush Jobs to R2. https://developers.cloudflare.com/logs/get-started/enable-destinations/r2/
# https://developers.cloudflare.com/logs/get-started/enable-destinations/r2/
data "cloudflare_api_token_permission_groups" "all" {
resource "cloudflare_api_token" "logpush_r2_token" {
name = "logpush_r2_token"
policy {
permission_groups = [
data.cloudflare_api_token_permission_groups.all.permissions["Workers R2 Storage Write"],
]
resources = {
"com.cloudflare.api.account.*" = "*"
}
}
}
resource "cloudflare_logpush_job" "http_requests" {
enabled = true
zone_id = var.zone_id
name = "http_requests"
logpull_options = "fields=ClientIP,ClientRequestHost,ClientRequestMethod,ClientRequestURI,EdgeEndTimestamp,EdgeResponseBytes,EdgeResponseStatus,EdgeStartTimestamp,RayID&timestamps=rfc3339"
destination_conf = "r2://cloudflare-logs/http_requests/date={DATE}?account-id=${var.account_id}&access-key-id=${cloudflare_api_token.logpush_r2_token.id}&secret-access-key=${sha256(cloudflare_api_token.logpush_r2_token.value)}"
dataset = "http_requests"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment