github.com/ricardclau/terraform@v0.6.17-0.20160519222547-283e3ae6b5a9/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  		},
    40  
    41  		ConfigureFunc: providerConfigure,
    42  	}
    43  }
    44  
    45  var descriptions map[string]string
    46  
    47  func init() {
    48  	descriptions = map[string]string{
    49  		"token": "The OAuth token used to connect to GitHub.",
    50  
    51  		"organization": "The GitHub organization name to manage.",
    52  
    53  		"base_url": "The GitHub Base API URL",
    54  	}
    55  }
    56  
    57  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    58  	config := Config{
    59  		Token:        d.Get("token").(string),
    60  		Organization: d.Get("organization").(string),
    61  		BaseURL:      d.Get("base_url").(string),
    62  	}
    63  
    64  	return config.Client()
    65  }