> ## 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.

# Dial Configuration

> How the Connector reaches a Resource's upstream: direct TCP, Google Cloud SQL, or GKE Connect Gateway

Dial configuration controls how the Connector establishes the upstream connection for a Resource. It is optional. When absent, the Connector dials direct TCP using the Resource's `hostname` and `port`. This is the default and matches the behavior of every Resource before this feature.

```mermaid theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
sequenceDiagram
    participant Client as Client
    participant Connector as Connector
    participant Upstream as Upstream

    Client->>Connector: Connect to hostname:port
    alt dial_method = tcp (default)
      Connector->>Upstream: TCP dial to hostname:port
    else dial_method = gcp_cloudsql
      Connector->>Upstream: Google Cloud SQL dial to project:region:instance
      Note over Connector, Upstream: Cloud SQL handles mTLS end-to-end
    else dial_method = gcp_connectgateway
      Connector->>Upstream: HTTPS to hostname:port under the fleet membership path
      Note over Connector, Upstream: Connect Gateway forwards to the cluster's API server
    end
    Upstream-->>Connector: Response
    Connector-->>Client: Response
```

## Dial methods

### `tcp` (default)

The Connector dials `hostname:port` directly. This fits self-managed databases, Amazon RDS and Aurora, and any other endpoint reachable over plain TCP from the Connector.

### `gcp_cloudsql`

The Connector dials Google Cloud SQL natively, similarly to what Google's `cloud-sql-proxy` does. Ephemeral mTLS certificates are minted and rotated automatically, and the connection is encrypted end-to-end by Cloud SQL.

`gcp_cloudsql` requires `dial_target` to be the Cloud SQL instance connection name in `project:region:instance` form. Supported only for `postgres`, `mysql`, and `mariadb` Resources.

Connector prerequisites:

* The Connector runs in the Cloud SQL instance's VPC, or in a peered / PSC-connected VPC. The dial targets the instance's private IP.
* Application Default Credentials configured: the `GOOGLE_APPLICATION_CREDENTIALS` environment variable points at a service account JSON key, or the Connector runs on a GCP workload with a bound identity.
* The credentials grant `roles/cloudsql.client` on the project that owns the Cloud SQL instance.

> [!NOTE]
>
> With `gcp_cloudsql`, the Resource's [TLS configuration](https://docs.formal.ai/docs/guides/core-concepts/resources/tls.md) is ignored.

### `gcp_connectgateway`

The Connector reaches a Kubernetes cluster through [GKE Connect Gateway](https://cloud.google.com/kubernetes-engine/enterprise/multicluster-management/gateway) instead of the cluster's own API server endpoint. This works for GKE clusters and for other fleet clusters, such as GKE on bare metal or attached clusters. The Resource's `hostname` is the gateway endpoint, `connectgateway.googleapis.com` for global memberships or `<location>-connectgateway.googleapis.com` for regional ones, and its `port` is `443`.

`gcp_connectgateway` requires `dial_target` to be the cluster's fleet membership name in `projects/<project-number>/locations/<location>/memberships/<membership>` form. Connect Gateway only accepts the project number, not the project ID; `gcloud projects describe <project> --format='value(projectNumber)'` returns it. Supported only for `kubernetes` Resources.

The Connector reads the fleet membership to know whether the cluster is a GKE cluster, since the gateway serves the two kinds under different paths. The gateway roles below already include the permission this needs.

Connector prerequisites:

* The cluster is registered to a fleet, and the Connect Gateway API (`connectgateway.googleapis.com`) and the GKE Hub API (`gkehub.googleapis.com`) are enabled on the fleet host project.
* The Resource's native users use GCP IAM authentication, so the Connector sends an access token from its Application Default Credentials.
* The credentials grant `roles/gkehub.gatewayReader` for read-only access or `roles/gkehub.gatewayEditor` for read and write access on the fleet host project. `kubectl exec`, `attach`, `cp`, and `port-forward` need `roles/gkehub.gatewayAdmin`.
* Kubernetes RBAC in the cluster binds the service account email of those credentials.
* `exec`, `attach`, and `cp` need the cluster on Kubernetes 1.30 or later, and `port-forward` needs 1.31 or later.

## Configure dial configuration

> [tab] Control Plane
>
> **1. Open the Resource**
>
> Navigate to [Resources](https://app.formal.ai/resources) and open the target Resource.
>
> **2. Open the Connectivity tab**
>
> Select the **Connectivity** tab. The **Dial Configuration** section is where the dial method and target are set.
>
> **3. Pick a dial method**
>
> Selecting **TCP** keeps the default. Selecting **Google Cloud SQL** routes upstream connections natively. Selecting **GKE Connect Gateway** routes Kubernetes requests through the gateway.
>
> **4. Set the dial target**
>
> For Cloud SQL, enter the instance connection name in `project:region:instance` form (for example `my-project:us-central1:pg-prod`). For GKE Connect Gateway, enter the fleet membership name (for example `projects/1234567/locations/global/memberships/prod`). Then click **Save**.

> [tab] Terraform
>
> ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> # Direct TCP dial (matches the default, usually omitted).
> resource "formal_resource_dial_configuration" "tcp" {
>   resource_id = formal_resource.my_postgres.id
>   dial_method = "tcp"
> }
>
> # Native Cloud SQL dial.
> resource "formal_resource_dial_configuration" "cloudsql" {
>   resource_id = formal_resource.my_postgres.id
>   dial_method = "gcp_cloudsql"
>   dial_target = "my-project:us-central1:pg-prod"
> }
>
> # GKE Connect Gateway, with the Resource's hostname set to connectgateway.googleapis.com.
> resource "formal_resource_dial_configuration" "connectgateway" {
>   resource_id = formal_resource.my_kubernetes.id
>   dial_method = "gcp_connectgateway"
>   dial_target = "projects/1234567/locations/global/memberships/prod"
> }
> ```

> [!TIP]
>
> A Resource has at most one dial configuration. Deleting it restores the default `tcp` behavior.

## Verify

After applying the configuration, run the standard connectivity check:

1. From the Resource Details page, click **Test Connection** (or **Test Connectors** for a specific Connector).
2. The check should report success for the TCP, TLS, Authentication, and Data Access stages.

See [Testing Resource Connectivity](https://docs.formal.ai/docs/guides/core-concepts/resources/introduction.md#testing-resource-connectivity) for what each stage validates.

> [!NOTE]
>
> For Cloud SQL, the first dial against a new instance adds roughly one second of latency while the ephemeral certificate is minted. Subsequent dials within the hour reuse the cached certificate.


## Related topics

- [Get resource dial configuration](https://docs.formal.ai/api-reference/corev1resourceservice/get-resource-dial-configuration.md)
- [Create resource dial configuration](https://docs.formal.ai/api-reference/corev1resourceservice/create-resource-dial-configuration.md)
- [Delete resource dial configuration](https://docs.formal.ai/api-reference/corev1resourceservice/delete-resource-dial-configuration.md)
- [Update resource dial configuration](https://docs.formal.ai/api-reference/corev1resourceservice/update-resource-dial-configuration.md)
- [Terraform Provider](https://docs.formal.ai/docs/changelog/terraform-provider.md)


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