# Deploying ENSNode with Terraform

This guide will help you deploy ENSNode using Terraform to Render. The Terraform configuration provides a complete infrastructure setup including database, ENSIndexer, ENSRainbow, and other required services.

:::note[Important]
These Terraform scripts are currently specific to ENSNode instances hosted by NameHash Labs. While these scripts provide a good starting point for deploying your own ENSNode instance, you will need to make modifications to suit your specific deployment needs. We plan to generalize these scripts in the future to better support community deployments.
:::

[Example Terraform Configuration](https://github.com/namehash/ensnode/tree/main/terraform)

## Prerequisites

- [Terraform](https://www.terraform.io/downloads.html) installed
- [Render](https://render.com/) account
- Render API token (generate from https://render.com/docs/api#1-create-an-api-key)
- RPC URLs for the chains you want to support (Mainnet, Sepolia, Base, Linea)
- AWS account (for DNS management)
- AWS S3 bucket defined inside AWS account - `ensnode-terraform` (for Terraform state)

:::note[Postgres Requirement]
ENSIndexer runs `CREATE EXTENSION IF NOT EXISTS pg_trgm` at startup to back partial-name search indexes. Render's managed Postgres has [`pg_trgm`](https://www.postgresql.org/docs/current/pgtrgm.html) available by default; if you adapt this configuration to a different provider, confirm the extension is available for installation on your Postgres plan.
:::

## Configuration

Copy `.env.sample` to `.env.local` and fill in your configuration values:

```bash
# ENSNode configuration
ensnode_version                           = "0.0.0"  # pin to the specific version you want to use as found at https://github.com/namehash/ensnode/releases
ensrainbow_searchlight_label_set_version  = "1" # pin to the specific version, see https://ensnode.io/ensrainbow/concepts/glossary#label_set_version
anthropic_api_key                         = "your_anthropic_api_key"

# Render configuration
render_api_key            = "your_render_api_key"
render_owner_id           = "your_render_owner_id"
render_environment        = "your_render_environment"

# Mainnet RPC URLs
ethereum_mainnet_rpc_url  = "your_ethereum_mainnet_rpc_url"
base_mainnet_rpc_url      = "your_base_mainnet_rpc_url"
linea_mainnet_rpc_url     = "your_linea_mainnet_rpc_url"
arbitrum_mainnet_rpc_url  = "your_arbitrum_mainnet_rpc_url"
scroll_mainnet_rpc_url    = "your_scroll_mainnet_rpc_url"

# Sepolia RPC URLs
ethereum_sepolia_rpc_url   = "your_ethereum_sepolia_rpc_url"
base_sepolia_rpc_url      = "your_base_sepolia_rpc_url"
linea_sepolia_rpc_url     = "your_linea_sepolia_rpc_url"
optimism_sepolia_rpc_url  = "your_optimism_sepolia_rpc_url"
arbitrum_sepolia_rpc_url  = "your_arbitrum_sepolia_rpc_url"
scroll_sepolia_rpc_url    = "your_scroll_sepolia_rpc_url"
```

## Infrastructure Components

The Terraform configuration sets up the following components:

- Render
  - Render project and environment
  - PostgreSQL database
  - ENSIndexer services
  - ENSRainbow service
- AWS
  - DNS configuration

## Deployment Steps

1. Initialize Terraform:

```bash
terraform init
```

2. Review the planned changes:

```bash
terraform plan
```

3. Apply the configuration:

```bash
terraform apply
```

## Cleanup

To destroy the infrastructure:

```bash
terraform destroy
```