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