github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/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 "domain_id": &schema.Schema{ 52 Type: schema.TypeString, 53 Optional: true, 54 DefaultFunc: schema.EnvDefaultFunc("OS_DOMAIN_ID", ""), 55 }, 56 "domain_name": &schema.Schema{ 57 Type: schema.TypeString, 58 Optional: true, 59 DefaultFunc: schema.EnvDefaultFunc("OS_DOMAIN_NAME", ""), 60 }, 61 "insecure": &schema.Schema{ 62 Type: schema.TypeBool, 63 Optional: true, 64 Default: false, 65 }, 66 "endpoint_type": &schema.Schema{ 67 Type: schema.TypeString, 68 Optional: true, 69 DefaultFunc: schema.EnvDefaultFunc("OS_ENDPOINT_TYPE", ""), 70 }, 71 "cacert_file": &schema.Schema{ 72 Type: schema.TypeString, 73 Optional: true, 74 DefaultFunc: schema.EnvDefaultFunc("OS_CACERT", ""), 75 }, 76 "cert": &schema.Schema{ 77 Type: schema.TypeString, 78 Optional: true, 79 DefaultFunc: schema.EnvDefaultFunc("OS_CERT", ""), 80 }, 81 "key": &schema.Schema{ 82 Type: schema.TypeString, 83 Optional: true, 84 DefaultFunc: schema.EnvDefaultFunc("OS_KEY", ""), 85 }, 86 }, 87 88 ResourcesMap: map[string]*schema.Resource{ 89 "openstack_blockstorage_volume_v1": resourceBlockStorageVolumeV1(), 90 "openstack_blockstorage_volume_v2": resourceBlockStorageVolumeV2(), 91 "openstack_compute_instance_v2": resourceComputeInstanceV2(), 92 "openstack_compute_keypair_v2": resourceComputeKeypairV2(), 93 "openstack_compute_secgroup_v2": resourceComputeSecGroupV2(), 94 "openstack_compute_servergroup_v2": resourceComputeServerGroupV2(), 95 "openstack_compute_floatingip_v2": resourceComputeFloatingIPV2(), 96 "openstack_fw_firewall_v1": resourceFWFirewallV1(), 97 "openstack_fw_policy_v1": resourceFWPolicyV1(), 98 "openstack_fw_rule_v1": resourceFWRuleV1(), 99 "openstack_lb_member_v1": resourceLBMemberV1(), 100 "openstack_lb_monitor_v1": resourceLBMonitorV1(), 101 "openstack_lb_pool_v1": resourceLBPoolV1(), 102 "openstack_lb_vip_v1": resourceLBVipV1(), 103 "openstack_lb_loadbalancer_v2": resourceLoadBalancerV2(), 104 "openstack_lb_listener_v2": resourceListenerV2(), 105 "openstack_lb_pool_v2": resourcePoolV2(), 106 "openstack_lb_member_v2": resourceMemberV2(), 107 "openstack_lb_monitor_v2": resourceMonitorV2(), 108 "openstack_networking_network_v2": resourceNetworkingNetworkV2(), 109 "openstack_networking_subnet_v2": resourceNetworkingSubnetV2(), 110 "openstack_networking_floatingip_v2": resourceNetworkingFloatingIPV2(), 111 "openstack_networking_port_v2": resourceNetworkingPortV2(), 112 "openstack_networking_router_v2": resourceNetworkingRouterV2(), 113 "openstack_networking_router_interface_v2": resourceNetworkingRouterInterfaceV2(), 114 "openstack_networking_router_route_v2": resourceNetworkingRouterRouteV2(), 115 "openstack_networking_secgroup_v2": resourceNetworkingSecGroupV2(), 116 "openstack_networking_secgroup_rule_v2": resourceNetworkingSecGroupRuleV2(), 117 "openstack_objectstorage_container_v1": resourceObjectStorageContainerV1(), 118 }, 119 120 ConfigureFunc: configureProvider, 121 } 122 } 123 124 func configureProvider(d *schema.ResourceData) (interface{}, error) { 125 config := Config{ 126 IdentityEndpoint: d.Get("auth_url").(string), 127 Username: d.Get("user_name").(string), 128 UserID: d.Get("user_id").(string), 129 Password: d.Get("password").(string), 130 Token: d.Get("token").(string), 131 TenantID: d.Get("tenant_id").(string), 132 TenantName: d.Get("tenant_name").(string), 133 DomainID: d.Get("domain_id").(string), 134 DomainName: d.Get("domain_name").(string), 135 Insecure: d.Get("insecure").(bool), 136 EndpointType: d.Get("endpoint_type").(string), 137 CACertFile: d.Get("cacert_file").(string), 138 ClientCertFile: d.Get("cert").(string), 139 ClientKeyFile: d.Get("key").(string), 140 } 141 142 if err := config.loadAndValidate(); err != nil { 143 return nil, err 144 } 145 146 return &config, nil 147 }