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

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

Merged
merged 8 commits into from
Jun 26, 2023

Conversation

cailen
Copy link
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
…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
Member

@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
Member

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
doonga referenced this pull request in doonga/greyrock-ops Jun 29, 2023
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github](https://registry.terraform.io/providers/integrations/github)
([source](https://togithub.com/integrations/terraform-provider-github))
| required_provider | minor | `5.28.1` -> `5.29.0` |

---

### Release Notes

<details>
<summary>integrations/terraform-provider-github (github)</summary>

###
[`v5.29.0`](https://togithub.com/integrations/terraform-provider-github/releases/tag/v5.29.0)

[Compare
Source](https://togithub.com/integrations/terraform-provider-github/compare/v5.28.1...v5.29.0)

#### What's Changed

- fix: support team slug in github_team_membership by
[@&#8203;kristian-lesko](https://togithub.com/kristian-lesko) in
[https://github.com/integrations/terraform-provider-github/pull/1751](https://togithub.com/integrations/terraform-provider-github/pull/1751)
- Fixes accidental deletion of Repository resource from state by
[@&#8203;t0yv0](https://togithub.com/t0yv0) in
[https://github.com/integrations/terraform-provider-github/pull/1750](https://togithub.com/integrations/terraform-provider-github/pull/1750)
- feat: Add GitHub Organization Custom Role Resource and Data Source by
[@&#8203;cailen](https://togithub.com/cailen) in
[https://github.com/integrations/terraform-provider-github/pull/1700](https://togithub.com/integrations/terraform-provider-github/pull/1700)
- Fix typo in deployment branch policy import by
[@&#8203;bpaquet](https://togithub.com/bpaquet) in
[https://github.com/integrations/terraform-provider-github/pull/1758](https://togithub.com/integrations/terraform-provider-github/pull/1758)
- Fix `resourceGithubDependabotOrganizationSecretCreateOrUpdate` by
[@&#8203;frankywahl](https://togithub.com/frankywahl) in
[https://github.com/integrations/terraform-provider-github/pull/1759](https://togithub.com/integrations/terraform-provider-github/pull/1759)
- \[Bug]: Renaming github_repository doesn't taint full_name attribute
by [@&#8203;KenSpur](https://togithub.com/KenSpur) in
[https://github.com/integrations/terraform-provider-github/pull/1756](https://togithub.com/integrations/terraform-provider-github/pull/1756)
- feat: Ability to Manage Codespaces Secrets by
[@&#8203;KenSpur](https://togithub.com/KenSpur) in
[https://github.com/integrations/terraform-provider-github/pull/1729](https://togithub.com/integrations/terraform-provider-github/pull/1729)

#### New Contributors

- [@&#8203;kristian-lesko](https://togithub.com/kristian-lesko) made
their first contribution in
[https://github.com/integrations/terraform-provider-github/pull/1751](https://togithub.com/integrations/terraform-provider-github/pull/1751)
- [@&#8203;t0yv0](https://togithub.com/t0yv0) made their first
contribution in
[https://github.com/integrations/terraform-provider-github/pull/1750](https://togithub.com/integrations/terraform-provider-github/pull/1750)
- [@&#8203;cailen](https://togithub.com/cailen) made their first
contribution in
[https://github.com/integrations/terraform-provider-github/pull/1700](https://togithub.com/integrations/terraform-provider-github/pull/1700)
- [@&#8203;frankywahl](https://togithub.com/frankywahl) made their first
contribution in
[https://github.com/integrations/terraform-provider-github/pull/1759](https://togithub.com/integrations/terraform-provider-github/pull/1759)
- [@&#8203;KenSpur](https://togithub.com/KenSpur) made their first
contribution in
[https://github.com/integrations/terraform-provider-github/pull/1756](https://togithub.com/integrations/terraform-provider-github/pull/1756)

**Full Changelog**:
integrations/terraform-provider-github@v5.28.1...v5.29.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xNDQuMCIsInVwZGF0ZWRJblZlciI6IjM1LjE0NC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: greyrock-bot <1583719+greyrock-bot[bot]@users.noreply.github.com>
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
MinItems: 1, // At least one permission should be passed.
Copy link
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
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