Skip to content

feat: Add GitHub Organization Custom Role Resource and Data Source#1700

Merged
kfcampbell merged 8 commits intointegrations:mainfrom
cailen:add-custom-roles
Jun 26, 2023
Merged

feat: Add GitHub Organization Custom Role Resource and Data Source#1700
kfcampbell merged 8 commits intointegrations:mainfrom
cailen:add-custom-roles

Conversation

@cailen
Copy link
Copy Markdown
Contributor

@cailen cailen commented May 25, 2023

Resolves #1069


Behavior

Before the change?

  • There was no ability to create custom roles in GitHub Organizations.

After the change?

  • You can create and manage custom roles
  • You can refer to them in a data source

Other information

N/A


Additional info

Pull request checklist

  • Tests for the changes have been added (for bug fixes / features)

    • Data Source:
    TF_ACC=1 go test -v ./... -run TestAccGithubOrganizationCustomRoleDataSource
      --- PASS: TestAccGithubOrganizationCustomRoleDataSource (7.03s)
      --- PASS: TestAccGithubOrganizationCustomRoleDataSource/queries_a_custom_repo_role (7.03s)
          --- SKIP: TestAccGithubOrganizationCustomRoleDataSource/queries_a_custom_repo_role/with_an_anonymous_account (0.00s)
          --- SKIP: TestAccGithubOrganizationCustomRoleDataSource/queries_a_custom_repo_role/with_an_individual_account (0.00s)
          --- PASS: TestAccGithubOrganizationCustomRoleDataSource/queries_a_custom_repo_role/with_an_organization_account (7.03s)
          PASS
          ok      github.com/integrations/terraform-provider-github/v5/github     7.958s
    
    • Resource:
    TF_ACC=1 go test -v ./... -run TestAccGithubOrganizationCustomRole
       --- PASS: TestAccGithubOrganizationCustomRole (16.99s)
      --- PASS: TestAccGithubOrganizationCustomRole/creates_custom_repo_role_without_error (4.27s)
          --- SKIP: TestAccGithubOrganizationCustomRole/creates_custom_repo_role_without_error/with_an_anonymous_account (0.00s)
          --- SKIP: TestAccGithubOrganizationCustomRole/creates_custom_repo_role_without_error/with_an_individual_account (0.00s)
          --- PASS: TestAccGithubOrganizationCustomRole/creates_custom_repo_role_without_error/with_an_organization_account (4.27s)
      --- PASS: TestAccGithubOrganizationCustomRole/updates_custom_repo_role_without_error (8.30s)
          --- SKIP: TestAccGithubOrganizationCustomRole/updates_custom_repo_role_without_error/with_an_anonymous_account (0.00s)
          --- SKIP: TestAccGithubOrganizationCustomRole/updates_custom_repo_role_without_error/with_an_individual_account (0.00s)
          --- PASS: TestAccGithubOrganizationCustomRole/updates_custom_repo_role_without_error/with_an_organization_account (8.30s)
      --- PASS: TestAccGithubOrganizationCustomRole/imports_custom_repo_role_without_error (4.42s)
          --- SKIP: TestAccGithubOrganizationCustomRole/imports_custom_repo_role_without_error/with_an_anonymous_account (0.00s)
          --- SKIP: TestAccGithubOrganizationCustomRole/imports_custom_repo_role_without_error/with_an_individual_account (0.00s)
          --- PASS: TestAccGithubOrganizationCustomRole/imports_custom_repo_role_without_error/with_an_organization_account (4.42s)
          PASS
          ok      github.com/integrations/terraform-provider-github/v5/github     24.637s
    
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

  • Added the appropriate label for the given change

Does this introduce a breaking change?

I do not believe so.

Please see our docs on breaking changes to help!

  • Yes (Please add the Type: Breaking change label)
  • No

If Yes, what's the impact:

  • N/A

Pull request type

  • Feature/model/API additions: Type: Feature
  • Updates to docs or samples: Type: Documentation

