github.com/andrewrynhard/terraform@v0.9.5-0.20170502003928-8d286b83eae4/builtin/providers/gitlab/provider.go (about)

     1  package gitlab
     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": {
    15  				Type:        schema.TypeString,
    16  				Required:    true,
    17  				DefaultFunc: schema.EnvDefaultFunc("GITLAB_TOKEN", nil),
    18  				Description: descriptions["token"],
    19  			},
    20  			"base_url": {
    21  				Type:        schema.TypeString,
    22  				Optional:    true,
    23  				DefaultFunc: schema.EnvDefaultFunc("GITLAB_BASE_URL", ""),
    24  				Description: descriptions["base_url"],
    25  			},
    26  		},
    27  		ResourcesMap: map[string]*schema.Resource{
    28  			"gitlab_project": resourceGitlabProject(),
    29  		},
    30  
    31  		ConfigureFunc: providerConfigure,
    32  	}
    33  }
    34  
    35  var descriptions map[string]string
    36  
    37  func init() {
    38  	descriptions = map[string]string{
    39  		"token": "The OAuth token used to connect to GitLab.",
    40  
    41  		"base_url": "The GitLab Base API URL",
    42  	}
    43  }
    44  
    45  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    46  	config := Config{
    47  		Token:   d.Get("token").(string),
    48  		BaseURL: d.Get("base_url").(string),
    49  	}
    50  
    51  	return config.Client()
    52  }