Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 docs/resources/team_repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ resource "github_repository" "some_repo" {
resource "github_team_repository" "some_team_repo" {
team_id = github_team.some_team.id
repository = github_repository.some_repo.name
permission = "pull"
permission = "read"
}
```

Expand All @@ -44,7 +44,7 @@ The following arguments are supported:

- `team_id` - (Required) The GitHub team id or the GitHub team slug
- `repository` - (Required) The repository to add to the team.
- `permission` - (Optional) The permissions of team members regarding the repository. Must be one of `pull`, `triage`, `push`, `maintain`, `admin` or the name of an existing [custom repository role](https://docs.github.com/en/enterprise-cloud@latest/organizations/managing-peoples-access-to-your-organization-with-roles/managing-custom-repository-roles-for-an-organization) within the organisation. Defaults to `pull`.
- `permission` - (Optional) The permissions of team members regarding the repository. Must be one of `read` (equivalent to `pull`), `triage`, `write` (equivalent to `push`), `maintain`, `admin` or the name of an existing [custom repository role](https://docs.github.com/en/enterprise-cloud@latest/organizations/managing-peoples-access-to-your-organization-with-roles/managing-custom-repository-roles-for-an-organization) within the organisation. Defaults to `read`.

## Import

Expand Down
2 changes: 1 addition & 1 deletion examples/resources/team_repository/example_1.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ resource "github_repository" "some_repo" {
resource "github_team_repository" "some_team_repo" {
team_id = github_team.some_team.id
repository = github_repository.some_repo.name
permission = "pull"
permission = "read"
}
11 changes: 7 additions & 4 deletions github/resource_github_team_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ func resourceGithubTeamRepository() *schema.Resource {
"permission": {
Type: schema.TypeString,
Optional: true,
Default: "pull",
Description: "The permissions of team members regarding the repository. Must be one of 'pull', 'triage', 'push', 'maintain', 'admin' or the name of an existing custom repository role within the organisation.",
Default: "read",
DiffSuppressFunc: func(_, oldValue, newValue string, _ *schema.ResourceData) bool {
return getPermission(oldValue) == getPermission(newValue)
},
Description: "The permissions of team members regarding the repository. Must be one of 'read' (equivalent to 'pull'), 'triage', 'write' (equivalent to 'push'), 'maintain', 'admin' or the name of an existing custom repository role within the organisation. Defaults to 'read'.",
},
"etag": {
Type: schema.TypeString,
Expand Down Expand Up @@ -94,7 +97,7 @@ func resourceGithubTeamRepositoryCreate(ctx context.Context, d *schema.ResourceD
orgName,
repoName,
&github.TeamAddTeamRepoOptions{
Permission: permission,
Permission: getPermission(permission),
},
)
if err != nil {
Expand Down Expand Up @@ -197,7 +200,7 @@ func resourceGithubTeamRepositoryUpdate(ctx context.Context, d *schema.ResourceD
orgName,
repoName,
&github.TeamAddTeamRepoOptions{
Permission: permission,
Permission: getPermission(permission),
},
)
if err != nil {
Expand Down
59 changes: 54 additions & 5 deletions github/resource_github_team_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,43 @@ func Test_resourceGithubTeamRepositoryDelete_nilResponseDoesNotPanic(t *testing.
}
}

func Test_resourceGithubTeamRepositoryPermissionAliases(t *testing.T) {
t.Parallel()

for _, testCase := range []struct {
permission string
want string
}{
{permission: "read", want: "pull"},
{permission: "write", want: "push"},
{permission: "pull", want: "pull"},
{permission: "push", want: "push"},
{permission: "triage", want: "triage"},
} {
t.Run(testCase.permission, func(t *testing.T) {
t.Parallel()

if got := getPermission(testCase.permission); got != testCase.want {
t.Errorf("getPermission(%q) = %q, want %q", testCase.permission, got, testCase.want)
}
})
}

permissionSchema := resourceGithubTeamRepository().Schema["permission"]
if permissionSchema.Default != "read" {
t.Errorf("permission default = %q, want %q", permissionSchema.Default, "read")
}
if !permissionSchema.DiffSuppressFunc("permission", "pull", "read", nil) {
t.Error("expected read and pull permissions to suppress a diff")
}
if !permissionSchema.DiffSuppressFunc("permission", "push", "write", nil) {
t.Error("expected write and push permissions to suppress a diff")
}
if permissionSchema.DiffSuppressFunc("permission", "pull", "push", nil) {
t.Error("expected read and write permissions to remain distinct")
}
}

func TestAccGithubTeamRepository(t *testing.T) {
t.Parallel()

Expand All @@ -67,7 +104,7 @@ func TestAccGithubTeamRepository(t *testing.T) {
resource "github_team_repository" "test" {
team_id = "${github_team.test.id}"
repository = "${github_repository.test.name}"
permission = "pull"
permission = "read"
}
`, teamName, repoName)

Expand Down Expand Up @@ -114,25 +151,37 @@ func TestAccGithubTeamRepository(t *testing.T) {
},
{
Config: strings.Replace(config,
`permission = "pull"`,
`permission = "read"`,
`permission = "pull"`, 1),
Check: checks["pull"],
},
{
Config: strings.Replace(config,
`permission = "read"`,
`permission = "triage"`, 1),
Check: checks["triage"],
},
{
Config: strings.Replace(config,
`permission = "pull"`,
`permission = "read"`,
`permission = "write"`, 1),
Check: checks["push"],
},
{
Config: strings.Replace(config,
`permission = "read"`,
`permission = "push"`, 1),
Check: checks["push"],
},
{
Config: strings.Replace(config,
`permission = "pull"`,
`permission = "read"`,
`permission = "maintain"`, 1),
Check: checks["maintain"],
},
{
Config: strings.Replace(config,
`permission = "pull"`,
`permission = "read"`,
`permission = "admin"`, 1),
Check: checks["admin"],
},
Expand Down
2 changes: 1 addition & 1 deletion templates/resources/team_repository.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The following arguments are supported:

- `team_id` - (Required) The GitHub team id or the GitHub team slug
- `repository` - (Required) The repository to add to the team.
- `permission` - (Optional) The permissions of team members regarding the repository. Must be one of `pull`, `triage`, `push`, `maintain`, `admin` or the name of an existing [custom repository role](https://docs.github.com/en/enterprise-cloud@latest/organizations/managing-peoples-access-to-your-organization-with-roles/managing-custom-repository-roles-for-an-organization) within the organisation. Defaults to `pull`.
- `permission` - (Optional) The permissions of team members regarding the repository. Must be one of `read` (equivalent to `pull`), `triage`, `write` (equivalent to `push`), `maintain`, `admin` or the name of an existing [custom repository role](https://docs.github.com/en/enterprise-cloud@latest/organizations/managing-peoples-access-to-your-organization-with-roles/managing-custom-repository-roles-for-an-organization) within the organisation. Defaults to `read`.

## Import

Expand Down
Loading