github.com/IBM-Cloud/terraform@v0.6.4-0.20170726051544-8872b87621df/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  			"gitlab_project_hook": resourceGitlabProjectHook(),
    30  		},
    31  
    32  		ConfigureFunc: providerConfigure,
    33  	}
    34  }
    35  
    36  var descriptions map[string]string
    37  
    38  func init() {
    39  	descriptions = map[string]string{
    40  		"token": "The OAuth token used to connect to GitLab.",
    41  
    42  		"base_url": "The GitLab Base API URL",
    43  	}
    44  }
    45  
    46  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    47  	config := Config{
    48  		Token:   d.Get("token").(string),
    49  		BaseURL: d.Get("base_url").(string),
    50  	}
    51  
    52  	return config.Client()
    53  }