Skip to content

[MAINT] Improve Import behaviour of github_default_branch - #3216

Merged
stevehipwell merged 34 commits into
integrations:mainfrom
F-Secure-web:fix-default-branch-import
Jun 24, 2026
Merged

stevehipwell merged 34 commits into
integrations:mainfrom
F-Secure-web:fix-default-branch-import

Conversation

@deiga

@deiga deiga commented Feb 21, 2026 •

Copy link
Copy Markdown
Collaborator

Resolves #2613


Before the change?

  • Resource didn't use Context-aware functions
  • Resource didn't use tflog for logging
  • Missing tests for Update and Import functionality

After the change?

  • Changes to use Context-aware functions
  • Changes to use tflog for logging
  • Adds support for repository renaming, by add repository_id field and removing ForceNew from repository

Pull request checklist

  • Schema migrations have been created if needed (example)
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

@github-actions

Copy link
Copy Markdown

👋 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 labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@github-actions github-actions Bot added the Type: Bug Something isn't working as documented label Feb 21, 2026
@deiga deiga added this to the v6.12.0 Release milestone Feb 22, 2026
@deiga
deiga force-pushed the fix-default-branch-import branch from 0e63837 to a31fc9f Compare March 8, 2026 21:14
@deiga
deiga requested a review from stevehipwell March 8, 2026 21:15
@deiga
deiga force-pushed the fix-default-branch-import branch from a31fc9f to cd4dd3d Compare May 11, 2026 02:08
@deiga
deiga marked this pull request as draft May 14, 2026 21:10
@deiga
deiga removed the request for review from stevehipwell May 17, 2026 13:22
@deiga
deiga force-pushed the fix-default-branch-import branch from b44b2a4 to 687ec04 Compare June 3, 2026 17:16
@deiga
deiga marked this pull request as ready for review June 3, 2026 17:16
@deiga
deiga force-pushed the fix-default-branch-import branch from b417ac4 to 055d00c Compare June 3, 2026 18:25
@deiga
deiga requested a review from Copilot June 3, 2026 18:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

These provider review instructions are being used.

This PR updates the github_branch_default resource to improve import and rename behavior, modernize the resource implementation to SDKv2 context-aware CRUD, and align logging and tests with current provider patterns.

Changes:

  • Refactors github_branch_default to use CreateContext/ReadContext/UpdateContext/DeleteContext, returns diag.Diagnostics, and uses tflog.
  • Adds rename-safe repository handling via repository_id + CustomizeDiff: diffRepository, and updates docs/templates to document the new exported attribute.
  • Expands acceptance coverage to include update and import scenarios using statecheck/plancheck.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
github/resource_github_branch_default.go Refactors resource to context-aware CRUD + tflog, adds repository_id, custom import handler, and rename-safe diffing.
github/resource_github_branch_default_test.go Adds/updates acceptance tests using modern statecheck/plancheck patterns for create/update/import coverage.
docs/resources/branch_default.md Documents exported repository_id attribute and clarifies import ID format.
templates/resources/branch_default.md.tmpl Mirrors docs updates for generated documentation (repository_id + import wording).

@deiga
deiga requested a review from stevehipwell June 3, 2026 19:50

@stevehipwell stevehipwell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a quick pre-pass to look at the coding patterns for a re-work. The multi line tflog statements make reviewing harder; as does the type checking but I think we need to keep that (other than for meta in the resource functions).

@deiga
deiga force-pushed the fix-default-branch-import branch from 9d51b80 to 85640c2 Compare June 4, 2026 11:18

@stevehipwell stevehipwell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the code for the repository_id addition is missing (e.g. migration, import, update ID modification). I'd also suggest that the docs be updated to the new pattern as part of this change given the attributes are being modified.

@deiga

deiga commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator Author

It looks like the code for the repository_id addition is missing (e.g. migration, import, update ID modification). I'd also suggest that the docs be updated to the new pattern as part of this change given the attributes are being modified.

🤦 Doh!
Good catch, adding that now

