Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a005b7f
Refactor to use Context-aware functions
deiga Feb 21, 2026
53936b0
Sort CRUD functions
deiga Feb 21, 2026
7da0969
Updates naming and error handling
deiga Feb 21, 2026
0d05789
Adds test cases for Update and Import functionality
deiga Feb 21, 2026
f496ba5
Refactor to use `tflog`
deiga Feb 21, 2026
a91b68e
Remove `Read` calls from `Update` and `Create`
deiga Feb 21, 2026
fe2b9b7
Update tests to use `ConfigStateChecks`
deiga Feb 21, 2026
6d275b2
Adds `repository_id` field
deiga Feb 21, 2026
54d8f7c
Adds custom `Import` function
deiga Feb 21, 2026
ded370a
Updates docs
deiga Feb 21, 2026
b859240
`gofmt`
deiga May 11, 2026
70677ab
Make `forcetypeassert` linter happy
deiga Jun 3, 2026
f65a2aa
Rename branch only if it's different from current default branch
deiga Jun 3, 2026
0271a3c
Fix documentation error
deiga Jun 4, 2026
072be3b
Add acc tests to verify Destroy behaviour
deiga Jun 4, 2026
55f8b93
Address review comments
deiga Jun 5, 2026
637360d
Use `errors.AsType` pattern
deiga Jun 5, 2026
cd1a46a
Address review comments
deiga Jun 5, 2026
bd9c20d
Add state migration and tests
deiga Jun 5, 2026
7dad19f
Update docs template to be mostly generated
deiga Jun 5, 2026
30c96f0
Ensure that ID gets updated if reponame changes
deiga Jun 6, 2026
d022c0c
Remove typeasserts from schema fields
deiga Jun 6, 2026
9ff4124
Address review comments
deiga Jun 11, 2026
d3d70ad
Address rename
deiga Jun 21, 2026
b910685
Adopt `migrateRepositoryWithID` pattern
deiga Jun 21, 2026
d873769
Address review comments
deiga Jun 21, 2026
4aa0e2c
Add wait for branch rename
deiga Jun 22, 2026
d90cd47
Address review comments
deiga Jun 22, 2026
bdcdf8e
Simplify migration logic
deiga Jun 22, 2026
47d397d
Address copilot comments
deiga Jun 22, 2026
7654612
Make waiting optional
deiga Jun 22, 2026
91c4e0e
Add unit test to verify that waiting is skipped if not configured
deiga Jun 22, 2026
bfaeb59
Update docs
deiga Jun 22, 2026
826998a
Fix linter
deiga Jun 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func resourceExampleRead(ctx context.Context, d *schema.ResourceData, m any) dia
// Single API call to get all needed data
resource, _, err := client.Resources.Get(ctx, owner, name)
if err != nil {
if ghErr, ok := errors.AsType[github.ErrorResponse](err); ok {
if ghErr, ok := errors.AsType[*github.ErrorResponse](err); ok {
if ghErr.Response.StatusCode == http.StatusNotFound {
tflog.Info(ctx, "Removing resource from state because it no longer exists", map[string]any{"name": name})
d.SetId("")
Expand Down Expand Up @@ -342,7 +342,7 @@ Handle 404s gracefully by removing from state:
```go
resource, _, err := client.Resources.Get(ctx, owner, name)
if err != nil {
if ghErr, ok := errors.AsType[github.ErrorResponse](err); ok {
if ghErr, ok := errors.AsType[*github.ErrorResponse](err); ok {
if ghErr.Response.StatusCode == http.StatusNotFound {
tflog.Info(ctx, "Removing resource from state because it no longer exists", map[string]any{"name": name})
d.SetId("")
Expand Down
50 changes: 35 additions & 15 deletions docs/resources/branch_default.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
---
page_title: "github_branch_default (Resource) - GitHub"
description: |-
Provides a GitHub branch default for a given repository.
Configures the default branch for a GitHub repository.
---

# github_branch_default (Resource)

Provides a GitHub branch default resource.
Configures the default branch for a GitHub repository.

This resource allows you to set the default branch for a given repository.

Note that use of this resource is incompatible with the `default_branch` option of the `github_repository` resource. Using both will result in plans always showing a diff.
~> This resource is incompatible with the `default_branch` option of the [`github_repository`](repository) resource. Using both will result in plans always showing a diff.

## Example Usage

Basic usage:

```terraform
# Basic usage

resource "github_repository" "example" {
name = "example"
description = "My awesome codebase"
Expand All @@ -34,9 +32,9 @@ resource "github_branch_default" "default" {
}
```

Renaming to a branch that doesn't exist:

```terraform
# Renaming to a branch that doesn't exist

resource "github_repository" "example" {
name = "example"
description = "My awesome codebase"
Expand All @@ -50,17 +48,39 @@ resource "github_branch_default" "default" {
}
```

## Argument Reference
<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `branch` (String) The name of the branch to set as the default (e.g. 'main').
- `repository` (String) The name of the GitHub repository.

### Optional

The following arguments are supported:
- `etag` (String) The ETag header for the repository API response.
- `rename` (Boolean) If `true` rename the existing branch when the `branch` input is changed. Defaults to 'false'.
- `wait_for_rename` (Boolean) If `true`, poll until GitHub propagates the renamed default branch before proceeding. Only has effect when `rename` is also `true`. Defaults to 'false'.

- `repository` - (Required) The GitHub repository
- `branch` - (Required) The branch (e.g. `main`)
- `rename` - (Optional) Indicate if it should rename the branch rather than use an existing branch. Defaults to `false`.
### Read-Only

- `id` (String) The ID of this resource.
- `repository_id` (Number) The ID of the GitHub repository.

## Import

GitHub Branch Defaults can be imported using an ID made up of `repository`, e.g.
Import is supported using the following syntax:

In Terraform v1.5.0 and later, the [`import` block](https://developer.hashicorp.com/terraform/language/import) can be used with the `id` attribute, for example:

```terraform
import {
to = github_branch_default.default
id = "example"
}
```

The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:

```shell
terraform import github_branch_default.branch_default my-repo
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {
to = github_branch_default.default
id = "example"
}
1 change: 1 addition & 0 deletions examples/resources/github_branch_default/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import github_branch_default.branch_default my-repo
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Basic usage

resource "github_repository" "example" {
name = "example"
description = "My awesome codebase"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Renaming to a branch that doesn't exist

resource "github_repository" "example" {
name = "example"
description = "My awesome codebase"
Expand Down
Loading
Loading