Skip to content

Unsupported (?) API call to github API causes github pages to not work properly #1198

Closed

Description

@timon-michel-svga

Impacted resource: github_repository

If we want to change the publishing source for a github repository, the provider uses the following arguments:

2022-06-21T11:41:13.197+0200 [DEBUG] provider.terraform-provider-github_v4.26.1: -----------------------------------------------------
2022-06-21T11:41:13.197+0200 [DEBUG] provider.terraform-provider-github_v4.26.1: 2022/06/21 11:41:13 [DEBUG] Github API Request Details:
2022-06-21T11:41:13.197+0200 [DEBUG] provider.terraform-provider-github_v4.26.1: ---[ REQUEST ]---------------------------------------
2022-06-21T11:41:13.197+0200 [DEBUG] provider.terraform-provider-github_v4.26.1: PUT /repos/Scopevisio/TestRepo/pages HTTP/1.1
2022-06-21T11:41:13.197+0200 [DEBUG] provider.terraform-provider-github_v4.26.1: Host: api.github.com
2022-06-21T11:41:13.197+0200 [DEBUG] provider.terraform-provider-github_v4.26.1: User-Agent: go-github
2022-06-21T11:41:13.197+0200 [DEBUG] provider.terraform-provider-github_v4.26.1: Content-Length: 37
2022-06-21T11:41:13.197+0200 [DEBUG] provider.terraform-provider-github_v4.26.1: Accept: application/vnd.github.v3+json
2022-06-21T11:41:13.198+0200 [DEBUG] provider.terraform-provider-github_v4.26.1: Content-Type: application/json
2022-06-21T11:41:13.198+0200 [DEBUG] provider.terraform-provider-github_v4.26.1: Accept-Encoding: gzip
2022-06-21T11:41:13.198+0200 [DEBUG] provider.terraform-provider-github_v4.26.1: 
2022-06-21T11:41:13.198+0200 [DEBUG] provider.terraform-provider-github_v4.26.1: {
2022-06-21T11:41:13.198+0200 [DEBUG] provider.terraform-provider-github_v4.26.1:  "cname": null,
2022-06-21T11:41:13.198+0200 [DEBUG] provider.terraform-provider-github_v4.26.1:  "source": "main /docs"
2022-06-21T11:41:13.198+0200 [DEBUG] provider.terraform-provider-github_v4.26.1: }
2022-06-21T11:41:13.198+0200 [DEBUG] provider.terraform-provider-github_v4.26.1: 

The documentation of the Github API, however specify a different method to set the branch and path:

{
"cname": null,
"source": {"branch":"main","path":"/docs"}
}

(https://docs.github.com/en/rest/pages#update-information-about-a-github-pages-site)

If we make the request using the method used by the terraform provider, we get an error:

2022-06-21T11:41:14.382+0200 [ERROR] vertex "github_repository.test" error: PUT https://api.github.com/repos/Scopevisio/TestRepo/pages: 422 Invalid request.

Invalid property /source: `main /docs` is not a possible value. Must be one of the following: gh-pages, master, master /docs. []

We can replicate this issue in CURL, but if we use the way provided in the GitHub API documentation it works flawlessly.

I am no expert in Go, but the corresponding source seems to be here:

source += fmt.Sprintf(" %s", v)

Activity

  1. gesellix commented on Jul 6, 2022

    @gesellix
    Contributor

    The internally used google/go-github module might need a change, see google/go-github#2406

  2. gesellix commented on Aug 19, 2022

    @gesellix
    Contributor

    go-github has been released as v46.0.0, including the required change to allow main as pages source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions