Skip to content

[BUG]: Fix CanAdminsBypass to Environment #1804

@nirav-chotai

Description

@nirav-chotai

Describe the need

While using github_repository_environment, it is automatically taking can_admins_bypass and making invalid PUT request.

"message": "Invalid request.\n\n\"can_admins_bypass\" is not a permitted key.",

Example code:

resource "github_repository_environment" "dev" {
  for_each = toset(
    [
      "dev-demo"
    ]
  )
  repository  = each.key
  environment = "dev-demo"
  reviewers {
    teams = ["123"]
  }
  deployment_branch_policy {
    protected_branches     = true
    custom_branch_policies = false
  }
}

There is no field for can_admins_bypass here, plan is successful, but when apply runs, and making PUT request, below is DEBUG error

2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: ---[ REQUEST ]---------------------------------------
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: PUT /api/v3/repos/my/dev-demo/environments/dev-demo HTTP/1.1
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: Host: abc.com
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: User-Agent: go-github/v53.2.0
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: Content-Length: 167
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: Accept: application/vnd.github.v3+json,application/vnd.github.stone-crop-preview+json
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: Content-Type: application/json
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: X-Github-Api-Version: 2022-11-28
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: Accept-Encoding: gzip
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0:
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: {
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0:  "wait_timer": 0,
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0:  "reviewers": [
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0:   {
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0:    "type": "Team",
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0:    "id": 123
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0:   }
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0:  ],
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0:  "can_admins_bypass": true,
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0:  "deployment_branch_policy": {
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0:   "protected_branches": true,
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0:   "custom_branch_policies": false
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0:  }
2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: }

Because of can_admins_bypass in above request, getting below error:

2023-07-20T13:00:28.754-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: -----------------------------------------------------
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: 2023/07/20 13:00:29 [DEBUG] GitHub API Response Details:
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: ---[ RESPONSE ]--------------------------------------
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: HTTP/2.0 422 Unprocessable Entity
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: Content-Length: 200
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: Access-Control-Allow-Origin: *
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: Content-Security-Policy: default-src 'none'
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: Content-Type: application/json; charset=utf-8
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: Date: Thu, 20 Jul 2023 20:00:29 GMT
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: Server: GitHub.com
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: Strict-Transport-Security: max-age=31536000; includeSubdomains
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: X-Accepted-Oauth-Scopes:
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: X-Content-Type-Options: nosniff
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: X-Frame-Options: deny
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: X-Github-Enterprise-Version: 3.8.4
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: X-Github-Media-Type: github.v3; format=json, github.stone-crop-preview; format=json
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: X-Github-Request-Id: 7c278f62-eb33-42d7-8291-fde2d9d3cf20
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: X-Oauth-Scopes: admin:repo_hook, delete_repo, project, repo, user
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: X-Ratelimit-Limit: 10000
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: X-Ratelimit-Remaining: 9515
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: X-Ratelimit-Reset: 1689884684
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: X-Ratelimit-Resource: core
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: X-Ratelimit-Used: 485
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: X-Runtime-Rack: 0.102010
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: X-Xss-Protection: 0
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0:
2023-07-20T13:00:29.088-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: {
2023-07-20T13:00:29.089-0700 [DEBUG] provider.terraform-provider-github_v5.31.0:  "message": "Invalid request.\n\n\"can_admins_bypass\" is not a permitted key.",
2023-07-20T13:00:29.089-0700 [DEBUG] provider.terraform-provider-github_v5.31.0:  "documentation_url": "https://docs.github.com/enterprise-server@3.8/rest/reference/repos#create-or-update-an-environment"
2023-07-20T13:00:29.089-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: }
2023-07-20T13:00:29.089-0700 [DEBUG] provider.terraform-provider-github_v5.31.0: -----------------------------------------------------

SDK Version

terraform-provider-github_v5.31.0

API Version

v3.8.4

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: Up for grabsIssues that are ready to be worked on by anyoneType: BugSomething isn't working as documentedhacktoberfestIssues for participation in Hacktoberfest

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions