这是indexloc提供的服务,不要输入任何密码
Skip to content

Bug: requests to create environment variables for custom environments are created with the wrong target #255

@qlimenoque

Description

@qlimenoque

Hi, I'm running into an error when I'm trying to create an Environment Variable resource for Custom Environment

tldr

Expected behavior:
The API should create an environment variable only for the Custom Environment with the corresponding ID

How it works now:
The API tries to create an environment variable with a target that was not specified anywhere.

Details

This is an example of the resource I am trying to create

resource “vercel_project_environment_variable” “test_sensitive” {
  for_each = try(var.config.env.test.sensitive, {})
  project_id = vercel_project.this.id
  comment = “Sensitive test environment variable”
  key = each.key
  value = each.value
  sensitive = true
  custom_environment_ids = [
    vercel_custom_environment.test.id,
  ]

  lifecycle {
    create_before_destroy = true
  }
}

But I get the following error

Could not create project environment variable, unexpected error: ENV_ALREADY_EXISTS - Another Environment Variable with the same Name and Environment exists in your project. Remove it or choose a different Name or Environment: unable to list environment variables to detect conflict: %!s(<nil>)

First of all, I noticed that the latest version of the API for /projects/ is v10, but the provider makes requests to v9.

After updating the version of the API used locally, I continued debugging POST requests and found out that the Vercel API was trying to create an environment variable with an incorrect target that was not even specified in the request (below is an example of a cURL request that I caught)

Request

curl 'https://api.vercel.com/v10/projects/prj_XXXXXXXXXXXXX/env?teamId=team_YYYYYYYYYYY' \
-X POST \
-H 'Host: api.vercel.com' \
-H 'User-Agent: terraform-provider-vercel/2.8.0-SNAPSHOT-35219ba' \
-H 'Authorization: Bearer TOKEN' \
-H 'Content-Type: application/json' \
--data-raw '{“key”: “NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY”, “value”: “TEST”, “customEnvironmentIds”:[“env_TTTTTTTTTTTTTTTTTT”], 
“type”: “sensitive”, “comment”: “Sensitive test environment variable”}'

Response:

{
  { “error”: {
    “code": “ENV_CONFLICT”,
    “message": “A variable with the name `NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY` already exists for the target preview.”
    “key": “key”,
    “envVarKey": “NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY”
  },
  “failed": [
    {
      “error": {
        “code": “ENV_CONFLICT”,
        “message": “A variable with the name `NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY` already exists for the target preview.”
        “key": “key”,
        “envVarKey": “NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY”
      }
    }
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions