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

# Resource TLS and Hostnames

> Configure TLS between the Connector and a resource, and add hostnames for multi-instance resources

The Connector opens its own connection to each resource. This page covers the TLS setting for that connection and the hostnames of a resource. For the connection between clients and the Connector, see [Connector hostname and TLS](https://docs.formal.ai/docs/guides/core-concepts/connectors/tls.md).

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

    Client->>Connector: Request
    Note over Connector, Resource: TLS, covered on this page
    Connector->>Resource: Request
    Resource-->>Connector: Response
    Connector-->>Client: Response
```

## TLS between the Connector and Resources

You can configure TLS settings between the Connector and resources on an individual resource level via our APIs, Terraform, or the Control Plane:

![](https://mintcdn.com/formal/z9GNtynV1YHUDYCN/assets/images/resource_tls_configuration.png?fit=max\&auto=format\&n=z9GNtynV1YHUDYCN\&q=85\&s=1b46c1b6ea53ebfd5ef8758f520918b7)

TLS settings for connections between the Connector and Resources are configured per-resource either via the UI or Terraform. The TLS configuration can be set to one of the following options: `disable`, `insecure-skip-verify`, `insecure-verify-ca-only` (verifies certificate chain but not hostname), or `verify-full`.

## Resource Hostnames

For resources with multiple instances or endpoints, you can register specific hostnames to distinguish between different access patterns. For example, a Postgres cluster might have separate reader and writer instances, each requiring different connection parameters.

### Configure Resource Hostnames

Use the `formal_resource_hostname` resource to register specific hostnames for your resources:

```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
# Reader instance hostname
resource "formal_resource_hostname" "postgres_reader" {
  name       = "postgres-reader"
  hostname   = "postgres-reader.example.com"
  resource_id = var.postgres_resource_id
}

# Writer instance hostname
resource "formal_resource_hostname" "postgres_writer" {
  name       = "postgres-writer"
  hostname   = "postgres-writer.example.com"
  resource_id = var.postgres_resource_id
}
```

### Resource Schema

#### Required Arguments

* **`hostname`** (String) - The hostname for this Resource hostname
* **`name`** (String) - The name of this Resource Hostname
* **`resource_id`** (String) - The ID of the Resource this hostname is linked to

#### Optional Arguments

* **`termination_protection`** (Boolean) - If set to true, this resource hostname cannot be deleted
* **`timeouts`** (Block, Optional) - Timeout configuration for the resource

#### Read-Only Attributes

* **`id`** (String) - The ID of this Resource Hostname

### Example: Multi-Instance Database Setup

```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
# Main Postgres resource
resource "formal_resource" "postgres_cluster" {
  name = "postgres-cluster"
  # ... other configuration
}

# Reader hostname
resource "formal_resource_hostname" "reader" {
  name       = "postgres-reader"
  hostname   = "postgres-reader.internal.company.com"
  resource_id = formal_resource.postgres_cluster.id
}

# Writer hostname
resource "formal_resource_hostname" "writer" {
  name       = "postgres-writer"
  hostname   = "postgres-writer.internal.company.com"
  resource_id = formal_resource.postgres_cluster.id
}
```

**Verify:**

```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
terraform plan
terraform apply
```

### Resource Hostname Specification

When connecting through the Formal Connector, you can target specific resource hostnames using the database name parameter. Use the format `database@resource-name@hostname-name` to specify both the resource and its specific hostname. Alternatively, you can use `database@resource-name` and include `formal_resource_hostname_name=hostname-name` in your connection parameters. This feature enables precise routing to specific database instances when you have multiple hostnames configured for a single resource, providing flexibility in managing multi-host database deployments.

**Example:**

```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
psql "host=localhost port=4002 user=idp:formal:human:user@example.com password=TOKEN dbname=mydb@my-resource@primary-hostname"
```

> [!TIP]
>
> If you connect through the [Formal Endpoint](https://docs.formal.ai/docs/guides/client-apps/cli.md#specify-resource-hostname), target a specific hostname with `formal connect RESOURCE_NAME@HOSTNAME_NAME` instead of encoding it in the database name. This is supported for PostgreSQL and MySQL resources.


## Related topics

- [Connector Hostname and TLS](https://docs.formal.ai/docs/guides/core-concepts/connectors/tls.md)
- [List resource hostnames](https://docs.formal.ai/api-reference/corev1resourceservice/list-resource-hostnames.md)
- [Create resource hostname](https://docs.formal.ai/api-reference/corev1resourceservice/create-resource-hostname.md)
- [Get resource hostname](https://docs.formal.ai/api-reference/corev1resourceservice/get-resource-hostname.md)
- [Update resource hostname](https://docs.formal.ai/api-reference/corev1resourceservice/update-resource-hostname.md)


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