github.com/anfernee/terraform@v0.6.16-0.20160430000239-06e5085a92f2/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 }, 82 83 ResourcesMap: map[string]*schema.Resource{ 84 "openstack_blockstorage_volume_v1": resourceBlockStorageVolumeV1(), 85 "openstack_compute_instance_v2": resourceComputeInstanceV2(), 86 "openstack_compute_keypair_v2": resourceComputeKeypairV2(), 87 "openstack_compute_secgroup_v2": resourceComputeSecGroupV2(), 88 "openstack_compute_servergroup_v2": resourceComputeServerGroupV2(), 89 "openstack_compute_floatingip_v2": resourceComputeFloatingIPV2(), 90 "openstack_fw_firewall_v1": resourceFWFirewallV1(), 91 "openstack_fw_policy_v1": resourceFWPolicyV1(), 92 "openstack_fw_rule_v1": resourceFWRuleV1(), 93 "openstack_lb_member_v1": resourceLBMemberV1(), 94 "openstack_lb_monitor_v1": resourceLBMonitorV1(), 95 "openstack_lb_pool_v1": resourceLBPoolV1(), 96 "openstack_lb_vip_v1": resourceLBVipV1(), 97 "openstack_networking_network_v2": resourceNetworkingNetworkV2(), 98 "openstack_networking_subnet_v2": resourceNetworkingSubnetV2(), 99 "openstack_networking_floatingip_v2": resourceNetworkingFloatingIPV2(), 100 "openstack_networking_port_v2": resourceNetworkingPortV2(), 101 "openstack_networking_router_v2": resourceNetworkingRouterV2(), 102 "openstack_networking_router_interface_v2": resourceNetworkingRouterInterfaceV2(), 103 "openstack_networking_router_route_v2": resourceNetworkingRouterRouteV2(), 104 "openstack_objectstorage_container_v1": resourceObjectStorageContainerV1(), 105 }, 106 107 ConfigureFunc: configureProvider, 108 } 109 } 110 111 func configureProvider(d *schema.ResourceData) (interface{}, error) { 112 config := Config{ 113 IdentityEndpoint: d.Get("auth_url").(string), 114 Username: d.Get("user_name").(string), 115 UserID: d.Get("user_id").(string), 116 Password: d.Get("password").(string), 117 Token: d.Get("token").(string), 118 APIKey: d.Get("api_key").(string), 119 TenantID: d.Get("tenant_id").(string), 120 TenantName: d.Get("tenant_name").(string), 121 DomainID: d.Get("domain_id").(string), 122 DomainName: d.Get("domain_name").(string), 123 Insecure: d.Get("insecure").(bool), 124 EndpointType: d.Get("endpoint_type").(string), 125 CACertFile: d.Get("cacert_file").(string), 126 } 127 128 if err := config.loadAndValidate(); err != nil { 129 return nil, err 130 } 131 132 return &config, nil 133 }