github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/cobbler/provider.go (about) 1 package cobbler 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 "url": &schema.Schema{ 14 Type: schema.TypeString, 15 Required: true, 16 Description: "Cobbler URL", 17 DefaultFunc: envDefaultFunc("COBBLER_URL"), 18 }, 19 20 "username": &schema.Schema{ 21 Type: schema.TypeString, 22 Required: true, 23 Description: "The username for accessing Cobbler.", 24 DefaultFunc: envDefaultFunc("COBBLER_USERNAME"), 25 }, 26 27 "password": &schema.Schema{ 28 Type: schema.TypeString, 29 Required: true, 30 Description: "The password for accessing Cobbler.", 31 DefaultFunc: envDefaultFunc("COBBLER_PASSWORD"), 32 }, 33 }, 34 35 ResourcesMap: map[string]*schema.Resource{ 36 "cobbler_distro": resourceDistro(), 37 "cobbler_kickstart_file": resourceKickstartFile(), 38 "cobbler_profile": resourceProfile(), 39 "cobbler_snippet": resourceSnippet(), 40 "cobbler_system": resourceSystem(), 41 }, 42 43 ConfigureFunc: configureProvider, 44 } 45 } 46 47 func configureProvider(d *schema.ResourceData) (interface{}, error) { 48 config := Config{ 49 Url: d.Get("url").(string), 50 Username: d.Get("username").(string), 51 Password: d.Get("password").(string), 52 } 53 54 if err := config.loadAndValidate(); err != nil { 55 return nil, err 56 } 57 58 return &config, nil 59 } 60 61 func envDefaultFunc(k string) schema.SchemaDefaultFunc { 62 return func() (interface{}, error) { 63 if v := os.Getenv(k); v != "" { 64 return v, nil 65 } 66 67 return nil, nil 68 } 69 } 70 71 func envDefaultFuncAllowMissing(k string) schema.SchemaDefaultFunc { 72 return func() (interface{}, error) { 73 v := os.Getenv(k) 74 return v, nil 75 } 76 }