In this guide, you will learn how to apply a series of firewall rules to multiple projects or teams by using Terraform to create configurations that are straightforward to manage and scalable.
- A Vercel account with access to the projects you want to manage.
- The Terraform CLI installed. Follow the Install Terraform guide to do this for all operating systems.
- A Vercel personal token to authenticate with the Terraform provider.
- The Vercel Terraform Provider installed.
Create a folder for your terraform setup
Create a .env file or export your token:
Then, create a Terraform file in your project folder and add Vercel as a provider.
Create a file called main.tf and paste the following content:
Run the following in the command line to initialize the project using main.tf:
If your Vercel projects already exist, import them into Terraform state:
Where prj_abc123 and prj_def456 are the Vercel project IDs.
This links your Terraform code to existing Vercel projects.
Your configuration will include the following rules:
- Suspicious user agents — Blocks known bots/crawlers.
- AI bots — Detects requests from AI services like GPTBot, Claude, etc.
- OFAC countries — Blocks traffic from sanctioned regions.
- WordPress URLs — Blocks scanners looking for common WordPress endpoints.
- Rate limiting — Limits API request frequency (per IP or JA4 fingerprint).
Define them in a vercel_firewall.tf file as follows:
- Suspicious user agents
- AI bots
- OFAC countries
- WordPress URLs
- Rate limiting
These are defined once and reused across both projects.
Each project (PROJECT_1, PROJECT_2) has a vercel_firewall_config that applies the rules defined in your variables.
For PROJECT_1, connect the following rules
And for PROJECT_2, connect the following rules:
This structure lets you enforce a consistent policy across multiple projects.
Run the following from the command line:
This will apply the rules defined for each project as defined for PROJECT_1 and PROJECT_2. Terraform loads all .tf files in the current working directory, merges them, and treats them as a single configuration.
- Test with
terraform planto preview changes before applying. - Store the project IDs and sensitive values using environment variables.