Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Diff Suppression Option To repository_collaborator #683

Merged
merged 3 commits into from
Feb 5, 2021
Merged
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 examples/repository_collaborator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ This example will also create a repository in the specified `owner` organization
Alternatively, you may use variables passed via command line:

```console
export GITHUB_ORG=
export GITHUB_ORGANIZATION=
export GITHUB_TOKEN=
export COLLABORATOR_USERNAME=
export COLLABORATOR_PERMISSION=
```

```console
terraform apply \
-var "organization=${GITHUB_ORG}" \
-var "organization=${GITHUB_ORGANIZATION}" \
-var "github_token=${GITHUB_TOKEN}" \
-var "username=${COLLABORATOR_USERNAME}" \
-var "permission=${COLLABORATOR_PERMISSION}"
Expand Down
1 change: 0 additions & 1 deletion examples/repository_collaborator/providers.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
provider "github" {
version = "2.8.0"
organization = var.organization
token = var.github_token
}
18 changes: 18 additions & 0 deletions github/resource_github_repository_collaborator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func resourceGithubRepositoryCollaborator() *schema.Resource {
return &schema.Resource{
Create: resourceGithubRepositoryCollaboratorCreate,
Read: resourceGithubRepositoryCollaboratorRead,
Update: resourceGithubRepositoryCollaboratorUpdate,
Delete: resourceGithubRepositoryCollaboratorDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
Expand All @@ -39,6 +40,19 @@ func resourceGithubRepositoryCollaborator() *schema.Resource {
ForceNew: true,
Default: "push",
ValidateFunc: validateValueFunc([]string{"pull", "triage", "push", "maintain", "admin"}),
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if d.Get("permission_diff_suppression").(bool) {
if new == "triage" || new == "maintain" {
return true
}
}
return false
},
},
"permission_diff_suppression": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"invitation_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -158,6 +172,10 @@ func resourceGithubRepositoryCollaboratorRead(d *schema.ResourceData, meta inter
return nil
}

func resourceGithubRepositoryCollaboratorUpdate(d *schema.ResourceData, meta interface{}) error {
Copy link
Contributor Author

@jcudit jcudit Jan 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding an update function was required if we are to add the permission_diff_suppression option without a ForceNew. This enables a smoother upgrade option as users can turn on this workaround without triggering a recreate. Downside is we'll have to keep this no-op update in mind if we ever want to update actual state.

return resourceGithubRepositoryCollaboratorRead(d, meta)
}

func resourceGithubRepositoryCollaboratorDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Owner).v3client

Expand Down
Loading