github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/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  		ResourcesMap: map[string]*schema.Resource{
   138  			"openstack_blockstorage_volume_v1":         resourceBlockStorageVolumeV1(),
   139  			"openstack_blockstorage_volume_v2":         resourceBlockStorageVolumeV2(),
   140  			"openstack_blockstorage_volume_attach_v2":  resourceBlockStorageVolumeAttachV2(),
   141  			"openstack_compute_instance_v2":            resourceComputeInstanceV2(),
   142  			"openstack_compute_keypair_v2":             resourceComputeKeypairV2(),
   143  			"openstack_compute_secgroup_v2":            resourceComputeSecGroupV2(),
   144  			"openstack_compute_servergroup_v2":         resourceComputeServerGroupV2(),
   145  			"openstack_compute_floatingip_v2":          resourceComputeFloatingIPV2(),
   146  			"openstack_compute_volume_attach_v2":       resourceComputeVolumeAttachV2(),
   147  			"openstack_fw_firewall_v1":                 resourceFWFirewallV1(),
   148  			"openstack_fw_policy_v1":                   resourceFWPolicyV1(),
   149  			"openstack_fw_rule_v1":                     resourceFWRuleV1(),
   150  			"openstack_lb_member_v1":                   resourceLBMemberV1(),
   151  			"openstack_lb_monitor_v1":                  resourceLBMonitorV1(),
   152  			"openstack_lb_pool_v1":                     resourceLBPoolV1(),
   153  			"openstack_lb_vip_v1":                      resourceLBVipV1(),
   154  			"openstack_lb_loadbalancer_v2":             resourceLoadBalancerV2(),
   155  			"openstack_lb_listener_v2":                 resourceListenerV2(),
   156  			"openstack_lb_pool_v2":                     resourcePoolV2(),
   157  			"openstack_lb_member_v2":                   resourceMemberV2(),
   158  			"openstack_lb_monitor_v2":                  resourceMonitorV2(),
   159  			"openstack_networking_network_v2":          resourceNetworkingNetworkV2(),
   160  			"openstack_networking_subnet_v2":           resourceNetworkingSubnetV2(),
   161  			"openstack_networking_floatingip_v2":       resourceNetworkingFloatingIPV2(),
   162  			"openstack_networking_port_v2":             resourceNetworkingPortV2(),
   163  			"openstack_networking_router_v2":           resourceNetworkingRouterV2(),
   164  			"openstack_networking_router_interface_v2": resourceNetworkingRouterInterfaceV2(),
   165  			"openstack_networking_router_route_v2":     resourceNetworkingRouterRouteV2(),
   166  			"openstack_networking_secgroup_v2":         resourceNetworkingSecGroupV2(),
   167  			"openstack_networking_secgroup_rule_v2":    resourceNetworkingSecGroupRuleV2(),
   168  			"openstack_objectstorage_container_v1":     resourceObjectStorageContainerV1(),
   169  		},
   170  
   171  		ConfigureFunc: configureProvider,
   172  	}
   173  }
   174  
   175  var descriptions map[string]string
   176  
   177  func init() {
   178  	descriptions = map[string]string{
   179  		"auth_url": "The Identity authentication URL.",
   180  
   181  		"user_name": "Username to login with.",
   182  
   183  		"user_id": "User ID to login with.",
   184  
   185  		"tenant_id": "The ID of the Tenant (Identity v2) or Project (Identity v3)\n" +
   186  			"to login with.",
   187  
   188  		"tenant_name": "The name of the Tenant (Identity v2) or Project (Identity v3)\n" +
   189  			"to login with.",
   190  
   191  		"password": "Password to login with.",
   192  
   193  		"token": "Authentication token to use as an alternative to username/password.",
   194  
   195  		"domain_id": "The ID of the Domain to scope to (Identity v3).",
   196  
   197  		"domain_name": "The name of the Domain to scope to (Identity v3).",
   198  
   199  		"insecure": "Trust self-signed certificates.",
   200  
   201  		"cacert_file": "A Custom CA certificate.",
   202  
   203  		"endpoint_type": "The catalog endpoint type to use.",
   204  
   205  		"cert": "A client certificate to authenticate with.",
   206  
   207  		"key": "A client private key to authenticate with.",
   208  
   209  		"swauth": "Use Swift's authentication system instead of Keystone. Only used for\n" +
   210  			"interaction with Swift.",
   211  	}
   212  }
   213  
   214  func configureProvider(d *schema.ResourceData) (interface{}, error) {
   215  	config := Config{
   216  		CACertFile:       d.Get("cacert_file").(string),
   217  		ClientCertFile:   d.Get("cert").(string),
   218  		ClientKeyFile:    d.Get("key").(string),
   219  		DomainID:         d.Get("domain_id").(string),
   220  		DomainName:       d.Get("domain_name").(string),
   221  		EndpointType:     d.Get("endpoint_type").(string),
   222  		IdentityEndpoint: d.Get("auth_url").(string),
   223  		Insecure:         d.Get("insecure").(bool),
   224  		Password:         d.Get("password").(string),
   225  		Swauth:           d.Get("swauth").(bool),
   226  		Token:            d.Get("token").(string),
   227  		TenantID:         d.Get("tenant_id").(string),
   228  		TenantName:       d.Get("tenant_name").(string),
   229  		Username:         d.Get("user_name").(string),
   230  		UserID:           d.Get("user_id").(string),
   231  	}
   232  
   233  	if err := config.loadAndValidate(); err != nil {
   234  		return nil, err
   235  	}
   236  
   237  	return &config, nil
   238  }