This commit adds a new Terraform resource for creating, reading, updating and deleting GitHub organization custom roles. The `resourceGithubOrganizationCustomRole` function is added to the `github/provider.go` file. The function creates a new schema with four fields: name, base_role, permissions and description. It also includes functions for create, read, update and delete operations on the resource.

A new data source is also added in this commit that allows users to query an existing custom repository role by its name. The `dataSourceGithubOrganizationCustomRole` function is added to the `github/data_source_github_organization_custom_role.go` file.

Finally, a test case is included in the `github/data_source_github_organization_custom_role_test.go` file that tests querying of an existing custom repository role using the newly created data source.
@cailen cailen changed the title feat: Add GitHub organization custom role resource feat: Add GitHub Organization Custom Role Resource and Data Source May 25, 2023
cailen added 2 commits May 25, 2023 21:56
…om Role

This commit updates the formatting of the test and resource files for Github Organization Custom Role. It also removes the ForceNew attribute from one of the required fields in the resource file and updates the tests to reflect it.
This commit fixes the arguments for creating an organization custom role.
Copy link
Copy Markdown
Contributor

@kfcampbell kfcampbell left a comment

Choose a reason for hiding this comment

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

Confirming that the added integration tests are passing for me. Thank you for contributing!

@kfcampbell
Copy link
Copy Markdown
Contributor

Sorry about the delay here; this slipped through the cracks for me somehow. I'll get this merged and released soon!

@kfcampbell kfcampbell merged commit bd56d13 into integrations:main Jun 26, 2023
@cailen cailen deleted the add-custom-roles branch June 28, 2023 01:31
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
MinItems: 1, // At least one permission should be passed.
Copy link
Copy Markdown
Contributor

@usmonster usmonster Nov 26, 2023

Choose a reason for hiding this comment

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

Sorry to comment on an old/merged PR, but is this a necessary constraint? The API permits creation of a repository role without additional permissions, and it makes perfect sense if the role's only purpose is to designate who can bypass a repository ruleset, for example:

gh api \
  --method POST \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  /orgs/$ORG/custom-repository-roles \
  -f name='rule-breaker' \
  -f description='Can bypass repository rulesets' \
  -f base_role='read' \
  -f "permissions[]" 

If you can confirm, shall I open another issue (or PR) to correct this? Thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I believe you may be right about this. I was however unable to get it to post to the API at the time, so I was thinking it did require something, but I may have just passed in the wrong blank value.

avidspartan1 pushed a commit to avidspartan1/terraform-provider-github that referenced this pull request Feb 5, 2024
…ntegrations#1700)

* feat: Add GitHub organization custom role resource

This commit adds a new Terraform resource for creating, reading, updating and deleting GitHub organization custom roles. The `resourceGithubOrganizationCustomRole` function is added to the `github/provider.go` file. The function creates a new schema with four fields: name, base_role, permissions and description. It also includes functions for create, read, update and delete operations on the resource.

A new data source is also added in this commit that allows users to query an existing custom repository role by its name. The `dataSourceGithubOrganizationCustomRole` function is added to the `github/data_source_github_organization_custom_role.go` file.

Finally, a test case is included in the `github/data_source_github_organization_custom_role_test.go` file that tests querying of an existing custom repository role using the newly created data source.

* refactor: Update test and resource files for Github Organization Custom Role

This commit updates the formatting of the test and resource files for Github Organization Custom Role. It also removes the ForceNew attribute from one of the required fields in the resource file and updates the tests to reflect it.

* docs: Fix arguments for organization custom role

This commit fixes the arguments for creating an organization custom role.

* docs: Update documentation with organization_custom_role

Updates to the documentation to reflect this change.

* docs: Fix errant parenthesis

* Fix bad merge

---------

Co-authored-by: Keegan Campbell <me@kfcampbell.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] GitHub Custom Repository Role resource

4 participants