github.com/arvindram03/terraform@v0.3.7-0.20150212015210-408f838db36d/builtin/providers/azure/provider.go (about)

     1  package azure
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/hashicorp/terraform/helper/schema"
     7  	"github.com/hashicorp/terraform/terraform"
     8  )
     9  
    10  func Provider() terraform.ResourceProvider {
    11  	return &schema.Provider{
    12  		Schema: map[string]*schema.Schema{
    13  			"publish_settings_file": &schema.Schema{
    14  				Type:        schema.TypeString,
    15  				Required:    true,
    16  				DefaultFunc: envDefaultFunc("AZURE_PUBLISH_SETTINGS_FILE"),
    17  			},
    18  		},
    19  
    20  		ResourcesMap: map[string]*schema.Resource{
    21  			"azure_virtual_machine":  resourceVirtualMachine(),
    22  		},
    23  
    24  		ConfigureFunc: providerConfigure,
    25  	}
    26  }
    27  
    28  func envDefaultFunc(k string) schema.SchemaDefaultFunc {
    29  	return func() (interface{}, error) {
    30  		if v := os.Getenv(k); v != "" {
    31  			return v, nil
    32  		}
    33  
    34  		return nil, nil
    35  	}
    36  }
    37  
    38  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    39  	config := Config{
    40  		PublishSettingsFile: d.Get("publish_settings_file").(string),
    41  	}
    42  
    43  	if err := config.loadAndValidate(); err != nil {
    44  		return nil, err
    45  	}
    46  
    47  	return &config, nil
    48  }