Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment Variable Edits Fail #118

Open
edelbalso opened this issue Dec 19, 2023 · 3 comments
Open

Environment Variable Edits Fail #118

edelbalso opened this issue Dec 19, 2023 · 3 comments

Comments

@edelbalso
Copy link

Hi, I've been using the pulumi-vercel provider with my team to manage multiple environments in various vercel projects, but it seems every time we change an environment variable, we're constantly faced with an error about the environment variable always existing, for example:

error: update failed

  vercel:index:ProjectEnvironmentVariable (pulumi-calculator_PREFECT_AIRTABLE_DEPLOYMENT_ID):
    error: Error creating project environment variable: 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.

  vercel:index:ProjectEnvironmentVariable (pulumi-api_WAREHOUSE_DATASETS):
    error: Error creating project environment variable: 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.

  vercel:index:ProjectEnvironmentVariable (pulumi-calculator_WAREHOUSE_DATASETS):
    error: Error creating project environment variable: 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.

  vercel:index:ProjectEnvironmentVariable (pulumi-api_PREFECT_AIRTABLE_DEPLOYMENT_ID):
    error: Error creating project environment variable: 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.

The code that sets this is a function that looks like this:

const VercelProjectOutputSchema = z
  .object({
    id: z.string(),
    teamId: z.string(),
    name: z.string(),
  })
  .strict()
type VercelProjectOutput = z.infer<typeof VercelProjectOutputSchema>

export type EnvOptions = Readonly<{
  key: string
  optional?: true
}>

export function setRequiredEnvVars(project: VercelProjectOutput, env: EnvOptions[], branch: null | DeployBranch) {
  assertConfigEnvVars(env)
  env.map((e) => {
    const value = config.get(e.key)
    if (!value && e.optional) return
    if (!value) throw new Error(`required env var ${e.key} is not set in pulumi config`)

    const args = new vercel.ProjectEnvironmentVariable(`${project.name}_${e.key}`, {
      projectId: project.id,
      key: e.key,
      value,
      targets: [vercelEnv],
      teamId: project.teamId,
      gitBranch: branch ? branch : undefined,
    })
  })
}

We're having a hard time identifying the pattern that causes this error to trigger. It seems like MOST of the time, when we change an environment variable's setting in our config, it will fail and say the env var already exists instead of updating it.

Here's the summary:


     Type                                        Name                                              Status                   Info
     pulumi:pulumi:Stack                         incentives-production                             **failed**               1 error; 1 warning
 +-  ├─ vercel:index:ProjectEnvironmentVariable  pulumi-api_PREFECT_AIRTABLE_DEPLOYMENT_ID         **replacing failed**     1 error
 +-  ├─ vercel:index:ProjectEnvironmentVariable  pulumi-calculator_WAREHOUSE_DATASETS              **replacing failed**     1 error
 +-  ├─ vercel:index:ProjectEnvironmentVariable  pulumi-calculator_PREFECT_AIRTABLE_DEPLOYMENT_ID  **replacing failed**     1 error
 +-  └─ vercel:index:ProjectEnvironmentVariable  pulumi-api_WAREHOUSE_DATASETS                     **replacing failed**     1 error
 
Diagnostics:
  vercel:index:ProjectEnvironmentVariable (pulumi-api_WAREHOUSE_DATASETS):
    error: Error creating project environment variable: 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.
 
  pulumi:pulumi:Stack (incentives-production):
    warning: Undefined value (domains) will not show as a stack output.
    error: update failed
 
  vercel:index:ProjectEnvironmentVariable (pulumi-api_PREFECT_AIRTABLE_DEPLOYMENT_ID):
    error: Error creating project environment variable: 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.
 
  vercel:index:ProjectEnvironmentVariable (pulumi-calculator_WAREHOUSE_DATASETS):
    error: Error creating project environment variable: 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.
 
  vercel:index:ProjectEnvironmentVariable (pulumi-calculator_PREFECT_AIRTABLE_DEPLOYMENT_ID):
    error: Error creating project environment variable: 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.
 
Outputs:
    vercelProjects: [
        [0]: <null>
        [1]: <null>
        [2]: <null>
        [3]: <null>
        [4]: <null>
    ]

