-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: Add github_enterprise_app_installation resource #3535
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
Open
slang25
wants to merge
12
commits into
integrations:main
Choose a base branch
from
slang25:slang25/github-issue-3460-feature
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ec6408e
feat: Add github_enterprise_app_installation resource
slang25 1fe33df
fix: Set resource ID before granting remaining repositories
slang25 4708b77
chore: Use Owner maxPerPage after per-page refactor
slang25 2f3d5f1
feat: Add enterprise app installation data sources
slang25 ea41514
docs: Generate enterprise app installation docs from the default temp…
slang25 964d64b
fix: Persist installation identifiers and drop read-after-write
slang25 f2c0cab
test: Use ConfigStateChecks for app installation assertions
slang25 4a18917
refactor: Rename resources to name the organization they target
slang25 743f769
fix: Force replacement when the new repository selection is unknown
slang25 3d78f5d
refactor: Paginate with the go-github iterator methods
slang25 904c1e0
ci: Provide the enterprise app client ID to acceptance tests
slang25 6d7f0c9
Fix indentation in acceptance-tests.yaml
slang25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
docs/data-sources/enterprise_app_installable_organizations.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| --- | ||
| page_title: "github_enterprise_app_installable_organizations (Data Source) - GitHub" | ||
| subcategory: "" | ||
| description: |- | ||
| Use this data source to retrieve the enterprise-owned organizations that GitHub Apps can be installed on. This data source requires GitHub Enterprise Cloud or GitHub Enterprise Server 3.19+ and an authenticated user that is an enterprise owner. | ||
| --- | ||
|
|
||
| # github_enterprise_app_installable_organizations (Data Source) | ||
|
|
||
| Use this data source to retrieve the enterprise-owned organizations that GitHub Apps can be installed on. This data source requires GitHub Enterprise Cloud or GitHub Enterprise Server 3.19+ and an authenticated user that is an enterprise owner. | ||
|
|
||
| ## Example Usage | ||
|
|
||
| ```terraform | ||
| data "github_enterprise_app_installable_organizations" "example" { | ||
| enterprise_slug = "my-enterprise" | ||
| } | ||
| ``` | ||
|
|
||
| <!-- schema generated by tfplugindocs --> | ||
| ## Schema | ||
|
|
||
| ### Required | ||
|
|
||
| - `enterprise_slug` (String) The slug of the enterprise. | ||
|
|
||
| ### Read-Only | ||
|
|
||
| - `id` (String) The ID of this resource. | ||
| - `organizations` (List of Object) List of organizations in the enterprise that GitHub Apps can be installed on. (see [below for nested schema](#nestedatt--organizations)) | ||
|
|
||
| <a id="nestedatt--organizations"></a> | ||
| ### Nested Schema for `organizations` | ||
|
|
||
| Read-Only: | ||
|
|
||
| - `accessible_repositories_url` (String) | ||
| - `id` (Number) | ||
| - `login` (String) |
41 changes: 41 additions & 0 deletions
41
docs/data-sources/enterprise_organization_app_accessible_repositories.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| --- | ||
| page_title: "github_enterprise_organization_app_accessible_repositories (Data Source) - GitHub" | ||
| subcategory: "" | ||
| description: |- | ||
| Use this data source to retrieve the repositories of an enterprise-owned organization that GitHub Apps can be granted access to. This data source requires GitHub Enterprise Cloud or GitHub Enterprise Server 3.19+ and an authenticated user that is an enterprise owner. | ||
| --- | ||
|
|
||
| # github_enterprise_organization_app_accessible_repositories (Data Source) | ||
|
|
||
| Use this data source to retrieve the repositories of an enterprise-owned organization that GitHub Apps can be granted access to. This data source requires GitHub Enterprise Cloud or GitHub Enterprise Server 3.19+ and an authenticated user that is an enterprise owner. | ||
|
|
||
| ## Example Usage | ||
|
|
||
| ```terraform | ||
| data "github_enterprise_organization_app_accessible_repositories" "example" { | ||
| enterprise_slug = "my-enterprise" | ||
| organization = "my-org" | ||
| } | ||
| ``` | ||
|
|
||
| <!-- schema generated by tfplugindocs --> | ||
| ## Schema | ||
|
|
||
| ### Required | ||
|
|
||
| - `enterprise_slug` (String) The slug of the enterprise that owns the organization. | ||
| - `organization` (String) The login of the enterprise-owned organization. | ||
|
|
||
| ### Read-Only | ||
|
|
||
| - `id` (String) The ID of this resource. | ||
| - `repositories` (List of Object) List of repositories of the organization that GitHub Apps can be granted access to. (see [below for nested schema](#nestedatt--repositories)) | ||
|
|
||
| <a id="nestedatt--repositories"></a> | ||
| ### Nested Schema for `repositories` | ||
|
|
||
| Read-Only: | ||
|
|
||
| - `full_name` (String) | ||
| - `id` (Number) | ||
| - `name` (String) |
51 changes: 51 additions & 0 deletions
51
docs/data-sources/enterprise_organization_app_installations.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| --- | ||
| page_title: "github_enterprise_organization_app_installations (Data Source) - GitHub" | ||
| subcategory: "" | ||
| description: |- | ||
| Use this data source to retrieve the GitHub App installations on an enterprise-owned organization. This data source requires GitHub Enterprise Cloud or GitHub Enterprise Server 3.19+ and an authenticated user that is an enterprise owner. | ||
| --- | ||
|
|
||
| # github_enterprise_organization_app_installations (Data Source) | ||
|
|
||
| Use this data source to retrieve the GitHub App installations on an enterprise-owned organization. This data source requires GitHub Enterprise Cloud or GitHub Enterprise Server 3.19+ and an authenticated user that is an enterprise owner. | ||
|
|
||
| ## Example Usage | ||
|
|
||
| ```terraform | ||
| data "github_enterprise_organization_app_installations" "example" { | ||
| enterprise_slug = "my-enterprise" | ||
| organization = "my-org" | ||
| } | ||
| ``` | ||
|
|
||
| <!-- schema generated by tfplugindocs --> | ||
| ## Schema | ||
|
|
||
| ### Required | ||
|
|
||
| - `enterprise_slug` (String) The slug of the enterprise that owns the organization. | ||
| - `organization` (String) The login of the enterprise-owned organization. | ||
|
|
||
| ### Read-Only | ||
|
|
||
| - `id` (String) The ID of this resource. | ||
| - `installations` (List of Object) List of GitHub App installations on the organization. (see [below for nested schema](#nestedatt--installations)) | ||
|
|
||
| <a id="nestedatt--installations"></a> | ||
| ### Nested Schema for `installations` | ||
|
|
||
| Read-Only: | ||
|
|
||
| - `app_id` (Number) | ||
| - `app_slug` (String) | ||
| - `client_id` (String) | ||
| - `created_at` (String) | ||
| - `events` (List of String) | ||
| - `id` (Number) | ||
| - `permissions` (Map of String) | ||
| - `repository_selection` (String) | ||
| - `single_file_paths` (List of String) | ||
| - `suspended` (Boolean) | ||
| - `target_id` (Number) | ||
| - `target_type` (String) | ||
| - `updated_at` (String) |
59 changes: 59 additions & 0 deletions
59
docs/resources/enterprise_organization_app_installation.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| --- | ||
| page_title: "github_enterprise_organization_app_installation (Resource) - GitHub" | ||
| subcategory: "" | ||
| description: |- | ||
| Manage the installation of a GitHub App on an organization owned by an enterprise. The app is installed on the organization, not on the enterprise account itself; GitHub offers no API for the latter. This resource requires GitHub Enterprise Cloud or GitHub Enterprise Server 3.19+ and an authenticated user that is an enterprise owner. | ||
| --- | ||
|
|
||
| # github_enterprise_organization_app_installation (Resource) | ||
|
|
||
| Manage the installation of a GitHub App on an organization owned by an enterprise. The app is installed on the organization, not on the enterprise account itself; GitHub offers no API for the latter. This resource requires GitHub Enterprise Cloud or GitHub Enterprise Server 3.19+ and an authenticated user that is an enterprise owner. | ||
|
|
||
| ## Example Usage | ||
|
|
||
| ```terraform | ||
| resource "github_enterprise_organization_app_installation" "all_repos" { | ||
| enterprise_slug = "my-enterprise" | ||
| organization = "my-org" | ||
| client_id = "Iv1.abc123def456" | ||
| repository_selection = "all" | ||
| } | ||
|
|
||
| resource "github_enterprise_organization_app_installation" "selected_repos" { | ||
| enterprise_slug = "my-enterprise" | ||
| organization = "my-org" | ||
| client_id = "Iv1.789ghi012jkl" | ||
| repository_selection = "selected" | ||
| selected_repositories = ["my-repo-1", "my-repo-2"] | ||
| } | ||
| ``` | ||
|
|
||
| <!-- schema generated by tfplugindocs --> | ||
| ## Schema | ||
|
|
||
| ### Required | ||
|
|
||
| - `client_id` (String) The client ID of the GitHub App to install. | ||
| - `enterprise_slug` (String) The slug of the enterprise that owns the organization. | ||
| - `organization` (String) The login of the enterprise-owned organization to install the app on. | ||
| - `repository_selection` (String) The repositories the installation can access. Can be one of 'all', 'selected' or 'none'. | ||
|
|
||
| ### Optional | ||
|
|
||
| - `selected_repositories` (Set of String) The names of the repositories the installation can access when 'repository_selection' is 'selected'. | ||
|
|
||
| ### Read-Only | ||
|
|
||
| - `app_slug` (String) The slug of the installed app. | ||
| - `id` (String) The ID of this resource. | ||
| - `installation_id` (String) The ID of the installation. | ||
|
|
||
| ## Import | ||
|
|
||
| Import is supported using the following syntax: | ||
|
|
||
| The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example: | ||
|
|
||
| ```shell | ||
| terraform import github_enterprise_organization_app_installation.all_repos my-enterprise:my-org:Iv1.abc123def456 | ||
| ``` |
3 changes: 3 additions & 0 deletions
3
examples/data-sources/github_enterprise_app_installable_organizations/data-source_1.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| data "github_enterprise_app_installable_organizations" "example" { | ||
| enterprise_slug = "my-enterprise" | ||
| } |
4 changes: 4 additions & 0 deletions
4
.../data-sources/github_enterprise_organization_app_accessible_repositories/data-source_1.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| data "github_enterprise_organization_app_accessible_repositories" "example" { | ||
| enterprise_slug = "my-enterprise" | ||
| organization = "my-org" | ||
| } |
4 changes: 4 additions & 0 deletions
4
examples/data-sources/github_enterprise_organization_app_installations/data-source_1.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| data "github_enterprise_organization_app_installations" "example" { | ||
| enterprise_slug = "my-enterprise" | ||
| organization = "my-org" | ||
| } |
1 change: 1 addition & 0 deletions
1
examples/resources/github_enterprise_organization_app_installation/import.sh
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also add a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| terraform import github_enterprise_organization_app_installation.all_repos my-enterprise:my-org:Iv1.abc123def456 |
14 changes: 14 additions & 0 deletions
14
examples/resources/github_enterprise_organization_app_installation/resource.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| resource "github_enterprise_organization_app_installation" "all_repos" { | ||
| enterprise_slug = "my-enterprise" | ||
| organization = "my-org" | ||
| client_id = "Iv1.abc123def456" | ||
| repository_selection = "all" | ||
| } | ||
|
|
||
| resource "github_enterprise_organization_app_installation" "selected_repos" { | ||
| enterprise_slug = "my-enterprise" | ||
| organization = "my-org" | ||
| client_id = "Iv1.789ghi012jkl" | ||
| repository_selection = "selected" | ||
| selected_repositories = ["my-repo-1", "my-repo-2"] | ||
| } |
80 changes: 80 additions & 0 deletions
80
github/data_source_github_enterprise_app_installable_organizations.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package github | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/google/go-github/v89/github" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
| ) | ||
|
|
||
| func dataSourceGithubEnterpriseAppInstallableOrganizations() *schema.Resource { | ||
| return &schema.Resource{ | ||
| ReadContext: dataSourceGithubEnterpriseAppInstallableOrganizationsRead, | ||
| Description: "Use this data source to retrieve the enterprise-owned organizations that GitHub Apps can be installed on. " + | ||
| "This data source requires GitHub Enterprise Cloud or GitHub Enterprise Server 3.19+ and an authenticated user that is an enterprise owner.", | ||
|
|
||
| Schema: map[string]*schema.Schema{ | ||
| "enterprise_slug": { | ||
| Type: schema.TypeString, | ||
| Required: true, | ||
| Description: "The slug of the enterprise.", | ||
| }, | ||
| "organizations": { | ||
| Type: schema.TypeList, | ||
| Computed: true, | ||
| Description: "List of organizations in the enterprise that GitHub Apps can be installed on.", | ||
| Elem: &schema.Resource{ | ||
| Schema: map[string]*schema.Schema{ | ||
| "id": { | ||
| Type: schema.TypeInt, | ||
| Computed: true, | ||
| Description: "The ID of the organization.", | ||
| }, | ||
| "login": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| Description: "The login of the organization.", | ||
| }, | ||
| "accessible_repositories_url": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| Description: "The API URL listing the repositories that can be made accessible to a GitHub App installed on the organization.", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func dataSourceGithubEnterpriseAppInstallableOrganizationsRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { | ||
| meta, _ := m.(*Owner) | ||
| client := meta.v3client | ||
|
|
||
| enterpriseSlug := d.Get("enterprise_slug").(string) | ||
|
|
||
| opts := &github.ListOptions{ | ||
| PerPage: meta.maxPerPage, | ||
| } | ||
|
|
||
| results := make([]map[string]any, 0) | ||
| for organization, err := range client.Enterprise.ListAppInstallableOrganizationsIter(ctx, enterpriseSlug, opts) { | ||
| if err != nil { | ||
| return diag.FromErr(err) | ||
| } | ||
|
|
||
| results = append(results, map[string]any{ | ||
| "id": organization.ID, | ||
| "login": organization.Login, | ||
| "accessible_repositories_url": organization.GetAccessibleRepositoriesURL(), | ||
| }) | ||
| } | ||
|
|
||
| d.SetId(enterpriseSlug) | ||
| if err := d.Set("organizations", results); err != nil { | ||
| return diag.FromErr(err) | ||
| } | ||
|
|
||
| return nil | ||
| } |
43 changes: 43 additions & 0 deletions
43
github/data_source_github_enterprise_app_installable_organizations_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package github | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
| "github.com/hashicorp/terraform-plugin-testing/knownvalue" | ||
| "github.com/hashicorp/terraform-plugin-testing/statecheck" | ||
| "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" | ||
| ) | ||
|
|
||
| func TestAccDataSourceGithubEnterpriseAppInstallableOrganizations(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| skipUnlessEnterprise(t) | ||
|
|
||
| t.Run("queries_installable_organizations", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| config := fmt.Sprintf(` | ||
| data "github_enterprise_app_installable_organizations" "test" { | ||
| enterprise_slug = "%s" | ||
| } | ||
| `, testAccConf.enterpriseSlug) | ||
|
|
||
| resource.Test(t, resource.TestCase{ | ||
| ProviderFactories: providerFactories, | ||
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: config, | ||
| ConfigStateChecks: []statecheck.StateCheck{ | ||
| statecheck.ExpectKnownValue("data.github_enterprise_app_installable_organizations.test", tfjsonpath.New("organizations"), knownvalue.SetPartial([]knownvalue.Check{ | ||
| knownvalue.MapPartial(map[string]knownvalue.Check{ | ||
| "login": knownvalue.StringExact(testAccConf.owner), | ||
| }), | ||
| })), | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| }) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: The docs generation plugin has an issue with nested Schemas and their descriptions. We have a few docs templates where the fix is to comment out the generated output and then copy-pasting the descriptions for those missing ones manually. Could you do that for this one as well? 🙏