Skip to content

github_repository needs to not fail if repository doesn't exist #933

Closed

Description

@ronmpatel

Affected Resource(s)
github_repository

For a new repository the following will fail the entire plan/apply. It would be nice if we return null so that we could use that to conditionally check if repository exist or not.

Our use case is to create the repository only if does not exist.

Terraform Configuration Files
data "github_repository" "existing_repository" {
  full_name   = "${var.github_org}/${var.repo}"
}

Error Output
GET https://api.github.com/repos// 404 Not Found []

Reference
We have this for branch here

Activity

  1. added
    Type: Bug
    on Nov 2, 2021
  2. GauravJain98 commented on Feb 6, 2025

    @GauravJain98

    This is so different from the normal terraform standard! I have no clue why they did this actively!!!

  3. GauravJain98 commented on Feb 6, 2025

    @GauravJain98
  4. GauravJain98 commented on Feb 6, 2025

    @GauravJain98
    data "github_repository" "repository" {
      name = coalesce(var.application.github_repo_name, var.name)
      lifecycle {
        postcondition {
          condition     = self.full_name != null
          error_message = "Repository does not exist for ${coalesce(var.application.github_repo_name, var.name)}"
        }
      }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: Bugd/repository

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions