> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/continuous-delivery/3.0/use-deployments/google-cloud-functions/step-library/google-cloud-functions-traffic-shift.md).

# Google Cloud Functions Traffic Shift

Shift traffic between revisions on a Google Cloud Function's backing Cloud Run service.

The traffic shift step routes a percentage of traffic to a target revision on a Google Cloud Function's backing Cloud Run service. Use it after a deploy step to progressively shift traffic, or to complete a cutover in a single step.

***

### Traffic shift YAML <a href="#traffic-shift-yaml" id="traffic-shift-yaml"></a>

Minimal form:

```yaml
- name: Google Cloud Function Traffic Shift
  id: googleCloudFunctionTrafficShiftStep
  template:
    uses: googleCloudFunctionTrafficShiftStep
    with:
      function: ${{stage.steps.googleCloudFunctionDeployStep.output.outputVariables.functionName}}
      is_first_deployment: ${{stage.steps.googleCloudFunctionDeployStep.output.outputVariables.isFirstDeployment}}
      target_revision: ${{stage.steps.googleCloudFunctionDeployStep.output.outputVariables.revision}}
      target_traffic_percent: "100"
```

With explicit overrides:

```yaml
- name: Google Cloud Function Traffic Shift
  id: googleCloudFunctionTrafficShiftStep
  template:
    uses: googleCloudFunctionTrafficShiftStep
    with:
      function: ${{stage.steps.googleCloudFunctionDeployStep.output.outputVariables.functionName}}
      is_first_deployment: ${{stage.steps.googleCloudFunctionDeployStep.output.outputVariables.isFirstDeployment}}
      target_revision: ${{stage.steps.googleCloudFunctionDeployStep.output.outputVariables.revision}}
      target_traffic_percent: "10"
      command_timeout: 15m
      log_level: debug
```

***

### How the traffic shift step works <a href="#how-the-traffic-shift-step-works" id="how-the-traffic-shift-step-works"></a>

When the step runs, Harness executes the following actions in order:

1. Authenticates with Google Cloud using the connector configured on the infrastructure definition.
2. Resolves **Cloud Function Name**, **Target Revision**, and **First Deployment**, typically from a preceding deploy step's output.
3. If **First Deployment** is `true`, skips the traffic shift because there is no previous revision to balance traffic against.
4. Otherwise, shifts **Target Traffic Percent** of traffic on the backing Cloud Run service to **Target Revision**.
5. Saves the resulting traffic split as rollback data for the rollback step.

***

### Traffic shift fields <a href="#traffic-shift-fields" id="traffic-shift-fields"></a>

The following fields configure which function and revision receive traffic, and how much.

| Field                                | Default                                                                                   | Description                                                                                                                                                    |
| ------------------------------------ | ----------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Cloud Function Name**              | `${{stage.steps.googleCloudFunctionDeployStep.output.outputVariables.functionName}}`      | The function to shift traffic for. Typically resolved from a preceding deploy step's output.                                                                   |
| **Target Traffic Percent**           | —                                                                                         | The percentage of traffic to shift to **Target Revision**.                                                                                                     |
| **Target Revision**                  | `${{stage.steps.googleCloudFunctionDeployStep.output.outputVariables.revision}}`          | The revision to shift traffic to. Typically resolved from a preceding deploy step's output.                                                                    |
| **GCP Connector**                    | —                                                                                         | The Google Cloud connector used to authenticate and shift traffic. Required.                                                                                   |
| **GCP Region**                       | `${{infra.region}}`                                                                       | The Google Cloud region of the function. Auto-resolved from the infrastructure definition.                                                                     |
| **GCP Project**                      | `${{infra.project}}`                                                                      | The Google Cloud project of the function. Auto-resolved from the infrastructure definition.                                                                    |
| **First Deployment**                 | `${{stage.steps.googleCloudFunctionDeployStep.output.outputVariables.isFirstDeployment}}` | Whether this is the first deployment of the function. When `true`, the step skips the traffic shift. Typically resolved from a preceding deploy step's output. |
| **Cloud Function State (legacy)**    | —                                                                                         | The serialized Cloud Function state to shift traffic for. A legacy fallback used only when **Cloud Function Name** is empty.                                   |
| **Cloud Run Service State (legacy)** | —                                                                                         | The serialized backing Cloud Run service state to shift traffic for. A legacy fallback used only when **Cloud Function Name** is empty.                        |
| **Command Timeout**                  | `10m`                                                                                     | Maximum time for the step to complete.                                                                                                                         |
| **Log Level**                        | `info`                                                                                    | Log verbosity for the step execution.                                                                                                                          |

{% hint style="info" %}
**Advanced and Container sections**

The step template also has collapsible **Advanced** and **Container** sections for additional overrides not covered above.
{% endhint %}

***

### Next steps <a href="#next-steps" id="next-steps"></a>

* Go to [Google Cloud Functions step library](https://developer.harness.io/continuous-delivery/3.0/use-deployments/google-cloud-functions/step-library.md) for the full list of available steps.
* Go to [Canary](https://developer.harness.io/continuous-delivery/3.0/use-deployments/google-cloud-functions/google-cloud-functions-deployment-strategies/canary.md) to use this step in a managed strategy.
