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

Create data source for github app #1268

Merged
merged 6 commits into from
Oct 27, 2022
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
52 changes: 52 additions & 0 deletions github/data_source_github_app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package github

import (
"context"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func dataSourceGithubApp() *schema.Resource {
return &schema.Resource{
Read: dataSourceGithubAppRead,

Schema: map[string]*schema.Schema{
"slug": {
Type: schema.TypeString,
Required: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"node_id": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourceGithubAppRead(d *schema.ResourceData, meta interface{}) error {
slug := d.Get("slug").(string)

client := meta.(*Owner).v3client
ctx := context.Background()

app, _, err := client.Apps.Get(ctx, slug)
if err != nil {
return err
}

d.SetId(strconv.FormatInt(app.GetID(), 10))
d.Set("description", app.GetDescription())
d.Set("name", app.GetName())
d.Set("node_id", app.GetNodeID())

return nil
}
1 change: 1 addition & 0 deletions github/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func Provider() terraform.ResourceProvider {
"github_actions_organization_secrets": dataSourceGithubActionsOrganizationSecrets(),
"github_actions_public_key": dataSourceGithubActionsPublicKey(),
"github_actions_secrets": dataSourceGithubActionsSecrets(),
"github_app": dataSourceGithubApp(),
"github_branch": dataSourceGithubBranch(),
"github_collaborators": dataSourceGithubCollaborators(),
"github_dependabot_organization_secrets": dataSourceGithubDependabotOrganizationSecrets(),
Expand Down
35 changes: 35 additions & 0 deletions website/docs/d/app.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
layout: "github"
page_title: "GitHub: github_app"
description: |-
Get information about an app.
---

# github\_app

Use this data source to retrieve information about an app.

## Example Usage

```hcl
data "github_app" "foobar" {
slug = "foobar"
}
```

## Argument Reference

The following arguments are supported:

* `slug` - (Required) The URL-friendly name of your GitHub App.


## Attribute Reference

The following additional attributes are exported:

* `description` - The app's description.

* `name` - The app's full name.

* `node_id` - The Node ID of the app.
3 changes: 3 additions & 0 deletions website/github.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<li>
<a href="/docs/providers/github/d/actions_secrets.html">actions_secrets</a>
</li>
<li>
<a href="/docs/providers/github/d/app.html"></a>
</li>
<li>
<a href="/docs/providers/github/d/branch.html">github_branch</a>
</li>
Expand Down