google_compute_backend_bucket

Backend buckets allow you to use Google Cloud Storage buckets with HTTP(S) load balancing.

An HTTP(S) load balancer can direct traffic to specified URLs to a backend bucket rather than a backend service. It can send requests for static content to a Cloud Storage bucket and requests for dynamic content to a virtual machine instance.

To get more information about BackendBucket, see:

Open in Cloud Shell

Example Usage - Backend Bucket Basic

resource "google_compute_backend_bucket" "image_backend" {
  name        = "image-backend-bucket"
  description = "Contains beautiful images"
  bucket_name = google_storage_bucket.image_bucket.name
  enable_cdn  = true
}

resource "google_storage_bucket" "image_bucket" {
  name     = "image-store-bucket"
  location = "EU"
}
Open in Cloud Shell

Example Usage - Backend Bucket Security Policy

resource "google_compute_backend_bucket" "image_backend" {
  name        = "image-backend-bucket"
  description = "Contains beautiful images"
  bucket_name = google_storage_bucket.image_backend.name
  enable_cdn  = true
  edge_security_policy = google_compute_security_policy.policy.id
}

resource "google_storage_bucket" "image_backend" {
  name     = "image-store-bucket"
  location = "EU"
}

resource "google_compute_security_policy" "policy" {
  name        = "image-store-bucket"
  description = "basic security policy"
    type = "CLOUD_ARMOR_EDGE"
}
Open in Cloud Shell

Example Usage - Backend Bucket Query String Whitelist

resource "google_compute_backend_bucket" "image_backend" {
  name        = "image-backend-bucket"
  description = "Contains beautiful images"
  bucket_name = google_storage_bucket.image_bucket.name
  enable_cdn  = true
  cdn_policy {
    cache_key_policy {
        query_string_whitelist = ["image-version"]
    }
  }
}

resource "google_storage_bucket" "image_bucket" {
  name     = "image-backend-bucket"
  location = "EU"
}
Open in Cloud Shell

Example Usage - Backend Bucket Include Http Headers

resource "google_compute_backend_bucket" "image_backend" {
  name        = "image-backend-bucket"
  description = "Contains beautiful images"
  bucket_name = google_storage_bucket.image_bucket.name
  enable_cdn  = true
  cdn_policy {
    cache_key_policy {
        include_http_headers = ["X-My-Header-Field"]
    }
  }
}

resource "google_storage_bucket" "image_bucket" {
  name     = "image-backend-bucket"
  location = "EU"
}

Argument Reference

The following arguments are supported:


The cdn_policy block supports:

The cache_key_policy block supports:

The negative_caching_policy block supports:

The bypass_cache_on_request_headers block supports:

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

Timeouts

This resource provides the following Timeouts configuration options:

Import

BackendBucket can be imported using any of these accepted formats:

In Terraform v1.5.0 and later, use an import block to import BackendBucket using one of the formats above. For example:

import {
  id = "projects/{{project}}/global/backendBuckets/{{name}}"
  to = google_compute_backend_bucket.default
}

When using the terraform import command, BackendBucket can be imported using one of the formats above. For example:

$ terraform import google_compute_backend_bucket.default projects/{{project}}/global/backendBuckets/{{name}}
$ terraform import google_compute_backend_bucket.default {{project}}/{{name}}
$ terraform import google_compute_backend_bucket.default {{name}}

User Project Overrides

This resource supports User Project Overrides.