Skip to content

Commit

Permalink
Add support for the Base URL endpoint so the GitHub provider can supp…
Browse files Browse the repository at this point in the history
…ort GitHub Enterprise (#6434)
  • Loading branch information
kddejong authored and stack72 committed May 9, 2016
1 parent 02d4458 commit 0cec1c1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
10 changes: 10 additions & 0 deletions builtin/providers/github/config.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package github

import (
"net/url"

"github.com/google/go-github/github"
"golang.org/x/oauth2"
)

type Config struct {
Token string
Organization string
BaseURL string
}

type Organization struct {
Expand All @@ -25,5 +28,12 @@ func (c *Config) Client() (interface{}, error) {
tc := oauth2.NewClient(oauth2.NoContext, ts)

org.client = github.NewClient(tc)
if c.BaseURL != "" {
u, err := url.Parse(c.BaseURL)
if err != nil {
return nil, err
}
org.client.BaseURL = u
}
return &org, nil
}
9 changes: 9 additions & 0 deletions builtin/providers/github/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ func Provider() terraform.ResourceProvider {
DefaultFunc: schema.EnvDefaultFunc("GITHUB_ORGANIZATION", nil),
Description: descriptions["organization"],
},
"base_url": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("GITHUB_BASE_URL", ""),
Description: descriptions["base_url"],
},
},

ResourcesMap: map[string]*schema.Resource{
Expand All @@ -43,13 +49,16 @@ func init() {
"token": "The OAuth token used to connect to GitHub.",

"organization": "The GitHub organization name to manage.",

"base_url": "The GitHub Base API URL",
}
}

func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config := Config{
Token: d.Get("token").(string),
Organization: d.Get("organization").(string),
BaseURL: d.Get("base_url").(string),
}

return config.Client()
Expand Down
8 changes: 6 additions & 2 deletions website/source/docs/providers/github/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ description: |-

# GitHub Provider

The GitHub provider is used to interact with GitHub organization resources.
The GitHub provider is used to interact with GitHub organization resources.

The provider allows you to manage your GitHub organization's members and teams easily.
The provider allows you to manage your GitHub organization's members and teams easily.
It needs to be configured with the proper credentials before it can be used.

Use the navigation to the left to read about the available resources.
Expand Down Expand Up @@ -40,3 +40,7 @@ The following arguments are supported in the `provider` block:
* `organization` - (Optional) This is the target GitHub organization to manage. The account
corresponding to the token will need "owner" privileges for this organization. It must be provided, but
it can also be sourced from the `GITHUB_ORGANIZATION` environment variable.

* `base_url` - (Optional) This is the target GitHub base API endpoint. Providing a value is a
requirement when working with GitHub Enterprise. It is optional to provide this value and
it can also be sourced from the `GITHUB_BASE_URL` environment variable. The value must end with a slash.

0 comments on commit 0cec1c1

Please sign in to comment.