Skip to content

Instantly share code, notes, and snippets.

@5hanth
Created March 27, 2025 17:18
Show Gist options
  • Save 5hanth/bffa0fea46c10b77da43aaa5c81bb0d8 to your computer and use it in GitHub Desktop.
Save 5hanth/bffa0fea46c10b77da43aaa5c81bb0d8 to your computer and use it in GitHub Desktop.
Terraform: Update Vercel Environment Variables
  1. Place your .env file next to .tf file
  2. export TF_VAR_vercel_api_token="your-api-token"
  3. terraform init
  4. terraform apply -var="project_id=your-project-id" -var="vercel_team_id=your-team-id"
terraform {
required_providers {
vercel = {
source = "vercel/vercel"
version = "0.13.0"
}
}
}
provider "vercel" {
api_token = var.vercel_api_token
}
variable "vercel_api_token" {
description = "API token for Vercel"
type = string
sensitive = true
}
variable "vercel_team_id" {
description = "Vercel team ID (if using an organization)"
type = string
default = "" # Leave empty for personal projects
}
variable "project_id" {
description = "The ID of the Vercel project"
type = string
}
# Read environment variables from .env file
locals {
env_vars = { for line in split("\n", file(".env")) :
trimsuffix(split("=", line)[0], "") => trimsuffix(split("=", line)[1], "")
if length(trimspace(line)) > 0 && !startswith(line, "#")
}
}
# Create environment variables in Vercel
resource "vercel_project_environment_variable" "env_vars" {
for_each = local.env_vars
project_id = var.project_id
key = each.key
value = each.value
target = ["production", "preview"]
team_id = var.vercel_team_id # Added team_id at the resource level
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment