Skip to content

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

@ahmadnassri

Description

@ahmadnassri

(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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions