github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/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 Description: descriptions["auth_url"], 21 }, 22 23 "user_name": &schema.Schema{ 24 Type: schema.TypeString, 25 Optional: true, 26 DefaultFunc: schema.EnvDefaultFunc("OS_USERNAME", ""), 27 Description: descriptions["user_name"], 28 }, 29 30 "user_id": &schema.Schema{ 31 Type: schema.TypeString, 32 Optional: true, 33 DefaultFunc: schema.EnvDefaultFunc("OS_USER_ID", ""), 34 Description: descriptions["user_name"], 35 }, 36 37 "tenant_id": &schema.Schema{ 38 Type: schema.TypeString, 39 Optional: true, 40 DefaultFunc: schema.MultiEnvDefaultFunc([]string{ 41 "OS_TENANT_ID", 42 "OS_PROJECT_ID", 43 }, ""), 44 Description: descriptions["tenant_id"], 45 }, 46 47 "tenant_name": &schema.Schema{ 48 Type: schema.TypeString, 49 Optional: true, 50 DefaultFunc: schema.MultiEnvDefaultFunc([]string{ 51 "OS_TENANT_NAME", 52 "OS_PROJECT_NAME", 53 }, ""), 54 Description: descriptions["tenant_name"], 55 }, 56 57 "password": &schema.Schema{ 58 Type: schema.TypeString, 59 Optional: true, 60 Sensitive: true, 61 DefaultFunc: schema.EnvDefaultFunc("OS_PASSWORD", ""), 62 Description: descriptions["password"], 63 }, 64 65 "token": &schema.Schema{ 66 Type: schema.TypeString, 67 Optional: true, 68 DefaultFunc: schema.EnvDefaultFunc("OS_AUTH_TOKEN", ""), 69 Description: descriptions["token"], 70 }, 71 72 "domain_id": &schema.Schema{ 73 Type: schema.TypeString, 74 Optional: true, 75 DefaultFunc: schema.MultiEnvDefaultFunc([]string{ 76 "OS_USER_DOMAIN_ID", 77 "OS_PROJECT_DOMAIN_ID", 78 "OS_DOMAIN_ID", 79 }, ""), 80 Description: descriptions["domain_id"], 81 }, 82 83 "domain_name": &schema.Schema{ 84 Type: schema.TypeString, 85 Optional: true, 86 DefaultFunc: schema.MultiEnvDefaultFunc([]string{ 87 "OS_USER_DOMAIN_NAME", 88 "OS_PROJECT_DOMAIN_NAME", 89 "OS_DOMAIN_NAME", 90 "OS_DEFAULT_DOMAIN", 91 }, ""), 92 Description: descriptions["domain_name"], 93 }, 94 95 "insecure": &schema.Schema{ 96 Type: schema.TypeBool, 97 Optional: true, 98 DefaultFunc: schema.EnvDefaultFunc("OS_INSECURE", ""), 99 Description: descriptions["insecure"], 100 }, 101 102 "endpoint_type": &schema.Schema{ 103 Type: schema.TypeString, 104 Optional: true, 105 DefaultFunc: schema.EnvDefaultFunc("OS_ENDPOINT_TYPE", ""), 106 }, 107 108 "cacert_file": &schema.Schema{ 109 Type: schema.TypeString, 110 Optional: true, 111 DefaultFunc: schema.EnvDefaultFunc("OS_CACERT", ""), 112 Description: descriptions["cacert_file"], 113 }, 114 115 "cert": &schema.Schema{ 116 Type: schema.TypeString, 117 Optional: true, 118 DefaultFunc: schema.EnvDefaultFunc("OS_CERT", ""), 119 Description: descriptions["cert"], 120 }, 121 122 "key": &schema.Schema{ 123 Type: schema.TypeString, 124 Optional: true, 125 DefaultFunc: schema.EnvDefaultFunc("OS_KEY", ""), 126 Description: descriptions["key"], 127 }, 128 129 "swauth": &schema.Schema{ 130 Type: schema.TypeBool, 131 Optional: true, 132 DefaultFunc: schema.EnvDefaultFunc("OS_SWAUTH", ""), 133 Description: descriptions["swauth"], 134 }, 135 }, 136 137 DataSourcesMap: map[string]*schema.Resource{ 138 "openstack_images_image_v2": dataSourceImagesImageV2(), 139 "openstack_networking_network_v2": dataSourceNetworkingNetworkV2(), 140 }, 141 142 ResourcesMap: map[string]*schema.Resource{ 143 "openstack_blockstorage_volume_v1": resourceBlockStorageVolumeV1(), 144 "openstack_blockstorage_volume_v2": resourceBlockStorageVolumeV2(), 145 "openstack_blockstorage_volume_attach_v2": resourceBlockStorageVolumeAttachV2(), 146 "openstack_compute_instance_v2": resourceComputeInstanceV2(), 147 "openstack_compute_keypair_v2": resourceComputeKeypairV2(), 148 "openstack_compute_secgroup_v2": resourceComputeSecGroupV2(), 149 "openstack_compute_servergroup_v2": resourceComputeServerGroupV2(), 150 "openstack_compute_floatingip_v2": resourceComputeFloatingIPV2(), 151 "openstack_compute_floatingip_associate_v2": resourceComputeFloatingIPAssociateV2(), 152 "openstack_compute_volume_attach_v2": resourceComputeVolumeAttachV2(), 153 "openstack_fw_firewall_v1": resourceFWFirewallV1(), 154 "openstack_fw_policy_v1": resourceFWPolicyV1(), 155 "openstack_fw_rule_v1": resourceFWRuleV1(), 156 "openstack_images_image_v2": resourceImagesImageV2(), 157 "openstack_lb_member_v1": resourceLBMemberV1(), 158 "openstack_lb_monitor_v1": resourceLBMonitorV1(), 159 "openstack_lb_pool_v1": resourceLBPoolV1(), 160 "openstack_lb_vip_v1": resourceLBVipV1(), 161 "openstack_lb_loadbalancer_v2": resourceLoadBalancerV2(), 162 "openstack_lb_listener_v2": resourceListenerV2(), 163 "openstack_lb_pool_v2": resourcePoolV2(), 164 "openstack_lb_member_v2": resourceMemberV2(), 165 "openstack_lb_monitor_v2": resourceMonitorV2(), 166 "openstack_networking_network_v2": resourceNetworkingNetworkV2(), 167 "openstack_networking_subnet_v2": resourceNetworkingSubnetV2(), 168 "openstack_networking_floatingip_v2": resourceNetworkingFloatingIPV2(), 169 "openstack_networking_port_v2": resourceNetworkingPortV2(), 170 "openstack_networking_router_v2": resourceNetworkingRouterV2(), 171 "openstack_networking_router_interface_v2": resourceNetworkingRouterInterfaceV2(), 172 "openstack_networking_router_route_v2": resourceNetworkingRouterRouteV2(), 173 "openstack_networking_secgroup_v2": resourceNetworkingSecGroupV2(), 174 "openstack_networking_secgroup_rule_v2": resourceNetworkingSecGroupRuleV2(), 175 "openstack_objectstorage_container_v1": resourceObjectStorageContainerV1(), 176 }, 177 178 ConfigureFunc: configureProvider, 179 } 180 } 181 182 var descriptions map[string]string 183 184 func init() { 185 descriptions = map[string]string{ 186 "auth_url": "The Identity authentication URL.", 187 188 "user_name": "Username to login with.", 189 190 "user_id": "User ID to login with.", 191 192 "tenant_id": "The ID of the Tenant (Identity v2) or Project (Identity v3)\n" + 193 "to login with.", 194 195 "tenant_name": "The name of the Tenant (Identity v2) or Project (Identity v3)\n" + 196 "to login with.", 197 198 "password": "Password to login with.", 199 200 "token": "Authentication token to use as an alternative to username/password.", 201 202 "domain_id": "The ID of the Domain to scope to (Identity v3).", 203 204 "domain_name": "The name of the Domain to scope to (Identity v3).", 205 206 "insecure": "Trust self-signed certificates.", 207 208 "cacert_file": "A Custom CA certificate.", 209 210 "endpoint_type": "The catalog endpoint type to use.", 211 212 "cert": "A client certificate to authenticate with.", 213 214 "key": "A client private key to authenticate with.", 215 216 "swauth": "Use Swift's authentication system instead of Keystone. Only used for\n" + 217 "interaction with Swift.", 218 } 219 } 220 221 func configureProvider(d *schema.ResourceData) (interface{}, error) { 222 config := Config{ 223 CACertFile: d.Get("cacert_file").(string), 224 ClientCertFile: d.Get("cert").(string), 225 ClientKeyFile: d.Get("key").(string), 226 DomainID: d.Get("domain_id").(string), 227 DomainName: d.Get("domain_name").(string), 228 EndpointType: d.Get("endpoint_type").(string), 229 IdentityEndpoint: d.Get("auth_url").(string), 230 Insecure: d.Get("insecure").(bool), 231 Password: d.Get("password").(string), 232 Swauth: d.Get("swauth").(bool), 233 Token: d.Get("token").(string), 234 TenantID: d.Get("tenant_id").(string), 235 TenantName: d.Get("tenant_name").(string), 236 Username: d.Get("user_name").(string), 237 UserID: d.Get("user_id").(string), 238 } 239 240 if err := config.loadAndValidate(); err != nil { 241 return nil, err 242 } 243 244 return &config, nil 245 }