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_file import not setting branch argument correctly #2020

Closed
1 task done
rhughes1 opened this issue Nov 17, 2023 · 3 comments
Closed
1 task done
Labels
Status: Stale Used by stalebot to clean house Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented

Comments

@rhughes1
Copy link
Contributor

Expected Behavior

Expected to see the branch argument populated with the Terraform state file and that the plan would not force replace the resource.

Actual Behavior

The Terraform state file recorded the branch as null. When a terraform plan occurs after the import, Terraform wants to force replace the resource.

  # github_repository_file.readme must be replaced
  # (imported from "test-import/README.md")
  # Warning: this will destroy the imported resource
-/+ resource "github_repository_file" "readme" {
      + branch              = "main" # forces replacement
      ~ commit_message      = "Initial commit of the module" -> "chore: Update repository scaffolding"
      ~ commit_sha          = "10d7666466de45cf1d2468bb4c201d8edb752b28" -> (known after apply)
      ~ id                  = "test-import/README.md" -> (known after apply)
      ~ overwrite_on_create = false -> true
      ~ ref                 = "main" -> (known after apply)
        repository          = "test-import"
      ~ sha                 = "c05f3f5777527c4f852f9f03d3f83gh18671a01f" -> (known after apply)
    }

Looking at the import logic, it only seems to set the branch if you import specifying the branch (ie with a :). However, when I do specify the branch within the import (ie test-import/README:main as the ID in the CLI or import configuration) it still shows as a force replacement.

The logic should set the branch if the default branch is being used explicitly.

Terraform Version

Terraform v1.6.3
integrations/github v5.42.0

Affected Resource(s)

  • github_repository_file

Terraform Configuration Files

import {
  id = "testorg/README.md"
  to = "github_repository_file.readme"
}

resource "github_repository_file" "readme" {
  repository = "test-import"
  branch     = "main"
  file       = "README.md"
  content    = "I'm a README file"
  commit_message      = "testing import"
  commit_author       = "test"
  commit_email        = "[email protected]"
  overwrite_on_create = true
}

Steps to Reproduce

  1. Import a file off of the repository's default branch (ie main). This can be done either with the Terraform CLI using terraform import github_repository_file.readme testorg/README.md or the Terraform import configuration.
  2. Run a terraform plan

Debug Output

No response

Panic Output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@rhughes1 rhughes1 added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Nov 17, 2023
Copy link

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@kfcampbell kfcampbell added Status: Up for grabs Issues that are ready to be worked on by anyone and removed Status: Triage This is being looked at and prioritized labels Nov 21, 2023
@kfcampbell kfcampbell moved this from 🆕 Triage to 🔥 Backlog in 🧰 Octokit Active Nov 21, 2023
@chris3ware
Copy link

chris3ware commented Nov 24, 2023

I believe #1128 may have caused this because v5.19.0 works ok, but v5.20.0 wants to replace all my github_repository_file_resources because the branch has changed from main => null.

However, providing the branch argument fixes this.

Copy link

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

@github-actions github-actions bot added the Status: Stale Used by stalebot to clean house label Aug 24, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 31, 2024
@github-project-automation github-project-automation bot moved this from 🔥 Backlog to ✅ Done in 🧰 Octokit Active Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale Used by stalebot to clean house 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
Development

No branches or pull requests

3 participants