Skip to content
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
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 @@ -337,7 +337,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
38 changes: 23 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.
~> **Note:** This resource is incompatible with the `default_branch` option of the `github_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,27 @@ 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

- `etag` (String) The ETag header for the repository API response.
- `rename` (Boolean) Indicate if the current default branch should be renamed rather than switching to an existing branch. Defaults to 'false'.

The following arguments are supported:
### Read-Only

- `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`.
- `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.
GitHub Branch Defaults can be imported using the repository name with the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), for example:

```shell
terraform import github_branch_default.branch_default my-repo
Expand Down
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