integrations/terraform-provider-github

github_repository_file keeps sending empty commits with the same commit message despite no changes to file content

ahmadnassri opened this issue ยท 5 comments

(I had already opened an issue about this in the old repo, but after it moved here, seems to have been lost...)

Terraform Version

Terraform v0.14.5

Affected Resource(s)

  • github_repository_file

Terraform Configuration Files

resource "github_repository_file" "file" {
  for_each = {
    for x in flatten([
      for name, repo in var.repos : [
        for file in fileset("templates", "${repo.template}/**") : {
          repo     = name
          file     = trimprefix(file, "${repo.template}/")
          template = repo.template
        }
      ] if can(repo.template) && lookup(repo, "archived", false) == false
    ]) : "${x.repo}:${x.file}" => x
  }

  repository          = each.value.repo
  branch              = github_branch_default.default[each.value.repo].branch
  file                = each.value.file
  content             = file("templates/${each.value.template}/${each.value.file}")
  commit_message      = "chore(template): update ${each.value.file}"
  overwrite_on_create = true

  depends_on = [
    github_repository.repository
  ]
}

Expected Behavior

Should not be sending empty commits with the file content not having changed!

Actual Behavior

when running terraform plan everything looks correct, and there is no indication that any modifications to the referenced files will be triggered, but when running terraform apply a whole bunch of empty commits are sent with the same commit message template

see this repo for a recent example: https://github.com/ahmadnassri/node-glob-promise/commits/master

all the commits starting with chore(template) are an example of this

I tried adding

  lifecycle {
    ignore_changes = [
      commit_message
    ]
  }

but that simply re-uses whatever the previous commit message was for the file and commits anyways!

Have you tried this?

  lifecycle {
    ignore_changes = [
      commit_author, 
      commit_email,
      commit_message
    ]
  }

It seems very buggy though, as you said with ignoring commit_message, it's re-used the previous commit message for the file. I'm going to test what happens with just ignoring the commit_email and commit_author (ie, not the message)

I had not tried ignoring the other two fields, but .. since the files were already created by and continue to use the same author / email (they are 100% managed by Terraform), I don't believe it would have made a difference

@ahmadnassri I just tested it and confirmed that ignoring the commit_author and commit_email meant it stopped detecting changes. Don't ignore the message, otherwise it'll modify the old commit message no matter what.

๐Ÿ‘‹ Hey Friends, this issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please add the Status: Pinned label if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!

@simontabor in #689 (comment)

Don't ignore the message, otherwise it'll modify the old commit message no matter what.

Using v5.42.0 I cannot confirm that ignoring commit_message still leads to that situation. I see neither any empty commits nor any non-empty commits with old messages arrive to my repo.