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

[BUG] github_repository resource errors with squash_merge/merge commit message/title #1730

Closed
aliculPix4D opened this issue Jun 16, 2023 · 0 comments · Fixed by #1834
Closed
Labels
Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented

Comments

@aliculPix4D
Copy link

aliculPix4D commented Jun 16, 2023

Short summary:
resource_github_repository tries to update the fields squash_merge_commit_message/squash_merge_commit_title
eventhough the allow_squash_merge is set to false. The terraform state is correctly updated with default values (i.e

) but the Github API call can't be done because the allow_squash_merge is set to false before and the endpoints to configure squash_merge_commit_message/squash_merge_commit_title are not available anymore.

Note that the same issue will occur with both: squash_merge_commit_message/squash_merge_commit_title and merge_commit_message/merge_commit_title pairs.

Minimal example to reproduce the bug:

Step 1: apply the following configuraion.

terraform {
  required_version = "1.4.6"

  required_providers {
    github = {
      source  = "integrations/github"
      version = "5.25.1"
    }
  }
}

provider "github" {
  token = var.github_token
  owner = "yourOrganization"
}

variable "github_token" {
  type = string
}

resource "github_repository" "repo" {
  name        = "test-repository-name"
  allow_squash_merge = true
  squash_merge_commit_message = "PR_BODY"
  squash_merge_commit_title   = "PR_TITLE"
}

Step 2: change your configuration to :

resource "github_repository" "repo" {
  name        = "test-repository-name"
  allow_squash_merge = false
}

Step 3: and run terraform apply

Terraform will perform the following actions:

  # github_repository.repo will be updated in-place
  ~ resource "github_repository" "repo" {
      ~ allow_squash_merge          = true -> false
        id                          = "test-repository-name"
        name                    = "test-repository-name"
      ~ squash_merge_commit_message = "PR_BODY" -> "COMMIT_MESSAGES"
      ~ squash_merge_commit_title   = "PR_TITLE" -> "COMMIT_OR_PR_TITLE"
        # (29 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

will result in:

github_repository.repo: Modifying... [id=test-repository-name]
╷
│ Error: PATCH https://api.github.com/repos/yourOrganization/test-repository-name: 422 Validation Failed [{Resource:Repository Field:merge_commit_allowed Code:invalid Message:Sorry, you need to allow the squash merge strategy in order to set the default squash commit message title or message. (no_squash_merge_strategy)}]
│ 
│   with github_repository.repo,
│   on main.tf line 21, in resource "github_repository" "repo":
│   21: resource "github_repository" "repo" {
│ 
╵

Step 4: but the next terraform plan/apply will always be empty.
No changes. Your infrastructure matches the configuration.

Possibly connected to: #1295

@nickfloyd nickfloyd moved this from 🆕 Triage to 🔥 Backlog in 🧰 Octokit Active Jun 16, 2023
@kfcampbell kfcampbell added Type: Bug Something isn't working as documented Status: Up for grabs Issues that are ready to be worked on by anyone Priority: Normal labels Jun 20, 2023
@github-project-automation github-project-automation bot moved this from 🔥 Backlog to ✅ Done in 🧰 Octokit Active Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented
Projects
None yet
3 participants