Resources:
    71 unchanged

Here's the diff:

pulumi:pulumi:Stack: (same)
    [urn=urn:pulumi:production::incentives::pulumi:pulumi:Stack::incentives-production]
    > pulumi:pulumi:StackReference: (read)
        [id=our-team-name/incentives/domain]
        [urn=urn:pulumi:production::incentives::pulumi:pulumi:StackReference::our-team-name/incentives/domain]
        name: "our-team-name/incentives/domain"
    > pulumi:pulumi:StackReference: (read)
        [id=our-team-name/incentives/vercel]
        [urn=urn:pulumi:production::incentives::pulumi:pulumi:StackReference::our-team-name/incentives/vercel]
        name: "our-team-name/incentives/vercel"
warning: Undefined value (domains) will not show as a stack output.
    ++vercel:index/projectEnvironmentVariable:ProjectEnvironmentVariable: (create-replacement)
        [id=__________bQhTHq]
        [urn=urn:pulumi:production::incentives::vercel:index/projectEnvironmentVariable:ProjectEnvironmentVariable::pulumi-api_WAREHOUSE_DATASETS]
        [provider=urn:pulumi:production::incentives::pulumi:providers:vercel::default_0_15_4_github_/api.github.com/pulumiverse::118589ca-c41b-4f9a-a959-efe36c5f7ec3]
        key      : "WAREHOUSE_DATASETS"
        projectId: "prj________________wIHEzJAnArEO1"
        targets  : [
            [0]: "production"
        ]
        teamId   : "team________________doK8U6E5f"
        value    : [secret]
    ++vercel:index/projectEnvironmentVariable:ProjectEnvironmentVariable: (create-replacement)
        [id=__________AhrRHQ]
        [urn=urn:pulumi:production::incentives::vercel:index/projectEnvironmentVariable:ProjectEnvironmentVariable::pulumi-api_PREFECT_AIRTABLE_DEPLOYMENT_ID]
        [provider=urn:pulumi:production::incentives::pulumi:providers:vercel::default_0_15_4_github_/api.github.com/pulumiverse::118589ca-c41b-4f9a-a959-efe36c5f7ec3]
        key      : "PREFECT_AIRTABLE_DEPLOYMENT_ID"
        projectId: "prj________________wIHEzJAnArEO1"
        targets  : [
            [0]: "production"
        ]
        teamId   : "team________________doK8U6E5f"
        value    : [secret]
    ++vercel:index/projectEnvironmentVariable:ProjectEnvironmentVariable: (create-replacement)
        [id=__________anSj8U]
        [urn=urn:pulumi:production::incentives::vercel:index/projectEnvironmentVariable:ProjectEnvironmentVariable::pulumi-calculator_WAREHOUSE_DATASETS]
        [provider=urn:pulumi:production::incentives::pulumi:providers:vercel::default_0_15_4_github_/api.github.com/pulumiverse::118589ca-c41b-4f9a-a959-efe36c5f7ec3]
        key      : "WAREHOUSE_DATASETS"
        projectId: "prj________________15lOMFU7WDgJj"
        targets  : [
            [0]: "production"
        ]
        teamId   : "team________________doK8U6E5f"
        value    : [secret]
    ++vercel:index/projectEnvironmentVariable:ProjectEnvironmentVariable: (create-replacement)
        [id=__________hDXaSz]
        [urn=urn:pulumi:production::incentives::vercel:index/projectEnvironmentVariable:ProjectEnvironmentVariable::pulumi-calculator_PREFECT_AIRTABLE_DEPLOYMENT_ID]
        [provider=urn:pulumi:production::incentives::pulumi:providers:vercel::default_0_15_4_github_/api.github.com/pulumiverse::118589ca-c41b-4f9a-a959-efe36c5f7ec3]
        key      : "PREFECT_AIRTABLE_DEPLOYMENT_ID"
        projectId: "prj________________15lOMFU7WDgJj"
        targets  : [
            [0]: "production"
        ]
        teamId   : "team________________doK8U6E5f"
        value    : [secret]
