github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/github/provider.go (about)

     1  package github
     2  
     3  import (
     4  	"github.com/hashicorp/terraform/helper/schema"
     5  	"github.com/hashicorp/terraform/terraform"
     6  )
     7  
     8  // Provider returns a terraform.ResourceProvider.
     9  func Provider() terraform.ResourceProvider {
    10  
    11  	// The actual provider
    12  	return &schema.Provider{
    13  		Schema: map[string]*schema.Schema{
    14  			"token": &schema.Schema{
    15  				Type:        schema.TypeString,
    16  				Required:    true,
    17  				DefaultFunc: schema.EnvDefaultFunc("GITHUB_TOKEN", nil),
    18  				Description: descriptions["token"],
    19  			},
    20  			"organization": &schema.Schema{
    21  				Type:        schema.TypeString,
    22  				Required:    true,
    23  				DefaultFunc: schema.EnvDefaultFunc("GITHUB_ORGANIZATION", nil),
    24  				Description: descriptions["organization"],
    25  			},
    26  			"base_url": &schema.Schema{
    27  				Type:        schema.TypeString,
    28  				Optional:    true,
    29  				DefaultFunc: schema.EnvDefaultFunc("GITHUB_BASE_URL", ""),
    30  				Description: descriptions["base_url"],
    31  			},
    32  		},
    33  
    34  		ResourcesMap: map[string]*schema.Resource{
    35  			"github_team":                    resourceGithubTeam(),
    36  			"github_team_membership":         resourceGithubTeamMembership(),
    37  			"github_team_repository":         resourceGithubTeamRepository(),
    38  			"github_membership":              resourceGithubMembership(),
    39  			"github_repository":              resourceGithubRepository(),
    40  			"github_repository_collaborator": resourceGithubRepositoryCollaborator(),
    41  		},
    42  
    43  		ConfigureFunc: providerConfigure,
    44  	}
    45  }
    46  
    47  var descriptions map[string]string
    48  
    49  func init() {
    50  	descriptions = map[string]string{
    51  		"token": "The OAuth token used to connect to GitHub.",
    52  
    53  		"organization": "The GitHub organization name to manage.",
    54  
    55  		"base_url": "The GitHub Base API URL",
    56  	}
    57  }
    58  
    59  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    60  	config := Config{
    61  		Token:        d.Get("token").(string),
    62  		Organization: d.Get("organization").(string),
    63  		BaseURL:      d.Get("base_url").(string),
    64  	}
    65  
    66  	return config.Client()
    67  }