Skip to content

[BUG] Updating repository visibility broken #1364

Closed

Description

@jtgrohn

Terraform Version
v1.1.9 (though this has nothing to do with the terraform version)

Provider Version
v5.7.0 (though I believe it is also broken in latest)

Affected Resource(s)
github_repository

Terraform Configuration Files

resource "github_repository" "internal-repo-test" {
    name       = "internal-repo-test"
    visibility = "internal"
}

Output
from terraform apply

Terraform will perform the following actions:

  # github_repository.internal-repo-test will be created
  + resource "github_repository" "internal-repo-test" {
      + allow_auto_merge            = false
      + allow_merge_commit          = true
      + allow_rebase_merge          = true
      + allow_squash_merge          = true
      + archived                    = false
      + default_branch              = (known after apply)
      + delete_branch_on_merge      = false
      + etag                        = (known after apply)
      + full_name                   = (known after apply)
      + git_clone_url               = (known after apply)
      + html_url                    = (known after apply)
      + http_clone_url              = (known after apply)
      + id                          = (known after apply)
      + merge_commit_message        = "PR_TITLE"
      + merge_commit_title          = "MERGE_MESSAGE"
      + name                        = "internal-repo-test"
      + node_id                     = (known after apply)
      + private                     = (known after apply)
      + repo_id                     = (known after apply)
      + squash_merge_commit_message = "COMMIT_MESSAGES"
      + squash_merge_commit_title   = "COMMIT_OR_PR_TITLE"
      + ssh_clone_url               = (known after apply)
      + svn_url                     = (known after apply)
      + visibility                  = "internal"
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

github_repository.internal-repo-test: Creating...
╷
│ Error: PATCH https://api.github.com/repos/myorg/internal-repo-test: 422 Visibility can't be changed by this user. and Visibility is already internal. []
│ 
│   with github_repository.internal-repo-test,
│   on main.tf line 17, in resource "github_repository" "internal-repo-test":
│   17: resource "github_repository" "internal-repo-test" {
│ 
╵
Releasing state lock. This may take a few moments...

Expected Behaviour
Repository creation should have completed successfully.

Actual Behaviour
Repository creation failed. The following steps occurred:

Steps to Reproduce
Using the configuration above, run:

terraform apply

Current Workaround

As the resource is currently tainted (because terraform taints resources when creation fails), rerunning terraform will delete/recreate the resource (because that's how terraform treats tainted resources) and run into the same issue.
Since visibility is one of the last edited properties for the repository (meaning the repository creation has actually fully completed) it is currently appears to be safe to untaint the resource and reapply

terraform untaint github_repository.internal-repo-test
terraform apply

Activity

  1. mbarany commented on Nov 16, 2022

    @mbarany
    Contributor

    I am seeing this issue as well

  2. n0rad commented on Nov 16, 2022

    @n0rad

    Same here on 5.8.0. It's broken and our teams cannot create repositories without manual actions.

    Is it github api that is broken? or a breaking change that need to be supported by the provider?

  3. chapurlatn commented on Nov 17, 2022

    @chapurlatn
    Contributor

    Hello,
    There is a test that ignore this error in the TF code. It's based on the error message returns by github API.
    But this message changed.
    Today, when trying to update visiblity from private to private, and when someone can't update the repo, github returns:
    422 Visibility can't be changed by this user. and Visibility is already private
    But in the code:
    https://github.com/integrations/terraform-provider-github/blob/main/github/resource_github_repository.go#L690
    if !strings.Contains(err.Error(), fmt.Sprintf("422 Visibility is already %s", n.(string))) {

    We should provide a fix (for example, contains "422" and contains "Visibility is already%s") and everybody will have to use the latest version.

  4. chapurlatn commented on Nov 17, 2022

    @chapurlatn
    Contributor

    Note that we found a bypass for visibility "private" only: use the deprecated property "private: true" instead of using the "visibility" property. Before updating a lot of terraform plan to use a deprecated property, we'd like to wait for a fix... 🙏

  5. Luis-3M commented on Nov 18, 2022

    @Luis-3M

    we're experiencing the same issue

  6. chapurlatn commented on Nov 21, 2022

    @chapurlatn
    Contributor

    We need a maintainer to review the PR that is blocked #1368

  7. chapurlatn commented on Nov 21, 2022

    @chapurlatn
    Contributor

    Eventually @kfcampbell , could you please take a look at this PR to make sure it's properly handled?

  8. mungojam commented on Nov 21, 2022

    @mungojam

    This impacts previously working workflows and only started happening last week. Presumably due to a GitHub API change or something

  9. jhaumont commented on Nov 21, 2022

    @jhaumont

    Hello
    I'm very interested by the fix, any ideas from when we can have this one?

  10. jtgrohn commented on Nov 21, 2022

    @jtgrohn
    ContributorAuthor

    If you're blocked while waiting for the fix, you can use the work around in the issue description OR you can build @chapurlatn's fix in #1368 and use it in your workflows by dropping the built binary into a bin directory, adding the following to your .terraformrc file, and setting the TF_CLI_CONFIG_FILE environment variable to .terraformrc

    provider_installation {
      dev_overrides {
        "integrations/github" = "bin/"
      }
      direct {}
    }
    
  11. chapurlatn commented on Nov 22, 2022

    @chapurlatn
    Contributor

    I'm wondering if we should add a way to change the bypass condition by configuration in addition to the fix. For example by using an environment variable. It would be pretty ugly but will offer people a way to bypass without waiting for a fix or deploying local build. wdyt @jtgrohn?
    Also, I will warn GitHub support about this API "error", cause this is the root cause of the custom behaviour and it's pretty weird: "you've got an error cause you try to didn't change something we can't change"...

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