error: Error creating project environment variable: 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.
error: Error creating project environment variable: 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.
error: Error creating project environment variable: 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.
error: Error creating project environment variable: 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.
error: update failed
 
    --outputs:--
    vercelProjects: [
        [0]: <null>
        [1]: <null>
        [2]: <null>
        [3]: <null>
        [4]: <null>
    ]

We're 100% confident that nobody is going into the vercel UI and manually changing the env vars, nor the pulumi state in the pulumi UI.

Anybody else seen behavior like this?

@iajax
Copy link

iajax commented Jan 4, 2024

@edelbalso Got the same issue. Did you fix it?

Previewing update (dev)

View Live: https://app.pulumi.com/iajax/service-directory/dev/previews/29b89b3c-82ca-4ad3-a0ac-0a6f4dbef62a


    pulumi:pulumi:Stack service-directory-dev running 
    pkg:index:MbFrontend web  
    pkg:index:MbProject web  
@ Previewing update....
    vercel:index:Project web  
    vercel:index:ProjectDomain webDomain  
 ++ vercel:index:ProjectEnvironmentVariable webKvRestApiUrlEnvironmentVariable create replacement 
 +- vercel:index:ProjectEnvironmentVariable webKvRestApiUrlEnvironmentVariable replace 
 ++ vercel:index:ProjectEnvironmentVariable webKvRestApiTokenEnvironmentVariable create replacement 
 +- vercel:index:ProjectEnvironmentVariable webKvRestApiTokenEnvironmentVariable replace 
    vercel:index:ProjectEnvironmentVariable webVercelUrlEnvironmentVariable  
    vercel:index:ProjectDomain webRedirect  
 -- vercel:index:ProjectEnvironmentVariable webKvRestApiTokenEnvironmentVariable delete original 
 -- vercel:index:ProjectEnvironmentVariable webKvRestApiUrlEnvironmentVariable delete original 
    pulumi:pulumi:Stack service-directory-dev  
Resources:
    +-2 to replace
    7 unchanged

Updating (dev)

View Live: https://app.pulumi.com/iajax/service-directory/dev/updates/16


    pulumi:pulumi:Stack service-directory-dev running 
    pkg:index:MbFrontend web  
@ Updating.....
    pkg:index:MbProject web  
@ Updating....
    vercel:index:Project web  
    vercel:index:ProjectDomain webDomain  
 ++ vercel:index:ProjectEnvironmentVariable webKvRestApiUrlEnvironmentVariable creating replacement (0s) 
    vercel:index:ProjectEnvironmentVariable webVercelUrlEnvironmentVariable  
 ++ vercel:index:ProjectEnvironmentVariable webKvRestApiTokenEnvironmentVariable creating replacement (0s) 
    vercel:index:ProjectDomain webRedirect  
@ Updating....
 ++ vercel:index:ProjectEnvironmentVariable webKvRestApiUrlEnvironmentVariable creating replacement (1s) error: Error creating project environment variable: 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.
 ++ vercel:index:ProjectEnvironmentVariable webKvRestApiUrlEnvironmentVariable **creating failed** error: Error creating project environment variable: 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.
@ Updating....
 ++ vercel:index:ProjectEnvironmentVariable webKvRestApiTokenEnvironmentVariable creating replacement (1s) error: Error creating project environment variable: 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.
 ++ vercel:index:ProjectEnvironmentVariable webKvRestApiTokenEnvironmentVariable **creating failed** error: Error creating project environment variable: 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.
    pulumi:pulumi:Stack service-directory-dev running error: update failed
    pulumi:pulumi:Stack service-directory-dev **failed** 1 error
Diagnostics:
  pulumi:pulumi:Stack (service-directory-dev):
    error: update failed

  vercel:index:ProjectEnvironmentVariable (webKvRestApiTokenEnvironmentVariable):
    error: Error creating project environment variable: 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.

  vercel:index:ProjectEnvironmentVariable (webKvRestApiUrlEnvironmentVariable):
    error: Error creating project environment variable: 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.

Resources:
    7 unchanged

Duration: 6s

@edelbalso
Copy link
Author

No, it continues to be a real pain point. We can't seem to figure it out.

@omercnet
Copy link
Collaborator

they made some changes and I mirrored them here, can you try again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants