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

# Deploy Fastly Compute Proxy Integration with Terraform

<Note>
  **Before you start: Read the general Fastly Compute guide**

  This document only covers deploying the Fingerprint Fastly Compute proxy integration using the [Terraform module](https://github.com/fingerprintjs/terraform-fastly-compute-fingerprint-proxy-integration). It assumes you have already read the general [Fastly Compute guide](/docs/fastly-compute-proxy-integration) and completed the [step 1](/docs/fastly-compute-proxy-integration#step-1-create-a-fingerprint-proxy-secret).
  If you want to deploy manually using the Fastly web interface instead of the Terraform module to install the integration, see [Deploy Fastly Compute manually](/docs/deploy-fastly-compute-manually).
</Note>

<Warning>
  **Limitations**

  This integration is exclusively supported for customers on the **Enterprise** Plan. Other customers are encouraged to use [Custom subdomain setup](/docs/custom-subdomain-setup) or [Cloudflare Proxy Integration](/docs/cloudflare-integration).
</Warning>

## Step 2.1: Create an empty Fastly Compute service

Due to Terraform's resource dependency limitations, you must create an empty Fastly Compute service using the Fastly web interface before using the Terraform module:

1. Log in to your [Fastly web interface](https://manage.fastly.com/).
2. Navigate to **Compute** > **Create service** and click **Create an Empty Service**.
3. Set a name that suits you, for example, `fingerprint-fastly-compute-proxy-integration`.
4. Copy the Compute Service ID displayed below the service name at the top of the page. You'll need it in the next steps to import the service into the Terraform state.

## Step 2.2: Get a Fastly API token

Grab your existing Fastly API token or [create a new one](https://manage.fastly.com/account/personal/tokens/new).

* Your token needs to have a `global` scope.
* See the [Fastly documentation](https://www.fastly.com/documentation/guides/account-info/account-management/using-api-tokens/#creating-api-tokens) for more details.

## Step 2.3: Add and configure the Terraform module

Create the `main.tf` file in your Terraform project directory. Populate the properties with the values generated in the previous steps.

```terraform theme={"theme":"github-dark-dimmed"}
terraform {
  required_version = ">=1.5"
}

module "fingerprint_fastly_compute_integration" {
  source             = "fingerprintjs/compute-fingerprint-proxy-integration/fastly"
  fastly_api_token   = "FASTLY_API_TOKEN"
  integration_domain = "metrics.yourwebsite.com"
  service_id         = "FASTLY_COMPUTE_SERVICE_ID"
  region             = "us" # or "eu" or "ap"
}
```

You can see the full list of the Terraform module's variables below:

| Variable                             | Description                                                                                                                                                                                    | Required | Example                                                 |
| ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------------------------------------------------- |
| `fastly_api_token`                   | Your Fastly API token                                                                                                                                                                          | Required | `"ABC123...xyz"`                                        |
| `integration_domain`                 | Domain used for your proxy integration                                                                                                                                                         | Required | `"metrics.yourwebsite.com"`                             |
| `service_id`                         | ID of your empty Fastly Compute service                                                                                                                                                        | Required | `"SU1Z0isxPaozGVKXdv0eY"`                               |
| `region`                             | Region for the Fingerprint API. One of: `us`, `eu`, `ap`.                                                                                                                                      | Optional | `"us"`                                                  |
| `agent_script_download_path`         | Path to download the JavaScript agent (only required for JavaScript agent v3)                                                                                                                  | Optional | `"4fs80xgx"`                                            |
| `get_result_path`                    | Path for identification requests (only required for JavaScript agent v3)                                                                                                                       | Optional | `"vpyr9bev"`                                            |
| `integration_name`                   | Name of the Fastly service                                                                                                                                                                     | Optional | `"fingerprint-fastly-compute-proxy-integration"`        |
| `download_asset`                     | Whether to auto-download the latest release                                                                                                                                                    | Optional | `true`                                                  |
| `compute_asset_name`                 | Custom filename if not downloading the official artifact                                                                                                                                       | Optional | `"fingerprint-fastly-compute-proxy-integration.tar.gz"` |
| `asset_version`                      | GitHub release version of the proxy integration (See [GitHub releases](https://github.com/fingerprintjs/terraform-fastly-compute-fingerprint-proxy-integration/releases))                      | Optional | `"latest"`                                              |
| `manage_fastly_config_store_entries` | Manage Fastly Config Store entries via terraform, see [Fastly documentation](https://registry.terraform.io/providers/fastly/fastly/latest/docs/resources/configstore_entries#manage_entries-1) | Optional | `false`                                                 |

> Updating Config Store Entries
>
> To have Terraform manage your Fastly Config Store entries, set the `manage_fastly_config_store_entries` variable to `true`.
> By default, these entries must be managed outside of Terraform.
> You can learn more about the reason behind this default behavior in the [official Fastly documentation](https://registry.terraform.io/providers/fastly/fastly/latest/docs/resources/configstore_entries#manage_entries-1).
> After updating Config Store Entries, whether through Terraform or manually, it may take a few minutes for the changes to take effect.

## Step 2.4: Deploy your changes

1. Initialize Terraform:

```shell theme={"theme":"github-dark-dimmed"}
terraform init
```

2. Download the latest available proxy integration release artifact:

```shell theme={"theme":"github-dark-dimmed"}
terraform apply -target=module.fingerprint_fastly_compute_integration.module.compute_asset
```

You will get this warning: `Warning: Resource targeting is in effect...`. You can safely ignore it. The module is downloading the latest release artifact so that it can upload it as a Compute package in the next `apply` command.

3. Import your empty Compute service into Terraform state:

```shell theme={"theme":"github-dark-dimmed"}
terraform import module.fingerprint_fastly_compute_integration.fastly_service_compute.fingerprint_integration "<your service ID>"
```

> Note: The module appends the service ID to all resource names to support multiple integrations in the same Fastly account.

4. Deploy the integration:

```shell theme={"theme":"github-dark-dimmed"}
terraform apply
```

<Note>
  **Safari accuracy on non-Fastly websites**

  For maximum accuracy, both your website and your proxy integration should be served by Fastly.

  You can use the Fastly Compute proxy integration even if your website is not served by Fastly, but this setup will likely limit Safari cookie lifetime to 7 days, resulting in lower accuracy. Because your website and the proxy integration will likely have different IP ranges, Safari will apply the same cookie lifetime cap as for third-party CNAME cloaking. This is still an improvement over third-party cookies getting blocked entirely by Safari.
</Note>

## Step 2.5: Add the proxy secret

Fastly [does not allow](https://registry.terraform.io/providers/fastly/fastly/latest/docs/resources/secretstore) storing or setting secrets using Terraform. Instead, you need to add the proxy secret manually:

1. Navigate to the Fastly web interface > **Resources** > **Secret Stores**.
2. Find the secret store created by Terraform: `Fingerprint_Compute_Secret_Store_<your service ID>`.
3. Open it and click **Add item**.
4. Set **Key** to `PROXY_SECRET`.
5. Set **Value** to your Fingerprint proxy secret created in [Step 1](/docs/fastly-compute-proxy-integration#step-1-create-a-fingerprint-proxy-secret).

Alternatively, you could use the Fastly API or CLI to set the secret.

<Note>
  **Note: Proxy secret required**

  Proxied identification requests without a valid proxy secret will result in an authentication error and not receive identification results.
</Note>

## Step 2.6: Configure your domain

To complete your domain setup, see [Issue a TLS certificate for your subdomain](/docs/deploy-fastly-compute-manually#step-2-6-issue-a-tls-certificate-for-your-subdomain).

## Step 3: Configure the client agent

Go back to the general Fastly Compute guide to [Configure the Fingerprint client agent to use your service](/docs/fastly-compute-proxy-integration#step-3-configure-the-fingerprint-client-agent-to-use-your-service).

## Updating the integration

The Terraform installation of the Fastly Compute proxy integration does not include any mechanism for automatic updates. To keep your integration up to date, please run `terraform apply` regularly.

## Removing the integration

To remove the integration, run:

```shell theme={"theme":"github-dark-dimmed"}
terraform destroy
```
