Skip to content

googleComputeBackendBucket

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:

Example Usage - Backend Bucket Basic

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleStorageBucketImageBucket = new google.storageBucket.StorageBucket(
  this,
  "image_bucket",
  {
    location: "EU",
    name: "image-store-bucket",
  }
);
new google.computeBackendBucket.ComputeBackendBucket(this, "image_backend", {
  bucket_name: googleStorageBucketImageBucket.name,
  description: "Contains beautiful images",
  enable_cdn: true,
  name: "image-backend-bucket",
});

Example Usage - Backend Bucket Security Policy

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleComputeSecurityPolicyPolicy =
  new google.computeSecurityPolicy.ComputeSecurityPolicy(this, "policy", {
    description: "basic security policy",
    name: "image-store-bucket",
    type: "CLOUD_ARMOR_EDGE",
  });
const googleStorageBucketImageBackend = new google.storageBucket.StorageBucket(
  this,
  "image_backend",
  {
    location: "EU",
    name: "image-store-bucket",
  }
);
const googleComputeBackendBucketImageBackend =
  new google.computeBackendBucket.ComputeBackendBucket(
    this,
    "image_backend_2",
    {
      bucket_name: googleStorageBucketImageBackend.name,
      description: "Contains beautiful images",
      edge_security_policy: googleComputeSecurityPolicyPolicy.id,
      enable_cdn: true,
      name: "image-backend-bucket",
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
googleComputeBackendBucketImageBackend.overrideLogicalId("image_backend");

Example Usage - Backend Bucket Query String Whitelist

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleStorageBucketImageBucket = new google.storageBucket.StorageBucket(
  this,
  "image_bucket",
  {
    location: "EU",
    name: "image-backend-bucket",
  }
);
new google.computeBackendBucket.ComputeBackendBucket(this, "image_backend", {
  bucket_name: googleStorageBucketImageBucket.name,
  cdn_policy: [
    {
      cache_key_policy: [
        {
          query_string_whitelist: ["image-version"],
        },
      ],
    },
  ],
  description: "Contains beautiful images",
  enable_cdn: true,
  name: "image-backend-bucket",
});

Example Usage - Backend Bucket Include Http Headers

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleStorageBucketImageBucket = new google.storageBucket.StorageBucket(
  this,
  "image_bucket",
  {
    location: "EU",
    name: "image-backend-bucket",
  }
);
new google.computeBackendBucket.ComputeBackendBucket(this, "image_backend", {
  bucket_name: googleStorageBucketImageBucket.name,
  cdn_policy: [
    {
      cache_key_policy: [
        {
          include_http_headers: ["X-My-Header-Field"],
        },
      ],
    },
  ],
  description: "Contains beautiful images",
  enable_cdn: true,
  name: "image-backend-bucket",
});

Argument Reference

The following arguments are supported:

  • bucketName - (Required) Cloud Storage bucket name.

  • name - (Required) Name of the resource. Provided by the client when the resource is created. The name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular expression [aZ]([AZ09]*[aZ09])? which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash.


  • cdnPolicy - (Optional) Cloud CDN configuration for this Backend Bucket. Structure is documented below.

  • compressionMode - (Optional) Compress text responses using Brotli or gzip compression, based on the client's Accept-Encoding header. Possible values are automatic and disabled.

  • edgeSecurityPolicy - (Optional) The security policy associated with this backend bucket.

  • customResponseHeaders - (Optional) Headers that the HTTP/S load balancer should add to proxied responses.

  • description - (Optional) An optional textual description of the resource; provided by the client when the resource is created.

  • enableCdn - (Optional) If true, enable Cloud CDN for this BackendBucket.

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

The cdnPolicy block supports:

  • cacheKeyPolicy - (Optional) The CacheKeyPolicy for this CdnPolicy. Structure is documented below.

  • signedUrlCacheMaxAgeSec - (Optional) Maximum number of seconds the response to a signed URL request will be considered fresh. After this time period, the response will be revalidated before being served. When serving responses to signed URL requests, Cloud CDN will internally behave as though all responses from this backend had a "Cache-Control: public, max-age=[TTL]" header, regardless of any existing Cache-Control header. The actual headers served in responses will not be altered.

  • defaultTtl - (Optional) Specifies the default TTL for cached content served by this origin for responses that do not have an existing valid TTL (max-age or s-max-age).

  • maxTtl - (Optional) Specifies the maximum allowed TTL for cached content served by this origin.

  • clientTtl - (Optional) Specifies the maximum allowed TTL for cached content served by this origin.

  • negativeCaching - (Optional) Negative caching allows per-status code TTLs to be set, in order to apply fine-grained caching for common errors or redirects.

  • negativeCachingPolicy - (Optional) Sets a cache TTL for the specified HTTP status code. negativeCaching must be enabled to configure negativeCachingPolicy. Omitting the policy and leaving negativeCaching enabled will use Cloud CDN's default cache TTLs. Structure is documented below.

  • cacheMode - (Optional) Specifies the cache setting for all responses from this backend. The possible values are: USE_ORIGIN_HEADERS, FORCE_CACHE_ALL and CACHE_ALL_STATIC Possible values are useOriginHeaders, forceCacheAll, and cacheAllStatic.

  • serveWhileStale - (Optional) Serve existing content from the cache (if available) when revalidating content with the origin, or when an error is encountered when refreshing the cache.

  • requestCoalescing - (Optional) If true then Cloud CDN will combine multiple concurrent cache fill requests into a small number of requests to the origin.

  • bypassCacheOnRequestHeaders - (Optional) Bypass the cache when the specified request headers are matched - e.g. Pragma or Authorization headers. Up to 5 headers can be specified. The cache is bypassed for all cdnPolicy.cacheMode settings. Structure is documented below.

The cacheKeyPolicy block supports:

  • queryStringWhitelist - (Optional) Names of query string parameters to include in cache keys. Default parameters are always included. '&' and '=' will be percent encoded and not treated as delimiters.

  • includeHttpHeaders - (Optional) Allows HTTP request headers (by name) to be used in the cache key.

The negativeCachingPolicy block supports:

  • code - (Optional) The HTTP status code to define a TTL against. Only HTTP status codes 300, 301, 308, 404, 405, 410, 421, 451 and 501 can be specified as values, and you cannot specify a status code more than once.

  • ttl - (Optional) The TTL (in seconds) for which to cache responses with the corresponding status code. The maximum allowed value is 1800s (30 minutes), noting that infrequently accessed objects may be evicted from the cache before the defined TTL.

The bypassCacheOnRequestHeaders block supports:

  • headerName - (Optional) The header field name to match on when bypassing cache. Values are case-insensitive.

Attributes Reference

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

  • id - an identifier for the resource with format projects/{{project}}/global/backendBuckets/{{name}}

  • creationTimestamp - Creation timestamp in RFC3339 text format.

  • selfLink - The URI of the created resource.

Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 20 minutes.
  • update - Default is 20 minutes.
  • delete - Default is 20 minutes.

Import

BackendBucket can be imported using any of these accepted formats:

$ 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.