Skip to content

googleAppEngineServiceSplitTraffic

Traffic routing configuration for versions within a single service. Traffic splits define how traffic directed to the service is assigned to versions.

To get more information about ServiceSplitTraffic, see:

Example Usage - App Engine Service Split Traffic

/*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 googleStorageBucketBucket = new google.storageBucket.StorageBucket(
  this,
  "bucket",
  {
    location: "US",
    name: "appengine-static-content",
  }
);
const googleStorageBucketObjectObject =
  new google.storageBucketObject.StorageBucketObject(this, "object", {
    bucket: googleStorageBucketBucket.name,
    name: "hello-world.zip",
    source: "./test-fixtures/appengine/hello-world.zip",
  });
new google.appEngineStandardAppVersion.AppEngineStandardAppVersion(
  this,
  "liveapp_v1",
  {
    delete_service_on_destroy: true,
    deployment: [
      {
        zip: [
          {
            source_url: `https://storage.googleapis.com/\${${googleStorageBucketBucket.name}}/\${${googleStorageBucketObjectObject.name}}`,
          },
        ],
      },
    ],
    entrypoint: [
      {
        shell: "node ./app.js",
      },
    ],
    env_variables: [
      {
        port: "8080",
      },
    ],
    runtime: "nodejs10",
    service: "liveapp",
    version_id: "v1",
  }
);
const googleAppEngineStandardAppVersionLiveappV2 =
  new google.appEngineStandardAppVersion.AppEngineStandardAppVersion(
    this,
    "liveapp_v2",
    {
      deployment: [
        {
          zip: [
            {
              source_url: `https://storage.googleapis.com/\${${googleStorageBucketBucket.name}}/\${${googleStorageBucketObjectObject.name}}`,
            },
          ],
        },
      ],
      entrypoint: [
        {
          shell: "node ./app.js",
        },
      ],
      env_variables: [
        {
          port: "8080",
        },
      ],
      noop_on_destroy: true,
      runtime: "nodejs10",
      service: "liveapp",
      version_id: "v2",
    }
  );
new google.appEngineServiceSplitTraffic.AppEngineServiceSplitTraffic(
  this,
  "liveapp",
  {
    migrate_traffic: false,
    service: googleAppEngineStandardAppVersionLiveappV2.service,
    split: [
      {
        allocations: [
          {
            "${(google_app_engine_standard_app_version.liveapp_v1.version_id)}": 0.75,
            "${(google_app_engine_standard_app_version.liveapp_v2.version_id)}": 0.25,
          },
        ],
        shard_by: "IP",
      },
    ],
  }
);

Argument Reference

The following arguments are supported:

  • service - (Required) The name of the service these settings apply to.

  • split - (Required) Mapping that defines fractional HTTP traffic diversion to different versions within the service. Structure is documented below.

The split block supports:

  • shardBy - (Optional) Mechanism used to determine which version a request is sent to. The traffic selection algorithm will be stable for either type until allocations are changed. Possible values are unspecified, cookie, ip, and random.

  • allocations - (Required) Mapping from version IDs within the service to fractional (0.000, 1] allocations of traffic for that version. Each version can be specified only once, but some versions in the service may not have any traffic allocation. Services that have traffic allocated cannot be deleted until either the service is deleted or their traffic allocation is removed. Allocations must sum to 1. Up to two decimal place precision is supported for IP-based splits and up to three decimal places is supported for cookie-based splits.


  • migrateTraffic - (Optional) If set to true traffic will be migrated to this version.

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

Attributes Reference

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

  • id - an identifier for the resource with format apps/{{project}}/services/{{service}}

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

ServiceSplitTraffic can be imported using any of these accepted formats:

$ terraform import google_app_engine_service_split_traffic.default apps/{{project}}/services/{{service}}
$ terraform import google_app_engine_service_split_traffic.default {{project}}/{{service}}
$ terraform import google_app_engine_service_split_traffic.default {{service}}

User Project Overrides

This resource supports User Project Overrides.