github.com/pmcatominey/terraform@v0.7.0-rc2.0.20160708105029-1401a52a5cc5/builtin/providers/openstack/provider.go (about) 1 package openstack 2 3 import ( 4 "github.com/hashicorp/terraform/helper/mutexkv" 5 "github.com/hashicorp/terraform/helper/schema" 6 "github.com/hashicorp/terraform/terraform" 7 ) 8 9 // This is a global MutexKV for use within this plugin. 10 var osMutexKV = mutexkv.NewMutexKV() 11 12 // Provider returns a schema.Provider for OpenStack. 13 func Provider() terraform.ResourceProvider { 14 return &schema.Provider{ 15 Schema: map[string]*schema.Schema{ 16 "auth_url": &schema.Schema{ 17 Type: schema.TypeString, 18 Required: true, 19 DefaultFunc: schema.EnvDefaultFunc("OS_AUTH_URL", nil), 20 }, 21 "user_name": &schema.Schema{ 22 Type: schema.TypeString, 23 Optional: true, 24 DefaultFunc: schema.EnvDefaultFunc("OS_USERNAME", ""), 25 }, 26 "user_id": &schema.Schema{ 27 Type: schema.TypeString, 28 Optional: true, 29 Default: "", 30 }, 31 "tenant_id": &schema.Schema{ 32 Type: schema.TypeString, 33 Optional: true, 34 Default: "", 35 }, 36 "tenant_name": &schema.Schema{ 37 Type: schema.TypeString, 38 Optional: true, 39 DefaultFunc: schema.EnvDefaultFunc("OS_TENANT_NAME", nil), 40 }, 41 "password": &schema.Schema{ 42 Type: schema.TypeString, 43 Optional: true, 44 DefaultFunc: schema.EnvDefaultFunc("OS_PASSWORD", ""), 45 }, 46 "token": &schema.Schema{ 47 Type: schema.TypeString, 48 Optional: true, 49 DefaultFunc: schema.EnvDefaultFunc("OS_AUTH_TOKEN", ""), 50 }, 51 "api_key": &schema.Schema{ 52 Type: schema.TypeString, 53 Optional: true, 54 DefaultFunc: schema.EnvDefaultFunc("OS_API_KEY", ""), 55 }, 56 "domain_id": &schema.Schema{ 57 Type: schema.TypeString, 58 Optional: true, 59 DefaultFunc: schema.EnvDefaultFunc("OS_DOMAIN_ID", ""), 60 }, 61 "domain_name": &schema.Schema{ 62 Type: schema.TypeString, 63 Optional: true, 64 DefaultFunc: schema.EnvDefaultFunc("OS_DOMAIN_NAME", ""), 65 }, 66 "insecure": &schema.Schema{ 67 Type: schema.TypeBool, 68 Optional: true, 69 Default: false, 70 }, 71 "endpoint_type": &schema.Schema{ 72 Type: schema.TypeString, 73 Optional: true, 74 DefaultFunc: schema.EnvDefaultFunc("OS_ENDPOINT_TYPE", ""), 75 }, 76 "cacert_file": &schema.Schema{ 77 Type: schema.TypeString, 78 Optional: true, 79 DefaultFunc: schema.EnvDefaultFunc("OS_CACERT", ""), 80 }, 81 "cert": &schema.Schema{ 82 Type: schema.TypeString, 83 Optional: true, 84 DefaultFunc: schema.EnvDefaultFunc("OS_CERT", ""), 85 }, 86 "key": &schema.Schema{ 87 Type: schema.TypeString, 88 Optional: true, 89 DefaultFunc: schema.EnvDefaultFunc("OS_KEY", ""), 90 }, 91 }, 92 93 ResourcesMap: map[string]*schema.Resource{ 94 "openstack_blockstorage_volume_v1": resourceBlockStorageVolumeV1(), 95 "openstack_blockstorage_volume_v2": resourceBlockStorageVolumeV2(), 96 "openstack_compute_instance_v2": resourceComputeInstanceV2(), 97 "openstack_compute_keypair_v2": resourceComputeKeypairV2(), 98 "openstack_compute_secgroup_v2": resourceComputeSecGroupV2(), 99 "openstack_compute_servergroup_v2": resourceComputeServerGroupV2(), 100 "openstack_compute_floatingip_v2": resourceComputeFloatingIPV2(), 101 "openstack_fw_firewall_v1": resourceFWFirewallV1(), 102 "openstack_fw_policy_v1": resourceFWPolicyV1(), 103 "openstack_fw_rule_v1": resourceFWRuleV1(), 104 "openstack_lb_member_v1": resourceLBMemberV1(), 105 "openstack_lb_monitor_v1": resourceLBMonitorV1(), 106 "openstack_lb_pool_v1": resourceLBPoolV1(), 107 "openstack_lb_vip_v1": resourceLBVipV1(), 108 "openstack_lb_loadbalancer_v2": resourceLoadBalancerV2(), 109 "openstack_lb_listener_v2": resourceListenerV2(), 110 "openstack_lb_pool_v2": resourcePoolV2(), 111 "openstack_lb_member_v2": resourceMemberV2(), 112 "openstack_lb_monitor_v2": resourceMonitorV2(), 113 "openstack_networking_network_v2": resourceNetworkingNetworkV2(), 114 "openstack_networking_subnet_v2": resourceNetworkingSubnetV2(), 115 "openstack_networking_floatingip_v2": resourceNetworkingFloatingIPV2(), 116 "openstack_networking_port_v2": resourceNetworkingPortV2(), 117 "openstack_networking_router_v2": resourceNetworkingRouterV2(), 118 "openstack_networking_router_interface_v2": resourceNetworkingRouterInterfaceV2(), 119 "openstack_networking_router_route_v2": resourceNetworkingRouterRouteV2(), 120 "openstack_networking_secgroup_v2": resourceNetworkingSecGroupV2(), 121 "openstack_networking_secgroup_rule_v2": resourceNetworkingSecGroupRuleV2(), 122 "openstack_objectstorage_container_v1": resourceObjectStorageContainerV1(), 123 }, 124 125 ConfigureFunc: configureProvider, 126 } 127 } 128 129 func configureProvider(d *schema.ResourceData) (interface{}, error) { 130 config := Config{ 131 IdentityEndpoint: d.Get("auth_url").(string), 132 Username: d.Get("user_name").(string), 133 UserID: d.Get("user_id").(string), 134 Password: d.Get("password").(string), 135 Token: d.Get("token").(string), 136 APIKey: d.Get("api_key").(string), 137 TenantID: d.Get("tenant_id").(string), 138 TenantName: d.Get("tenant_name").(string), 139 DomainID: d.Get("domain_id").(string), 140 DomainName: d.Get("domain_name").(string), 141 Insecure: d.Get("insecure").(bool), 142 EndpointType: d.Get("endpoint_type").(string), 143 CACertFile: d.Get("cacert_file").(string), 144 ClientCertFile: d.Get("cert").(string), 145 ClientKeyFile: d.Get("key").(string), 146 } 147 148 if err := config.loadAndValidate(); err != nil { 149 return nil, err 150 } 151 152 return &config, nil 153 }