Skip to content

googleNetworkServicesEdgeCacheService

EdgeCacheService defines the IP addresses, protocols, security policies, cache policies and routing configuration.

\~> Warning: These resources require allow-listing to use, and are not openly available to all Cloud customers. Engage with your Cloud account team to discuss how to onboard.

Example Usage - Network Services Edge Cache Service 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 googleStorageBucketDest = new google.storageBucket.StorageBucket(
  this,
  "dest",
  {
    force_destroy: true,
    location: "US",
    name: "my-bucket",
  }
);
const googleNetworkServicesEdgeCacheOriginInstance =
  new google.networkServicesEdgeCacheOrigin.NetworkServicesEdgeCacheOrigin(
    this,
    "instance",
    {
      description: "The default bucket for media edge test",
      max_attempts: 2,
      name: "my-origin",
      origin_address: googleStorageBucketDest.url,
      timeout: [
        {
          connect_timeout: "10s",
        },
      ],
    }
  );
const googleNetworkServicesEdgeCacheServiceInstance =
  new google.networkServicesEdgeCacheService.NetworkServicesEdgeCacheService(
    this,
    "instance_2",
    {
      description: "some description",
      name: "my-service",
      routing: [
        {
          host_rule: [
            {
              description: "host rule description",
              hosts: ["sslcert.tf-test.club"],
              path_matcher: "routes",
            },
          ],
          path_matcher: [
            {
              name: "routes",
              route_rule: [
                {
                  description: "a route rule to match against",
                  header_action: [
                    {
                      response_header_to_add: [
                        {
                          header_name: "x-cache-status",
                          header_value: "{cdn_cache_status}",
                        },
                      ],
                    },
                  ],
                  match_rule: [
                    {
                      prefix_match: "/",
                    },
                  ],
                  origin: googleNetworkServicesEdgeCacheOriginInstance.name,
                  priority: 1,
                  route_action: [
                    {
                      cdn_policy: [
                        {
                          cache_mode: "CACHE_ALL_STATIC",
                          default_ttl: "3600s",
                        },
                      ],
                    },
                  ],
                },
              ],
            },
          ],
        },
      ],
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
googleNetworkServicesEdgeCacheServiceInstance.overrideLogicalId("instance");

Example Usage - Network Services Edge Cache Service Advanced

/*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.*/
new google.networkServicesEdgeCacheOrigin.NetworkServicesEdgeCacheOrigin(
  this,
  "google",
  {
    description: "The default bucket for media edge test",
    max_attempts: 2,
    name: "origin-google",
    origin_address: "google.com",
    timeout: [
      {
        connect_timeout: "10s",
      },
    ],
  }
);
const googleStorageBucketDest = new google.storageBucket.StorageBucket(
  this,
  "dest",
  {
    force_destroy: true,
    location: "US",
    name: "my-bucket",
  }
);
const googleNetworkServicesEdgeCacheOriginInstance =
  new google.networkServicesEdgeCacheOrigin.NetworkServicesEdgeCacheOrigin(
    this,
    "instance",
    {
      description: "The default bucket for media edge test",
      max_attempts: 2,
      name: "my-origin",
      origin_address: googleStorageBucketDest.url,
      timeout: [
        {
          connect_timeout: "10s",
        },
      ],
    }
  );
const googleNetworkServicesEdgeCacheServiceInstance =
  new google.networkServicesEdgeCacheService.NetworkServicesEdgeCacheService(
    this,
    "instance_3",
    {
      description: "some description",
      disable_http2: true,
      disable_quic: true,
      labels: [
        {
          a: "b",
        },
      ],
      log_config: [
        {
          enable: true,
          sample_rate: 0.01,
        },
      ],
      name: "my-service",
      routing: [
        {
          host_rule: [
            {
              description: "host rule description",
              hosts: ["sslcert.tf-test.club"],
              path_matcher: "routes",
            },
            {
              description: "host rule2",
              hosts: ["sslcert.tf-test2.club"],
              path_matcher: "routes",
            },
            {
              description: "host rule3",
              hosts: ["sslcert.tf-test3.club"],
              path_matcher: "routesAdvanced",
            },
          ],
          path_matcher: [
            {
              name: "routes",
              route_rule: [
                {
                  description: "a route rule to match against",
                  header_action: [
                    {
                      response_header_to_add: [
                        {
                          header_name: "x-cache-status",
                          header_value: "{cdn_cache_status}",
                        },
                      ],
                    },
                  ],
                  match_rule: [
                    {
                      prefix_match: "/",
                    },
                  ],
                  origin: googleNetworkServicesEdgeCacheOriginInstance.name,
                  priority: 1,
                  route_action: [
                    {
                      cdn_policy: [
                        {
                          cache_mode: "CACHE_ALL_STATIC",
                          default_ttl: "3600s",
                        },
                      ],
                    },
                  ],
                },
              ],
            },
            {
              description: "an advanced ruleset",
              name: "routesAdvanced",
              route_rule: [
                {
                  description: "an advanced route rule to match against",
                  header_action: [
                    {
                      request_header_to_add: [
                        {
                          header_name: "debug",
                          header_value: "true",
                          replace: true,
                        },
                        {
                          header_name: "potato",
                          header_value: "plant",
                        },
                      ],
                      request_header_to_remove: [
                        {
                          header_name: "prod",
                        },
                      ],
                      response_header_to_add: [
                        {
                          header_name: "potato",
                          header_value: "plant",
                          replace: true,
                        },
                      ],
                      response_header_to_remove: [
                        {
                          header_name: "prod",
                        },
                      ],
                    },
                  ],
                  match_rule: [
                    {
                      prefix_match: "/potato/",
                      query_parameter_match: [
                        {
                          name: "debug",
                          present_match: true,
                        },
                        {
                          exact_match: "debug",
                          name: "state",
                        },
                      ],
                    },
                    {
                      full_path_match: "/apple",
                    },
                  ],
                  origin: googleNetworkServicesEdgeCacheOriginInstance.name,
                  priority: 1,
                  route_action: [
                    {
                      cdn_policy: [
                        {
                          cache_key_policy: [
                            {
                              exclude_host: true,
                              include_protocol: true,
                              included_cookie_names: ["orange"],
                              included_header_names: ["banana"],
                              included_query_parameters: [
                                "apple",
                                "dev",
                                "santa",
                                "claus",
                              ],
                            },
                          ],
                          cache_mode: "CACHE_ALL_STATIC",
                          client_ttl: "3600s",
                          default_ttl: "3800s",
                          max_ttl: "9000s",
                          negative_caching: true,
                          negative_caching_policy: [
                            {
                              500: "3000s",
                            },
                          ],
                          signed_request_mode: "DISABLED",
                        },
                      ],
                      cors_policy: [
                        {
                          allow_credentials: true,
                          allow_headers: ["dev"],
                          allow_methods: ["GET"],
                          allow_origins: ["*"],
                          expose_headers: ["prod"],
                          max_age: "2500s",
                        },
                      ],
                      url_rewrite: [
                        {
                          host_rewrite: "dev.club",
                          path_prefix_rewrite: "/dev",
                        },
                      ],
                    },
                  ],
                },
                {
                  description: "a second route rule to match against",
                  match_rule: [
                    {
                      full_path_match: "/yay",
                    },
                  ],
                  origin: googleNetworkServicesEdgeCacheOriginInstance.name,
                  priority: 2,
                  route_action: [
                    {
                      cdn_policy: [
                        {
                          cache_key_policy: [
                            {
                              excluded_query_parameters: ["dev"],
                            },
                          ],
                          cache_mode: "CACHE_ALL_STATIC",
                          default_ttl: "3600s",
                        },
                      ],
                      cors_policy: [
                        {
                          allow_headers: ["dev"],
                          disabled: true,
                          max_age: "3000s",
                        },
                      ],
                    },
                  ],
                },
              ],
            },
          ],
        },
      ],
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
googleNetworkServicesEdgeCacheServiceInstance.overrideLogicalId("instance");

Example Usage - Network Services Edge Cache Service Dual Token

/*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 googleNetworkServicesEdgeCacheOriginInstance =
  new google.networkServicesEdgeCacheOrigin.NetworkServicesEdgeCacheOrigin(
    this,
    "instance",
    {
      description: "The default bucket for media edge test",
      name: "my-origin",
      origin_address: "gs://media-edge-default",
    }
  );
const googleSecretManagerSecretSecretBasic =
  new google.secretManagerSecret.SecretManagerSecret(this, "secret-basic", {
    replication: [
      {
        automatic: true,
      },
    ],
    secret_id: "secret-name",
  });
const googleSecretManagerSecretVersionSecretVersionBasic =
  new google.secretManagerSecretVersion.SecretManagerSecretVersion(
    this,
    "secret-version-basic",
    {
      secret: googleSecretManagerSecretSecretBasic.id,
      secret_data: "secret-data",
    }
  );
const googleNetworkServicesEdgeCacheKeysetKeyset =
  new google.networkServicesEdgeCacheKeyset.NetworkServicesEdgeCacheKeyset(
    this,
    "keyset",
    {
      description: "The default keyset",
      name: "keyset-name",
      public_key: [
        {
          id: "my-public-key",
          managed: true,
        },
      ],
      validation_shared_keys: [
        {
          secret_version: googleSecretManagerSecretVersionSecretVersionBasic.id,
        },
      ],
    }
  );
const googleNetworkServicesEdgeCacheServiceInstance =
  new google.networkServicesEdgeCacheService.NetworkServicesEdgeCacheService(
    this,
    "instance_4",
    {
      description: "some description",
      name: "my-service",
      routing: [
        {
          host_rule: [
            {
              description: "host rule description",
              hosts: ["sslcert.tf-test.club"],
              path_matcher: "routes",
            },
          ],
          path_matcher: [
            {
              name: "routes",
              route_rule: [
                {
                  description: "a route rule to match against master playlist",
                  match_rule: [
                    {
                      path_template_match: "/master.m3u8",
                    },
                  ],
                  origin: googleNetworkServicesEdgeCacheOriginInstance.name,
                  priority: 1,
                  route_action: [
                    {
                      cdn_policy: [
                        {
                          add_signatures: [
                            {
                              actions: ["GENERATE_COOKIE"],
                              copied_parameters: ["PathGlobs", "SessionID"],
                              keyset:
                                googleNetworkServicesEdgeCacheKeysetKeyset.id,
                            },
                          ],
                          signed_request_keyset:
                            googleNetworkServicesEdgeCacheKeysetKeyset.id,
                          signed_request_maximum_expiration_ttl: "600s",
                          signed_request_mode: "REQUIRE_TOKENS",
                          signed_token_options: [
                            {
                              token_query_parameter: "edge-cache-token",
                            },
                          ],
                        },
                      ],
                    },
                  ],
                },
                {
                  description: "a route rule to match against all playlists",
                  match_rule: [
                    {
                      path_template_match: "/*.m3u8",
                    },
                  ],
                  origin: googleNetworkServicesEdgeCacheOriginInstance.name,
                  priority: 2,
                  route_action: [
                    {
                      cdn_policy: [
                        {
                          add_signatures: [
                            {
                              actions: ["GENERATE_TOKEN_HLS_COOKIELESS"],
                              copied_parameters: ["URLPrefix"],
                              keyset:
                                googleNetworkServicesEdgeCacheKeysetKeyset.id,
                              token_query_parameter: "hdntl",
                              token_ttl: "1200s",
                            },
                          ],
                          signed_request_keyset:
                            googleNetworkServicesEdgeCacheKeysetKeyset.id,
                          signed_request_mode: "REQUIRE_TOKENS",
                          signed_token_options: [
                            {
                              allowed_signature_algorithms: [
                                "ED25519",
                                "HMAC_SHA_256",
                                "HMAC_SHA1",
                              ],
                              token_query_parameter: "hdnts",
                            },
                          ],
                        },
                      ],
                    },
                  ],
                },
                {
                  description: "a route rule to match against",
                  match_rule: [
                    {
                      path_template_match: "/**.m3u8",
                    },
                  ],
                  origin: googleNetworkServicesEdgeCacheOriginInstance.name,
                  priority: 3,
                  route_action: [
                    {
                      cdn_policy: [
                        {
                          add_signatures: [
                            {
                              actions: ["PROPAGATE_TOKEN_HLS_COOKIELESS"],
                              token_query_parameter: "hdntl",
                            },
                          ],
                          signed_request_keyset:
                            googleNetworkServicesEdgeCacheKeysetKeyset.id,
                          signed_request_mode: "REQUIRE_TOKENS",
                          signed_token_options: [
                            {
                              token_query_parameter: "hdntl",
                            },
                          ],
                        },
                      ],
                    },
                  ],
                },
              ],
            },
          ],
        },
      ],
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
googleNetworkServicesEdgeCacheServiceInstance.overrideLogicalId("instance");

Argument Reference

The following arguments are supported:

  • routing - (Required) Defines how requests are routed, modified, cached and/or which origin content is filled from. Structure is documented below.

  • name - (Required) Name of the resource; provided by the client when the resource is created. The name must be 1-64 characters long, and match the regular expression [a-zA-Z][a-zA-Z0-9_-]* which means the first character must be a letter, and all following characters must be a dash, underscore, letter or digit.

The routing block supports:

  • hostRule - (Required) The list of hostRules to match against. These rules define which hostnames the EdgeCacheService will match against, and which route configurations apply. Structure is documented below.

  • pathMatcher - (Required) The list of pathMatchers referenced via name by hostRules. PathMatcher is used to match the path portion of the URL when a HostRule matches the URL's host portion. Structure is documented below.

The hostRule block supports:

  • description - (Optional) A human-readable description of the hostRule.

  • hosts - (Required) The list of host patterns to match. Host patterns must be valid hostnames. Ports are not allowed. Wildcard hosts are supported in the suffix or prefix form. * matches any string of ([a-z0-9-.]*). It does not match the empty string. When multiple hosts are specified, hosts are matched in the following priority:

    1. Exact domain names: wwwFooCom.
    2. Suffix domain wildcards: *FooCom or *BarFooCom.
    3. Prefix domain wildcards: foo.* or foo-*.
    4. Special wildcard * matching any domain. Notes: The wildcard will not match the empty string. e.g. *BarFooCom will match bazBarFooCom but not barFooCom. The longest wildcards match first. Only a single host in the entire service can match on *. A domain must be unique across all configured hosts within a service. Hosts are matched against the HTTP Host header, or for HTTP/2 and HTTP/3, the ":authority" header, from the incoming request. You may specify up to 10 hosts.
  • pathMatcher - (Required) The name of the pathMatcher associated with this hostRule.

The pathMatcher block supports:

  • name - (Required) The name to which this PathMatcher is referred by the HostRule.

  • description - (Optional) A human-readable description of the resource.

  • routeRule - (Required) The routeRules to match against. routeRules support advanced routing behaviour, and can match on paths, headers and query parameters, as well as status codes and HTTP methods. Structure is documented below.

The routeRule block supports:

  • priority - (Required) The priority of this route rule, where 1 is the highest priority. You cannot configure two or more routeRules with the same priority. Priority for each rule must be set to a number between 1 and 999 inclusive. Priority numbers can have gaps, which enable you to add or remove rules in the future without affecting the rest of the rules. For example, 1, 2, 3, 4, 5, 9, 12, 16 is a valid series of priority numbers to which you could add rules numbered from 6 to 8, 10 to 11, and 13 to 15 in the future without any impact on existing rules.

  • description - (Optional) A human-readable description of the routeRule.

  • matchRule - (Required) The list of criteria for matching attributes of a request to this routeRule. This list has OR semantics: the request matches this routeRule when any of the matchRules are satisfied. However predicates within a given matchRule have AND semantics. All predicates within a matchRule must match for the request to match the rule. Structure is documented below.

  • headerAction - (Optional) The header actions, including adding & removing headers, for requests that match this route. Structure is documented below.

  • routeAction - (Optional) In response to a matching path, the routeAction performs advanced routing actions like URL rewrites, header transformations, etc. prior to forwarding the request to the selected origin. Structure is documented below.

  • origin - (Optional) The Origin resource that requests to this route should fetch from when a matching response is not in cache. Origins can be defined as short names ("my-origin") or fully-qualified resource URLs - e.g. "networkservices.googleapis.com/projects/my-project/global/edgecacheorigins/my-origin" Only one of origin or urlRedirect can be set.

  • urlRedirect - (Optional) The URL redirect configuration for requests that match this route. Structure is documented below.

The matchRule block supports:

  • ignoreCase - (Optional) Specifies that prefixMatch and fullPathMatch matches are case sensitive.

  • headerMatch - (Optional) Specifies a list of header match criteria, all of which must match corresponding headers in the request. Structure is documented below.

  • queryParameterMatch - (Optional) Specifies a list of query parameter match criteria, all of which must match corresponding query parameters in the request. Structure is documented below.

  • prefixMatch - (Optional) For satisfying the matchRule condition, the request's path must begin with the specified prefixMatch. prefixMatch must begin with a /.

  • pathTemplateMatch - (Optional) For satisfying the matchRule condition, the path of the request must match the wildcard pattern specified in pathTemplateMatch after removing any query parameters and anchor that may be part of the original URL. pathTemplateMatch must be between 1 and 255 characters (inclusive). The pattern specified by pathTemplateMatch may have at most 5 wildcard operators and at most 5 variable captures in total.

  • fullPathMatch - (Optional) For satisfying the matchRule condition, the path of the request must exactly match the value specified in fullPathMatch after removing any query parameters and anchor that may be part of the original URL.

The headerMatch block supports:

  • headerName - (Required) The header name to match on.

  • presentMatch - (Optional) A header with the contents of headerName must exist. The match takes place whether or not the request's header has a value.

  • exactMatch - (Optional) The value of the header should exactly match contents of exactMatch.

  • prefixMatch - (Optional) The value of the header must start with the contents of prefixMatch.

  • suffixMatch - (Optional) The value of the header must end with the contents of suffixMatch.

  • invertMatch - (Optional) If set to false (default), the headerMatch is considered a match if the match criteria above are met. If set to true, the headerMatch is considered a match if the match criteria above are NOT met.

The queryParameterMatch block supports:

  • name - (Required) The name of the query parameter to match. The query parameter must exist in the request, in the absence of which the request match fails.

  • presentMatch - (Optional) Specifies that the queryParameterMatch matches if the request contains the query parameter, irrespective of whether the parameter has a value or not.

  • exactMatch - (Optional) The queryParameterMatch matches if the value of the parameter exactly matches the contents of exactMatch.

The headerAction block supports:

  • requestHeaderToAdd - (Optional) Describes a header to add. Structure is documented below.

  • responseHeaderToAdd - (Optional) Headers to add to the response prior to sending it back to the client. Response headers are only sent to the client, and do not have an effect on the cache serving the response. Structure is documented below.

  • requestHeaderToRemove - (Optional) A list of header names for headers that need to be removed from the request prior to forwarding the request to the origin. Structure is documented below.

  • responseHeaderToRemove - (Optional) A list of header names for headers that need to be removed from the request prior to forwarding the request to the origin. Structure is documented below.

The requestHeaderToAdd block supports:

  • headerName - (Required) The name of the header to add.

  • headerValue - (Required) The value of the header to add.

  • replace - (Optional) Whether to replace all existing headers with the same name.

The responseHeaderToAdd block supports:

  • headerName - (Required) The name of the header to add.

  • headerValue - (Required) The value of the header to add.

  • replace - (Optional) Whether to replace all existing headers with the same name.

The requestHeaderToRemove block supports:

  • headerName - (Required) The name of the header to remove.

The responseHeaderToRemove block supports:

  • headerName - (Required) Headers to remove from the response prior to sending it back to the client. Response headers are only sent to the client, and do not have an effect on the cache serving the response.

The routeAction block supports:

  • cdnPolicy - (Optional) The policy to use for defining caching and signed request behaviour for requests that match this route. Structure is documented below.

  • urlRewrite - (Optional) The URL rewrite configuration for requests that match this route. Structure is documented below.

  • corsPolicy - (Optional) CORSPolicy defines Cross-Origin-Resource-Sharing configuration, including which CORS response headers will be set. Structure is documented below.

The cdnPolicy block supports:

  • cacheMode - (Optional) Cache modes allow users to control the behaviour of the cache, what content it should cache automatically, whether to respect origin headers, or whether to unconditionally cache all responses. For all cache modes, Cache-Control headers will be passed to the client. Use clientTtl to override what is sent to the client. Possible values are cacheAllStatic, useOriginHeaders, forceCacheAll, and bypassCache.

  • clientTtl - (Optional) Specifies a separate client (e.g. browser client) TTL, separate from the TTL used by the edge caches. Leaving this empty will use the same cache TTL for both the CDN and the client-facing response.

    • The TTL must be > 0 and <= 86400s (1 day)
    • The clientTtl cannot be larger than the defaultTtl (if set)
    • Fractions of a second are not allowed. Omit this field to use the defaultTtl, or the max-age set by the origin, as the client-facing TTL. When the cache mode is set to "USE_ORIGIN_HEADERS" or "BYPASS_CACHE", you must omit this field. A duration in seconds terminated by 's'. Example: "3s".
  • 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). Defaults to 3600s (1 hour).

    • The TTL must be >= 0 and <= 31,536,000 seconds (1 year)
    • Setting a TTL of "0" means "always revalidate" (equivalent to must-revalidate)
    • The value of defaultTTL cannot be set to a value greater than that of maxTTL.
    • Fractions of a second are not allowed.
    • When the cacheMode is set to FORCE_CACHE_ALL, the defaultTTL will overwrite the TTL set in all responses. Note that infrequently accessed objects may be evicted from the cache before the defined TTL. Objects that expire will be revalidated with the origin. When the cache mode is set to "USE_ORIGIN_HEADERS" or "BYPASS_CACHE", you must omit this field. A duration in seconds terminated by 's'. Example: "3s".
  • maxTtl - (Optional) Specifies the maximum allowed TTL for cached content served by this origin. Defaults to 86400s (1 day). Cache directives that attempt to set a max-age or s-maxage higher than this, or an Expires header more than maxTtl seconds in the future will be capped at the value of maxTTL, as if it were the value of an s-maxage Cache-Control directive.

    • The TTL must be >= 0 and <= 31,536,000 seconds (1 year)
    • Setting a TTL of "0" means "always revalidate"
    • The value of maxTtl must be equal to or greater than defaultTtl.
    • Fractions of a second are not allowed. When the cache mode is set to "USE_ORIGIN_HEADERS", "FORCE_CACHE_ALL", or "BYPASS_CACHE", you must omit this field. A duration in seconds terminated by 's'. Example: "3s".
  • cacheKeyPolicy - (Optional) Defines the request parameters that contribute to the cache key. Structure is documented below.

  • negativeCaching - (Optional) Negative caching allows per-status code TTLs to be set, in order to apply fine-grained caching for common errors or redirects. This can reduce the load on your origin and improve end-user experience by reducing response latency. By default, the CDNPolicy will apply the following default TTLs to these status codes:

    • HTTP 300 (Multiple Choice), 301, 308 (Permanent Redirects): 10m
    • HTTP 404 (Not Found), 410 (Gone), 451 (Unavailable For Legal Reasons): 120s
    • HTTP 405 (Method Not Found), 414 (URI Too Long), 501 (Not Implemented): 60s These defaults can be overridden in negativeCachingPolicy
  • 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 the default TTLs for each status code, defined in negativeCaching.
    • TTLs must be >= 0 (where 0 is "always revalidate") and <= 86400s (1 day) Note that when specifying an explicit negativeCachingPolicy, you should take care to specify a cache TTL for all response codes that you wish to cache. The CDNPolicy will not apply any default negative caching when a policy exists.
  • signedRequestMode - (Optional) Whether to enforce signed requests. The default value is DISABLED, which means all content is public, and does not authorize access. You must also set a signedRequestKeyset to enable signed requests. When set to REQUIRE_SIGNATURES, all matching requests will have their signature validated. Requests that were not signed with the corresponding private key, or that are otherwise invalid (expired, do not match the signature, IP address, or header) will be rejected with a HTTP 403 and (if enabled) logged. Possible values are disabled, requireSignatures, and requireTokens.

  • signedRequestKeyset - (Optional) The EdgeCacheKeyset containing the set of public keys used to validate signed requests at the edge.

  • signedTokenOptions - (Optional) Additional options for signed tokens. signedTokenOptions may only be specified when signedRequestMode is REQUIRE_TOKENS. Structure is documented below.

  • addSignatures - (Optional) Enable signature generation or propagation on this route. This field may only be specified when signedRequestMode is set to REQUIRE_TOKENS. Structure is documented below.

  • signedRequestMaximumExpirationTtl - (Optional) Limit how far into the future the expiration time of a signed request may be. When set, a signed request is rejected if its expiration time is later than now + signedRequestMaximumExpirationTtl, where now is the time at which the signed request is first handled by the CDN.

    • The TTL must be > 0.
    • Fractions of a second are not allowed. By default, signedRequestMaximumExpirationTtl is not set and the expiration time of a signed request may be arbitrarily far into future.

The cacheKeyPolicy block supports:

  • includeProtocol - (Optional) If true, http and https requests will be cached separately.

  • excludeQueryString - (Optional) If true, exclude query string parameters from the cache key If false (the default), include the query string parameters in the cache key according to includeQueryParameters and excludeQueryParameters. If neither includeQueryParameters nor excludeQueryParameters is set, the entire query string will be included.

  • excludeHost - (Optional) If true, requests to different hosts will be cached separately. Note: this should only be enabled if hosts share the same origin and content. Removing the host from the cache key may inadvertently result in different objects being cached than intended, depending on which route the first user matched.

  • includedQueryParameters - (Optional) Names of query string parameters to include in cache keys. All other parameters will be excluded. Either specify includedQueryParameters or excludedQueryParameters, not both. '&' and '=' will be percent encoded and not treated as delimiters.

  • excludedQueryParameters - (Optional) Names of query string parameters to exclude from cache keys. All other parameters will be included. Either specify includedQueryParameters or excludedQueryParameters, not both. '&' and '=' will be percent encoded and not treated as delimiters.

  • includedHeaderNames - (Optional) Names of HTTP request headers to include in cache keys. The value of the header field will be used as part of the cache key.

    • Header names must be valid HTTP RFC 7230 header field values.
    • Header field names are case insensitive
    • To include the HTTP method, use ":method" Note that specifying several headers, and/or headers that have a large range of values (e.g. per-user) will dramatically impact the cache hit rate, and may result in a higher eviction rate and reduced performance.
  • includedCookieNames - (Optional) Names of Cookies to include in cache keys. The cookie name and cookie value of each cookie named will be used as part of the cache key. Cookie names:

    • must be valid RFC 6265 "cookie-name" tokens
    • are case sensitive
    • cannot start with "Edge-Cache-" (case insensitive) Note that specifying several cookies, and/or cookies that have a large range of values (e.g., per-user) will dramatically impact the cache hit rate, and may result in a higher eviction rate and reduced performance. You may specify up to three cookie names.

The signedTokenOptions block supports:

  • tokenQueryParameter - (Optional) The query parameter in which to find the token. The name must be 1-64 characters long and match the regular expression [aZAZ]([aZAZ09_-])* which means the first character must be a letter, and all following characters must be a dash, underscore, letter or digit. Defaults to edgeCacheToken.

  • allowedSignatureAlgorithms - (Optional) The allowed signature algorithms to use. Defaults to using only ED25519. You may specify up to 3 signature algorithms to use. Each value may be one of ed25519, hmacSha256, and hmacSha1.

The addSignatures block supports:

  • actions - (Required) The actions to take to add signatures to responses. Each value may be one of generateCookie, generateTokenHlsCookieless, and propagateTokenHlsCookieless.

  • keyset - (Optional) The keyset to use for signature generation. The following are both valid paths to an EdgeCacheKeyset resource:

    • projects/project/locations/global/edgeCacheKeysets/yourKeyset
    • yourKeyset This must be specified when the GENERATE_COOKIE or GENERATE_TOKEN_HLS_COOKIELESS actions are specified. This field may not be specified otherwise.
  • tokenTtl - (Optional) The duration the token is valid starting from the moment the token is first generated. Defaults to 86400S (1 day). The TTL must be >= 0 and <= 604,800 seconds (1 week). This field may only be specified when the GENERATE_COOKIE or GENERATE_TOKEN_HLS_COOKIELESS actions are specified. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".

  • tokenQueryParameter - (Optional) The query parameter in which to put the generated token. If not specified, defaults to edgeCacheToken. If specified, the name must be 1-64 characters long and match the regular expression [aZAZ]([aZAZ09_-])* which means the first character must be a letter, and all following characters must be a dash, underscore, letter or digit. This field may only be set when the GENERATE_TOKEN_HLS_COOKIELESS or PROPAGATE_TOKEN_HLS_COOKIELESS actions are specified.

  • copiedParameters - (Optional) The parameters to copy from the verified token to the generated token. Only the following parameters may be copied:

    • pathGlobs
    • paths
    • acl
    • urlPrefix
    • ipRanges
    • sessionId
    • id
    • data
    • data
    • payload
    • headers You may specify up to 6 parameters to copy. A given parameter is be copied only if the parameter exists in the verified token. Parameter names are matched exactly as specified. The order of the parameters does not matter. Duplicates are not allowed. This field may only be specified when the GENERATE_COOKIE or GENERATE_TOKEN_HLS_COOKIELESS actions are specified.

The urlRewrite block supports:

  • pathPrefixRewrite - (Optional) Prior to forwarding the request to the selected origin, the matching portion of the request's path is replaced by pathPrefixRewrite.

  • hostRewrite - (Optional) Prior to forwarding the request to the selected origin, the request's host header is replaced with contents of hostRewrite.

  • pathTemplateRewrite - (Optional) Prior to forwarding the request to the selected origin, if the request matched a pathTemplateMatch, the matching portion of the request's path is replaced re-written using the pattern specified by pathTemplateRewrite. pathTemplateRewrite must be between 1 and 255 characters (inclusive), must start with a '/', and must only use variables captured by the route's pathTemplate matchers. pathTemplateRewrite may only be used when all of a route's MatchRules specify pathTemplate. Only one of pathPrefixRewrite and pathTemplateRewrite may be specified.

The corsPolicy block supports:

  • maxAge - (Required) Specifies how long results of a preflight request can be cached by a client in seconds. Note that many browser clients enforce a maximum TTL of 600s (10 minutes).

    • Setting the value to -1 forces a pre-flight check for all requests (not recommended)
    • A maximum TTL of 86400s can be set, but note that (as above) some clients may force pre-flight checks at a more regular interval.
    • This translates to the Access-Control-Max-Age header. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".
  • allowCredentials - (Optional) In response to a preflight request, setting this to true indicates that the actual request can include user credentials. This translates to the Access-Control-Allow-Credentials response header.

  • allowOrigins - (Optional) Specifies the list of origins that will be allowed to do CORS requests. This translates to the Access-Control-Allow-Origin response header.

  • allowMethods - (Optional) Specifies the content for the Access-Control-Allow-Methods response header.

  • allowHeaders - (Optional) Specifies the content for the Access-Control-Allow-Headers response header.

  • exposeHeaders - (Optional) Specifies the content for the Access-Control-Allow-Headers response header.

  • disabled - (Optional) If true, specifies the CORS policy is disabled. The default value is false, which indicates that the CORS policy is in effect.

The urlRedirect block supports:

  • hostRedirect - (Optional) The host that will be used in the redirect response instead of the one that was supplied in the request.

  • pathRedirect - (Optional) The path that will be used in the redirect response instead of the one that was supplied in the request. pathRedirect cannot be supplied together with prefixRedirect. Supply one alone or neither. If neither is supplied, the path of the original request will be used for the redirect. The path value must be between 1 and 1024 characters.

  • prefixRedirect - (Optional) The prefix that replaces the prefixMatch specified in the routeRule, retaining the remaining portion of the URL before redirecting the request. prefixRedirect cannot be supplied together with pathRedirect. Supply one alone or neither. If neither is supplied, the path of the original request will be used for the redirect.

  • redirectResponseCode - (Optional) The HTTP Status code to use for this RedirectAction. The supported values are:

    • movedPermanentlyDefault, which is the default value and corresponds to 301.
    • found, which corresponds to 302.
    • seeOther which corresponds to 303.
    • temporaryRedirect, which corresponds to 307. in this case, the request method will be retained.
    • permanentRedirect, which corresponds to 308. in this case, the request method will be retained. Possible values are movedPermanentlyDefault, found, seeOther, temporaryRedirect, and permanentRedirect.
  • httpsRedirect - (Optional) If set to true, the URL scheme in the redirected request is set to https. If set to false, the URL scheme of the redirected request will remain the same as that of the request. This can only be set if there is at least one (1) edgeSslCertificate set on the service.

  • stripQuery - (Optional) If set to true, any accompanying query portion of the original URL is removed prior to redirecting the request. If set to false, the query portion of the original URL is retained.


  • description - (Optional) A human-readable description of the resource.

  • labels - (Optional) Set of label tags associated with the EdgeCache resource.

  • disableQuic - (Optional) HTTP/3 (IETF QUIC) and Google QUIC are enabled by default.

  • disableHttp2 - (Optional) Disables HTTP/2. HTTP/2 (h2) is enabled by default and recommended for performance. HTTP/2 improves connection re-use and reduces connection setup overhead by sending multiple streams over the same connection. Some legacy HTTP clients may have issues with HTTP/2 connections due to broken HTTP/2 implementations. Setting this to true will prevent HTTP/2 from being advertised and negotiated.

  • requireTls - (Optional) Require TLS (HTTPS) for all clients connecting to this service. Clients who connect over HTTP (port 80) will receive a HTTP 301 to the same URL over HTTPS (port 443). You must have at least one (1) edgeSslCertificate specified to enable this.

  • edgeSslCertificates - (Optional) URLs to sslCertificate resources that are used to authenticate connections between users and the EdgeCacheService. Note that only "global" certificates with a "scope" of "EDGE_CACHE" can be attached to an EdgeCacheService.

  • sslPolicy - (Optional) URL of the SslPolicy resource that will be associated with the EdgeCacheService. If not set, the EdgeCacheService has no SSL policy configured, and will default to the "COMPATIBLE" policy.

  • logConfig - (Optional) Specifies the logging options for the traffic served by this service. If logging is enabled, logs will be exported to Cloud Logging. Structure is documented below.

  • edgeSecurityPolicy - (Optional) Resource URL that points at the Cloud Armor edge security policy that is applied on each request against the EdgeCacheService.

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

The logConfig block supports:

  • enable - (Required) Specifies whether to enable logging for traffic served by this service.

  • sampleRate - (Optional) Configures the sampling rate of requests, where 1.0 means all logged requests are reported and 0.0 means no logged requests are reported. The default value is 1.0, and the value of the field must be in [0, 1]. This field can only be specified if logging is enabled for this service.

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}}/locations/global/edgeCacheServices/{{name}}

  • ipv4Addresses - The IPv4 addresses associated with this service. Addresses are static for the lifetime of the service.

  • ipv6Addresses - The IPv6 addresses associated with this service. Addresses are static for the lifetime of the service.

Timeouts

This resource provides the following Timeouts configuration options:

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

Import

EdgeCacheService can be imported using any of these accepted formats:

$ terraform import google_network_services_edge_cache_service.default projects/{{project}}/locations/global/edgeCacheServices/{{name}}
$ terraform import google_network_services_edge_cache_service.default {{project}}/{{name}}
$ terraform import google_network_services_edge_cache_service.default {{name}}

User Project Overrides

This resource supports User Project Overrides.