Skip to content

Conversation

nebrass
Copy link

@nebrass nebrass commented Sep 17, 2025

fix(actions): Handle existing environment variables on create

Description

This PR fixes an issue with the github_actions_environment_variable resource where it would fail with a 409 Conflict error if the environment variable already existed in GitHub but not in the Terraform state. This typically occurs when a variable is created manually via the GitHub UI and then later managed by Terraform.

The Create function for the resource has been updated to handle this scenario gracefully. It now attempts to Update the variable if it already exists, effectively performing an "upsert" operation. This makes the resource more robust and prevents unexpected errors.

Fixes #2328

How to test

An acceptance test has been added to cover this specific scenario. You can run the test with the following command:

TF_ACC=1 go test -v ./github -run ^TestAccGithubActionsEnvironmentVariable_alreadyExists$

This test:

  1. Creates a repository and an environment.
  2. Creates an environment variable using the GitHub API to simulate an out-of-band creation.
  3. Applies a Terraform configuration that defines the same variable.
  4. Verifies that Terraform successfully "adopts" the variable without any errors.

…riables on create

The `github_actions_environment_variable` resource would fail with a 409 Conflict error if the environment variable already existed in GitHub but not in the Terraform state. This could happen if the variable was created manually in the GitHub UI.

This commit changes the create function to handle this conflict. It now attempts to update the variable if it already exists, effectively performing an "upsert" operation.

This makes the resource more resilient and avoids unexpected errors when managing existing resources.

Fixes integrations#2328
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

Successfully merging this pull request may close these issues.

1 participant