@deiga
deiga force-pushed the fix-default-branch-import branch from efdac3c to 4137ac7 Compare June 5, 2026 20:06
@deiga
deiga requested review from Copilot and stevehipwell June 5, 2026 20:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

@deiga
deiga requested a review from stevehipwell June 12, 2026 06:36

@stevehipwell stevehipwell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you wait for #3476 to be merged you can reuse the repo ID migration logic.

@deiga
deiga force-pushed the fix-default-branch-import branch from 6b9e94a to 0220d16 Compare June 21, 2026 20:27
Timo Sand added 18 commits June 24, 2026 10:18
Signed-off-by: Timo Sand <[email protected]>
Signed-off-by: Timo Sand <[email protected]>
Signed-off-by: Timo Sand <[email protected]>
Signed-off-by: Timo Sand <[email protected]>
Signed-off-by: Timo Sand <[email protected]>
Removing `etag` after rename made it visible that the GH API is eventually consistent when a branch is being renamed.

Signed-off-by: Timo Sand <[email protected]>
Signed-off-by: Timo Sand <[email protected]>
Signed-off-by: Timo Sand <[email protected]>
Signed-off-by: Timo Sand <[email protected]>
Signed-off-by: Timo Sand <[email protected]>
Signed-off-by: Timo Sand <[email protected]>
Signed-off-by: Timo Sand <[email protected]>
@deiga
deiga dismissed stale reviews from stevehipwell and robert-crandall via 826998a June 24, 2026 07:20
@deiga
deiga force-pushed the fix-default-branch-import branch from c9eb706 to 826998a Compare June 24, 2026 07:20

@stevehipwell stevehipwell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stevehipwell
stevehipwell merged commit 1eaeaeb into integrations:main Jun 24, 2026
13 of 19 checks passed
@deiga
deiga deleted the fix-default-branch-import branch June 24, 2026 09:17
br3ndonland added a commit to br3ndonland/infrastructure-live that referenced this pull request Jul 29, 2026
The configuration embeds GitHub Pages in github_repository and
iterates over resource objects. This causes deprecated attribute
warnings and persistent workflow source diffs during the provider
upgrade.

This commit will:

- Manage workflow-based Pages with github_repository_pages.
- Import the three existing Pages sites without recreating them.
- Derive resource instances from input maps while keeping dependencies.
- Remove the obsolete workflow source-path setting.

- #12
- https://github.com/integrations/terraform-provider-github/releases/tag/v6.13.0
- integrations/terraform-provider-github#3216
br3ndonland added a commit to br3ndonland/infrastructure-live that referenced this pull request Jul 30, 2026
The configuration embeds GitHub Pages in github_repository and
iterates over resource objects. This causes deprecated attribute
warnings and persistent workflow source diffs during the provider
upgrade.

This commit will:

- Manage workflow-based Pages with github_repository_pages.
- Import the three existing Pages sites without recreating them.
- Derive resource instances from input maps while keeping dependencies.
- Remove the obsolete workflow source-path setting.

- #12
- https://github.com/integrations/terraform-provider-github/releases/tag/v6.13.0
- integrations/terraform-provider-github#3216
br3ndonland added a commit to br3ndonland/infrastructure-live that referenced this pull request Jul 30, 2026
## Description

GitHub provider v6.13.0 introduces a state schema migration for default
branches, but the current stack still manages GitHub Pages through a
deprecated repository block. Keeping the provider upgrade and its
configuration migration together allows the first tracked apply to
persist the new provider state safely.

## Changes

This PR will:

- Upgrade the GitHub provider from v6.12.1 to v6.13.0.
- Manage workflow-based sites with github_repository_pages.
- Import the three existing Pages sites without recreating them.
- Derive resource instances from input maps while preserving
  dependencies.
- Remove the obsolete workflow source-path setting.

## Related

- https://github.com/integrations/terraform-provider-github/releases/tag/v6.13.0
- integrations/terraform-provider-github#3216

Co-authored-by: Brendon Smith <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug Something isn't working as documented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: github_branch_default attempts to rename to the same name on import

4 participants