> ## Documentation Index
> Fetch the complete documentation index at: https://docs.formal.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# GCP

> Connect a Google Cloud project for autodiscovery and log delivery to Cloud Storage and Pub/Sub

The GCP Cloud Account connects a Google Cloud project to Formal using [Workload Identity Federation](https://cloud.google.com/iam/docs/workload-identity-federation). Formal presents its AWS identity, which your project trusts through a workload identity pool, then impersonates a dedicated service account. No service account keys are created; access is entirely federated.

## What Formal Discovers

> [accordion] Cloud SQL Autodiscovery
>
> Discover Cloud SQL for PostgreSQL and MySQL instances and add them as Formal
> resources.

> [accordion] GKE Autodiscovery
>
> Discover GKE clusters for Kubernetes access control. Clusters need a public
> endpoint to be discovered.

> [accordion] Compute Engine Autodiscovery
>
> Discover Compute Engine instances for SSH access.

> [accordion] Cloud Storage Log Delivery
>
> Write logs to GCS buckets through a
> [Log Forwarding](https://docs.formal.ai/docs/guides/integrations/log.md#google-cloud-storage).

> [accordion] Pub/Sub Log Delivery
>
> Publish logs to Pub/Sub topics through a
> [Log Forwarding](https://docs.formal.ai/docs/guides/integrations/log.md#google-cloud-pubsub).

Autodiscovery for all three resource types is on by default. See [Resource Autodiscovery](https://docs.formal.ai/docs/guides/integrations/clouds/introduction.md#resource-autodiscovery) for how discovered resources behave.

## Architecture

The [`terraform-formal-gcp`](https://github.com/formalco/terraform-formal-gcp) module enables the required APIs (IAM, STS, IAM Credentials, Cloud Resource Manager) and creates:

1. **Workload Identity Pool**: a pool with an AWS-type provider that trusts Formal's AWS account
2. **Attribute Condition**: pins Formal's per-integration role ARN, so only that exact role can exchange a token
3. **Service Account**: the identity Formal impersonates in your project
4. **Custom Role**: a single role holding only the permissions the capabilities you enable actually use, such as `compute.instances.list`, `container.clusters.list`, and `cloudsql.instances.list` for discovery, and `storage.objects.create` or `pubsub.topics.publish` for log delivery, granted to the service account

Formal derives the exact permissions from the capabilities you enable and returns them for the module to grant through one custom role.

## Setup

> [tab] Control Plane
>
> **1. Navigate to Cloud Accounts**
>
> Go to [Cloud Accounts](https://app.formal.ai/cloud-accounts)
>
> **2. Create Integration**
>
> Click **Create Integration** and choose **GCP**
>
> **3. Enter Details**
>
> Enter a name and the Google Cloud **project ID** to connect
>
> **4. Choose Discovery**
>
> Toggle autodiscovery for **Compute Engine**, **GKE**, and **Cloud SQL**. All are on by default.
>
> **5. Configure GCS Access**
>
> To deliver logs to Cloud Storage, enable **GCS log writes**. Leave the bucket list empty to allow every bucket in the project, or name specific buckets to scope access.
>
> **6. Configure Pub/Sub Access**
>
> To publish logs to Pub/Sub, enable **Allow Pub/Sub log publishing**. Leave the topic list empty to allow every topic in the project, or name specific topics to scope access.
>
> **7. Run the Setup Command**
>
> Formal shows a command with your integration ID and security key filled in. Paste it into an authenticated [Cloud Shell](https://cloud.google.com/shell) for that project:
>
> ```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> bash <(curl -sSL https://formal.ai/gcp.sh) <INTEGRATION_ID> <SECURITY_KEY>
> ```
>
> It fetches the setup parameters from Formal, runs `terraform apply`, then reports the service account and workload identity pool provider back to Formal, which activates the integration.

> [tab] Terraform
>
> Register the integration, provision the GCP resources with the [`terraform-formal-gcp`](https://github.com/formalco/terraform-formal-gcp) module, then report them back to activate it.
>
> ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> # 1. Register the GCP Cloud Account. Autodiscovery is on by default. allow_gcs_access
> #    and allow_pubsub_access with an empty gcs_buckets or pubsub_topics list grant log
> #    delivery to any bucket or topic in the project; set the list to scope it.
> resource "formal_integration_cloud" "gcp" {
>   name = "production-gcp"
>
>   gcp {
>     project_id                              = "my-gcp-project"
>     enable_compute_instances_autodiscovery  = true
>     enable_gke_clusters_autodiscovery       = true
>     enable_cloudsql_instances_autodiscovery = true
>     allow_gcs_access                        = true
>     allow_pubsub_access                     = true
>   }
> }
>
> # 2. Provision the GCP-side resources with the Formal-maintained module (service
> #    account, workload identity pool provider, custom role).
> module "formal_gcp" {
>   source = "github.com/formalco/terraform-formal-gcp"
>
>   integration_id  = formal_integration_cloud.gcp.id
>   formal_role_arn = formal_integration_cloud.gcp.aws_formal_role_arn
>   project_id      = "my-gcp-project"
>   permissions     = formal_integration_cloud.gcp.gcp_permissions
>   gcs_buckets     = formal_integration_cloud.gcp.gcp[0].gcs_buckets
>   pubsub_topics   = formal_integration_cloud.gcp.gcp[0].pubsub_topics
> }
>
> # 3. Report the created resources back to Formal to activate the integration.
> resource "formal_integration_cloud_gcp_activation" "gcp" {
>   integration_id                  = formal_integration_cloud.gcp.id
>   service_account_email           = module.formal_gcp.service_account_email
>   workload_identity_pool_provider = module.formal_gcp.workload_identity_pool_provider
> }
> ```
>
> > [!NOTE]
> >
> > The activation resource is separate from `formal_integration_cloud` on purpose. That resource feeds the module its ID and role ARN, so reading the module outputs back into it would create a dependency cycle.
>
> Each discovery flag defaults to `true`; set any to `false` to skip that resource type.

## Cloud Storage Log Delivery

To forward logs to GCS, the integration needs Cloud Storage access. Enable it when creating the integration with two settings:

| Setting | Description |
| - | - |
| `allow_gcs_access` | Grants Formal's service account permission to write log objects. |
| `gcs_buckets` | Buckets Formal may write to. Leave empty to allow every bucket in the project. |

Formal grants matching IAM: a project-wide `storage.objects.create` permission in the custom role when the bucket list is empty, or per-bucket IAM bindings when you restrict it.

Once access is granted, configure [Log Forwarding](https://docs.formal.ai/docs/guides/integrations/log.md) for a bucket to start forwarding logs.

## Pub/Sub Log Delivery

To publish logs to Pub/Sub, the integration needs Pub/Sub access. Enable it when creating the integration with two settings:

| Setting | Description |
| - | - |
| `allow_pubsub_access` | Grants Formal's service account permission to publish log messages. |
| `pubsub_topics` | Topics Formal may publish to (`projects/<project>/topics/<topic>`). Leave empty to allow every topic in the project. |

Formal grants matching IAM: a project-wide `pubsub.topics.publish` permission in the custom role when the topic list is empty, or `roles/pubsub.publisher` on each topic when you restrict it.

Once access is granted, configure [Log Forwarding](https://docs.formal.ai/docs/guides/integrations/log.md) for a topic to start forwarding logs.

## Security

* **Federated, keyless**: no service account keys are created or stored.
* **Pinned role**: the pool's attribute condition trusts only Formal's exact per-integration role ARN.
* **Least privilege**: through one custom role, the service account gets only the permissions the capabilities you enable actually use, plus read access to the project's own metadata for connection verification.
* **Bucket scoping**: restrict `gcs_buckets` so Formal can write only to the buckets you name.
* **Topic scoping**: restrict `pubsub_topics` so Formal can publish only to the topics you name.

## Troubleshooting

> [accordion] Setup command fails
>
> **Possible causes:**
>
> * The Cloud Shell is not authenticated to the target project
> * The account lacks permission to enable APIs or create IAM resources
> * The integration ID or security key is wrong
>
> **Solution:**
>
> 1. Run `gcloud config set project <PROJECT_ID>` in the Cloud Shell
> 2. Ensure the account has `roles/owner` or an equivalent set of IAM and Service Usage roles
> 3. Copy the exact command Formal shows when you create the integration

> [accordion] Resources not discovered
>
> **Possible causes:**
>
> * Autodiscovery disabled for that resource type
> * GKE cluster has no public endpoint
> * Cloud SQL instance is neither PostgreSQL nor MySQL
> * Service account missing the viewer role
>
> **Solution:**
>
> 1. Verify the discovery toggle is enabled on the Cloud Account
> 2. Confirm the cluster exposes a public endpoint
> 3. Re-run the setup command so the module grants the viewer roles
> 4. Wait a few minutes for the initial scan

> [accordion] GCS log forwarding not working
>
> **Possible causes:**
>
> * Cloud Storage access not enabled on the integration
> * The target bucket is not in the `gcs_buckets` allowlist
> * Log integration not configured
>
> **Solution:**
>
> 1. Confirm `allow_gcs_access` is enabled on the Cloud Account
> 2. Add the bucket to `gcs_buckets`, or leave the list empty to allow all buckets
> 3. Configure [Log Forwarding](https://docs.formal.ai/docs/guides/integrations/log.md) for this cloud integration

> [accordion] Pub/Sub log forwarding not working
>
> **Possible causes:**
>
> * Pub/Sub access not enabled on the integration
> * The target topic is not in the `pubsub_topics` allowlist
> * Log integration not configured
>
> **Solution:**
>
> 1. Confirm `allow_pubsub_access` is enabled on the Cloud Account
> 2. Add the topic to `pubsub_topics`, or leave the list empty to allow all topics
> 3. Configure [Log Forwarding](https://docs.formal.ai/docs/guides/integrations/log.md) for this cloud integration

## Next Steps

> [card] [Log Forwarding](https://docs.formal.ai/docs/guides/integrations/log.md)
>
> Forward logs to Cloud Storage or Pub/Sub

> [card] [Add Resources](https://docs.formal.ai/docs/guides/core-concepts/resources/introduction.md)
>
> Manually configure discovered resources

> [card] [Terraform](https://docs.formal.ai/docs/guides/configuration/terraform.md)
>
> Manage integrations as code

> [card] [View Resources](https://app.formal.ai/resources)
>
> See all autodiscovered resources


## Related topics

- [GCP](https://docs.formal.ai/docs/guides/core-concepts/resources/gcp.md)
- [Activate a GCP cloud integration](https://docs.formal.ai/api-reference/corev1integrationcloudservice/activate-a-gcp-cloud-integration.md)
- [Get GCP cloud integration setup parameters](https://docs.formal.ai/api-reference/corev1integrationcloudservice/get-gcp-cloud-integration-setup-parameters.md)
- [Log In to the Endpoint with OIDC](https://docs.formal.ai/docs/guides/client-apps/oidc.md)
- [Dial Configuration](https://docs.formal.ai/docs/guides/core-concepts/resources/dial.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.