terraform/builtin/providers/azure/provider.go

49 lines
988 B
Go
Raw Normal View History

2015-01-11 04:01:32 +01:00
package azure
import (
"os"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"publish_settings_file": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: envDefaultFunc("AZURE_PUBLISH_SETTINGS_FILE"),
},
},
ResourcesMap: map[string]*schema.Resource{
"azure_virtual_machine": resourceVirtualMachine(),
},
ConfigureFunc: providerConfigure,
}
}
func envDefaultFunc(k string) schema.SchemaDefaultFunc {
return func() (interface{}, error) {
if v := os.Getenv(k); v != "" {
return v, nil
}
return nil, nil
}
}
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config := Config{
PublishSettingsFile: d.Get("publish_settings_file").(string),
}
if err := config.loadAndValidate(); err != nil {
return nil, err
}
return &config, nil
}