> 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/google-cloud-functions-infrastructure.md).

# Google Cloud Functions infrastructure

Configure a Google Cloud Functions infrastructure definition with a Google Cloud connector, project, and region.

An infrastructure definition links your logical Harness environment to the actual physical resources. For Google Cloud Functions, it specifies the Google Cloud connector, project, and region Harness deploys to.

***

### What you will learn from this topic <a href="#what-you-will-learn-from-this-topic" id="what-you-will-learn-from-this-topic"></a>

* How to create an infrastructure definition for Google Cloud Functions.
* How to configure the Google Cloud connector, project, and region, and control simultaneous deployments.

***

### Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

* An environment to associate the infrastructure definition with.
* A Google Cloud connector with access to the target project.
* The Google Cloud project and region where the function deploys.

***

### Create an environment <a href="#create-an-environment" id="create-an-environment"></a>

1. Go to **Deployments**, expand the drop-down, and select **Environments**.
2. Select **+ New Environment**.
3. Enter a name and select an environment type: **Pre-Production** or **Production**. The type affects governance policies and deployment dashboards.
4. Select **Save**.

Harness opens the environment detail page with two tabs: **Configuration** and **Infrastructure Definitions**.

***

### Create an infrastructure definition <a href="#create-an-infrastructure-definition" id="create-an-infrastructure-definition"></a>

1. From the environment's **Infrastructure Definitions** tab, click **+ New Infrastructure**, or click **+ Add** in the stage wizard's infrastructure step.
2. Search for and select **Google Cloud Functions** as the infrastructure type.
3. Enter a **Name**. Harness generates the **Id** automatically; edit it using the pencil icon if needed.
4. Set **Storage** to **Inline** or a Git repository.
5. Expand **Google Cloud Provider Details**, then **Provisioner Configuration**, and select a **Connector**, **Project**, and **Region**.
6. Configure **Simultaneous deployments** and, optionally, **Scope to Specific Services**.
7. Click **Save**.

#### Top-level fields <a href="#top-level-fields" id="top-level-fields"></a>

| Field       | Description                                                                                                                  |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------- |
| **Name**    | A name for the infrastructure definition. Harness generates the **Id** automatically; you can edit it using the pencil icon. |
| **Storage** | Where the infrastructure definition is stored: **Inline** or a Git repository.                                               |

#### Google Cloud provider details <a href="#google-cloud-provider-details" id="google-cloud-provider-details"></a>

Expand **Google Cloud Provider Details**, then **Provisioner Configuration**, to set the following fields.

| Field         | Required | Description                                                                         |
| ------------- | -------- | ----------------------------------------------------------------------------------- |
| **Connector** | Yes      | The Google Cloud connector Harness uses to authenticate and deploy to this project. |
| **Project**   | Yes      | The Google Cloud project where the function deploys.                                |
| **Region**    | Yes      | The Google Cloud region where the function deploys.                                 |

#### Simultaneous deployments <a href="#simultaneous-deployments" id="simultaneous-deployments"></a>

| Field                        | Default | Description                                                                                                                    |
| ---------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------ |
| **Simultaneous deployments** | `False` | By default, Harness queues deployments to the same infrastructure to avoid conflict. Enable to allow simultaneous deployments. |

***

### Authentication <a href="#authentication" id="authentication"></a>

The Google Cloud connector used in the **Connector** field supports three authentication methods: service account, OIDC, and inherit from delegate.

#### Service account <a href="#service-account" id="service-account"></a>

Harness activates the key using `gcloud auth activate-service-account`. To set this up, create a connector, select **GCP**, choose **Specify credentials here**, then upload or paste the service account JSON key and save.

#### OIDC <a href="#oidc" id="oidc"></a>

Harness uses a Workload Identity Pool to exchange tokens for GCP credentials. Setup requires the Workload Identity Pool ID, Workload Provider ID, GCP project ID, and the service account email to impersonate.

{% hint style="info" %}
**Required permissions for OIDC**

OIDC authentication requires the `iam.workloadIdentityPools.createCredentialConfig` permission, plus `iam.serviceAccounts.actAs` on the service identity.
{% endhint %}

#### Inherit from delegate <a href="#inherit-from-delegate" id="inherit-from-delegate"></a>

This method suits delegates deployed on GKE with Workload Identity or on GCE with an attached service account. Harness runs `gcloud auth list --filter=status:ACTIVE` to find the active account, then uses Application Default Credentials.

***

### IAM permissions <a href="#iam-permissions" id="iam-permissions"></a>

The connector's credentials must have the following permissions to deploy Google Cloud Functions resources.

#### Minimum permissions <a href="#minimum-permissions" id="minimum-permissions"></a>

Google Cloud Functions (Gen 2) deploys through the Cloud Run API, so the connector's credentials need both the `cloudfunctions.*` and `run.*` permissions below.

| Operation                                         | Permissions required                                                                                                                                   |
| ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Create or update a function                       | `cloudfunctions.functions.create`, `cloudfunctions.functions.update`                                                                                   |
| List functions                                    | `cloudfunctions.functions.list`                                                                                                                        |
| Get function deployment status                    | `cloudfunctions.operations.get`                                                                                                                        |
| Create or update the underlying Cloud Run service | `run.services.create`, `run.services.update`, `run.services.get`                                                                                       |
| Create and inspect Cloud Run revisions            | `run.revisions.create`, `run.revisions.get`                                                                                                            |
| Create and inspect Cloud Run routes               | `run.routes.create`, `run.routes.get`                                                                                                                  |
| Call the Cloud Functions and Cloud Run APIs       | `cloudfunctions.functions.getIamPolicy`, `cloudfunctions.functions.testIamPermissions`, `run.services.getIamPolicy`, `run.services.testIamPermissions` |
| Service account impersonation                     | `iam.serviceAccounts.actAs` (required on the function's service identity, even when the deployer and service identity are the same account)            |

Harness also needs access to the Cloud Storage bucket that hosts the function source ZIP file.

#### Predefined roles <a href="#predefined-roles" id="predefined-roles"></a>

| Role                                                         | Purpose                                                                                                                                                                        |
| ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `roles/cloudfunctions.admin` (Cloud Functions Admin)         | Full access to functions, operations, and locations. Also grant a Cloud Run role such as `roles/run.admin`, since Google Cloud Functions Gen 2 deploys through Cloud Run.      |
| `roles/cloudfunctions.developer` (Cloud Functions Developer) | Read and write access to all functions-related resources. Also grant a Cloud Run role such as `roles/run.admin`, since Google Cloud Functions Gen 2 deploys through Cloud Run. |
| `roles/run.admin` (Cloud Run Admin)                          | Full administrative access to the underlying Cloud Run service. Required for deploying Google Cloud Functions.                                                                 |
| `roles/storage.objectViewer` (Storage Object Viewer)         | Read access to the Cloud Storage bucket hosting the function source ZIP.                                                                                                       |
| `roles/storage.objectAdmin` (Storage Object Admin)           | Read and write access to the Cloud Storage bucket hosting the function source ZIP.                                                                                             |

***

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

* Go to [Deployment strategies](https://developer.harness.io/continuous-delivery/3.0/use-deployments/google-cloud-functions/google-cloud-functions-deployment-strategies.md) to configure a deployment strategy.
* Go to [Google Cloud Functions services](https://developer.harness.io/continuous-delivery/3.0/use-deployments/google-cloud-functions/google-cloud-functions-services.md) to configure a service.
