Skip to content

resource_github_team_repository cannot handle custom role after creation #1183

@joshua-hancox

Description

@joshua-hancox

Affected Resource(s)

  • resource_github_team_repository

Expected Behavior

After creating a resource_github_team_repository with a custom role set in the permission field, making no changes, and re-running the plan, I expect no changes to be planned by terraform.

Actual Behavior

After creating the resource and re-running the plan, terraform plan tries to change from the built in role that the custom role was based on, to the role that was originally set.

Steps to Reproduce

e.g. config

resource "github_team_repository" "custom_role" {
  team_id    = github_team.this.id
  repository = github_repository.this.name
  permission = "my-custom-role"
}

(assume that my-custom-role was created in github, and based on the built in maintainer role, with some added permissions)

  1. Run terraform apply
  2. Once the terraform apply has been applied, run terraform plan

The plan output will show:

  # github_team_repository.custom_role will be updated in-place
  ~ resource "github_team_repository" "custom_role" {
        id         = "5817097:my-repo-name"
      ~ permission = "maintainer" -> "my-custom-role"
    }

Suggested fix

I think this issue comes from this function being called here to guess what the permission is that is applied.

It assumes that there are only built in roles, which is no longer the case.

I have extended the Repository struct in go-github with this PR to include the role_name field in the repository that is returned(automatically includes the .GetRoleName() function), and also raised a PR in this repo to bump to the latest version of that module.

Once that is complete I think we should be able to remove the function getRepoPermission altogether and amend resource_github_team_repository to do it's permission look up from:

	permName, permErr := getRepoPermission(repo.GetPermissions())
	if permErr != nil {
		return permErr
	}

	d.Set("permission", permName)

to

	d.Set("permission", repo.GetRoleName())

If that makes sense, and we can merge the PR to bump the module then let me know and I can raise a new PR for the fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugSomething isn't working as documented

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions