integrations / terraform-provider-github

Terraform GitHub provider
https://www.terraform.io/docs/providers/github/
MIT License
887 stars 730 forks source link

[BUG]: github_repository template `include_all_branches = true` not applying correctly #2130

Open cclaes-dsi opened 7 months ago

cclaes-dsi commented 7 months ago

Expected Behavior

The repository based on the template should be created and include all the branches from the template. A second apply should not change anything when there haven't been any changes.

Actual Behavior

The repository is created successfully (with all the branches), but during a second apply it will change include_all_branches = false -> true while it was never set to false.

Terraform Version

Terraform v1.6.6 on darwin_amd64

Affected Resource(s)

Terraform Configuration Files

resource "github_repository" "this" {
  allow_auto_merge          = false
  allow_rebase_merge        = false
  allow_squash_merge        = false
  allow_update_branch       = false
  auto_init                 = true
  delete_branch_on_merge    = true
  description               = var.description
  merge_commit_message      = "PR_TITLE"
  merge_commit_title        = "MERGE_MESSAGE"
  name                      = var.name

  template {
    include_all_branches = true
    owner                = var.organization
    repository           = var.create_development_branch ? "template-dev" : "template-main"
  }
}

Steps to Reproduce

Create a repository that is based on a template with include_all_branches = true, apply the resource. Apply again and it will suggest changing include_all_branches = false -> true

Debug Output

# First apply  
resource "github_repository" "this" {
.....
      + template {
          + include_all_branches = true
          + owner                = "XXX"
          + repository           = "template-main"
        }
    }

# Second apply without making any changes
~ resource "github_repository" "this" {
        id                          = "template-test-main"
        name                        = "template-test-main"
        # (33 unchanged attributes hidden)

      ~ template {
          ~ include_all_branches = false -> true
            # (2 unchanged attributes hidden)
        }

        # (1 unchanged block hidden)
    }

Panic Output

No response

Code of Conduct

cclaes-dsi commented 7 months ago

This has been tested by setting auto_init = false as well, but it had the same result.

ethanrucinski commented 4 months ago

I've proposed a solution to this in my PR. I don't believe the GitHub API allows retrieving this value from an existing GitHub repository. I proposed simply persisting the provided value from the template into state as it cannot be updated on or retrieved from an existing repository.