github.com/andresvia/terraform@v0.6.15-0.20160412045437-d51c75946785/builtin/providers/openstack/provider.go (about) 1 package openstack 2 3 import ( 4 "github.com/hashicorp/terraform/helper/schema" 5 "github.com/hashicorp/terraform/terraform" 6 ) 7 8 // Provider returns a schema.Provider for OpenStack. 9 func Provider() terraform.ResourceProvider { 10 return &schema.Provider{ 11 Schema: map[string]*schema.Schema{ 12 "auth_url": &schema.Schema{ 13 Type: schema.TypeString, 14 Required: true, 15 DefaultFunc: schema.EnvDefaultFunc("OS_AUTH_URL", nil), 16 }, 17 "user_name": &schema.Schema{ 18 Type: schema.TypeString, 19 Optional: true, 20 DefaultFunc: schema.EnvDefaultFunc("OS_USERNAME", nil), 21 }, 22 "user_id": &schema.Schema{ 23 Type: schema.TypeString, 24 Optional: true, 25 Default: "", 26 }, 27 "tenant_id": &schema.Schema{ 28 Type: schema.TypeString, 29 Optional: true, 30 Default: "", 31 }, 32 "tenant_name": &schema.Schema{ 33 Type: schema.TypeString, 34 Optional: true, 35 DefaultFunc: schema.EnvDefaultFunc("OS_TENANT_NAME", nil), 36 }, 37 "password": &schema.Schema{ 38 Type: schema.TypeString, 39 Optional: true, 40 DefaultFunc: schema.EnvDefaultFunc("OS_PASSWORD", nil), 41 }, 42 "api_key": &schema.Schema{ 43 Type: schema.TypeString, 44 Optional: true, 45 DefaultFunc: schema.EnvDefaultFunc("OS_AUTH_TOKEN", ""), 46 }, 47 "domain_id": &schema.Schema{ 48 Type: schema.TypeString, 49 Optional: true, 50 DefaultFunc: schema.EnvDefaultFunc("OS_DOMAIN_ID", ""), 51 }, 52 "domain_name": &schema.Schema{ 53 Type: schema.TypeString, 54 Optional: true, 55 DefaultFunc: schema.EnvDefaultFunc("OS_DOMAIN_NAME", ""), 56 }, 57 "insecure": &schema.Schema{ 58 Type: schema.TypeBool, 59 Optional: true, 60 Default: false, 61 }, 62 "endpoint_type": &schema.Schema{ 63 Type: schema.TypeString, 64 Optional: true, 65 DefaultFunc: schema.EnvDefaultFunc("OS_ENDPOINT_TYPE", ""), 66 }, 67 "cacert_file": &schema.Schema{ 68 Type: schema.TypeString, 69 Optional: true, 70 DefaultFunc: schema.EnvDefaultFunc("OS_CACERT", ""), 71 }, 72 }, 73 74 ResourcesMap: map[string]*schema.Resource{ 75 "openstack_blockstorage_volume_v1": resourceBlockStorageVolumeV1(), 76 "openstack_compute_instance_v2": resourceComputeInstanceV2(), 77 "openstack_compute_keypair_v2": resourceComputeKeypairV2(), 78 "openstack_compute_secgroup_v2": resourceComputeSecGroupV2(), 79 "openstack_compute_servergroup_v2": resourceComputeServerGroupV2(), 80 "openstack_compute_floatingip_v2": resourceComputeFloatingIPV2(), 81 "openstack_fw_firewall_v1": resourceFWFirewallV1(), 82 "openstack_fw_policy_v1": resourceFWPolicyV1(), 83 "openstack_fw_rule_v1": resourceFWRuleV1(), 84 "openstack_lb_member_v1": resourceLBMemberV1(), 85 "openstack_lb_monitor_v1": resourceLBMonitorV1(), 86 "openstack_lb_pool_v1": resourceLBPoolV1(), 87 "openstack_lb_vip_v1": resourceLBVipV1(), 88 "openstack_networking_network_v2": resourceNetworkingNetworkV2(), 89 "openstack_networking_subnet_v2": resourceNetworkingSubnetV2(), 90 "openstack_networking_floatingip_v2": resourceNetworkingFloatingIPV2(), 91 "openstack_networking_port_v2": resourceNetworkingPortV2(), 92 "openstack_networking_router_v2": resourceNetworkingRouterV2(), 93 "openstack_networking_router_interface_v2": resourceNetworkingRouterInterfaceV2(), 94 "openstack_objectstorage_container_v1": resourceObjectStorageContainerV1(), 95 }, 96 97 ConfigureFunc: configureProvider, 98 } 99 } 100 101 func configureProvider(d *schema.ResourceData) (interface{}, error) { 102 config := Config{ 103 IdentityEndpoint: d.Get("auth_url").(string), 104 Username: d.Get("user_name").(string), 105 UserID: d.Get("user_id").(string), 106 Password: d.Get("password").(string), 107 APIKey: d.Get("api_key").(string), 108 TenantID: d.Get("tenant_id").(string), 109 TenantName: d.Get("tenant_name").(string), 110 DomainID: d.Get("domain_id").(string), 111 DomainName: d.Get("domain_name").(string), 112 Insecure: d.Get("insecure").(bool), 113 EndpointType: d.Get("endpoint_type").(string), 114 CACertFile: d.Get("cacert_file").(string), 115 } 116 117 if err := config.loadAndValidate(); err != nil { 118 return nil, err 119 } 120 121 return &config, nil 122 }