github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/builtin/providers/opc/provider.go (about)

     1  package opc
     2  
     3  import (
     4  	"github.com/hashicorp/terraform/helper/schema"
     5  	"github.com/hashicorp/terraform/terraform"
     6  )
     7  
     8  func Provider() terraform.ResourceProvider {
     9  	return &schema.Provider{
    10  		Schema: map[string]*schema.Schema{
    11  			"user": {
    12  				Type:        schema.TypeString,
    13  				Required:    true,
    14  				DefaultFunc: schema.EnvDefaultFunc("OPC_USERNAME", nil),
    15  				Description: "The user name for OPC API operations.",
    16  			},
    17  
    18  			"password": {
    19  				Type:        schema.TypeString,
    20  				Required:    true,
    21  				DefaultFunc: schema.EnvDefaultFunc("OPC_PASSWORD", nil),
    22  				Description: "The user password for OPC API operations.",
    23  			},
    24  
    25  			"identity_domain": {
    26  				Type:        schema.TypeString,
    27  				Required:    true,
    28  				DefaultFunc: schema.EnvDefaultFunc("OPC_IDENTITY_DOMAIN", nil),
    29  				Description: "The OPC identity domain for API operations",
    30  			},
    31  
    32  			"endpoint": {
    33  				Type:        schema.TypeString,
    34  				Required:    true,
    35  				DefaultFunc: schema.EnvDefaultFunc("OPC_ENDPOINT", nil),
    36  				Description: "The HTTP endpoint for OPC API operations.",
    37  			},
    38  
    39  			// TODO Actually implement this
    40  			"max_retry_timeout": {
    41  				Type:        schema.TypeInt,
    42  				Optional:    true,
    43  				DefaultFunc: schema.EnvDefaultFunc("OPC_MAX_RETRY_TIMEOUT", 3000),
    44  				Description: "Max num seconds to wait for successful response when operating on resources within OPC (defaults to 3000)",
    45  			},
    46  		},
    47  
    48  		DataSourcesMap: map[string]*schema.Resource{
    49  			"opc_compute_network_interface": dataSourceNetworkInterface(),
    50  			"opc_compute_vnic":              dataSourceVNIC(),
    51  		},
    52  
    53  		ResourcesMap: map[string]*schema.Resource{
    54  			"opc_compute_ip_network":              resourceOPCIPNetwork(),
    55  			"opc_compute_acl":                     resourceOPCACL(),
    56  			"opc_compute_image_list":              resourceOPCImageList(),
    57  			"opc_compute_image_list_entry":        resourceOPCImageListEntry(),
    58  			"opc_compute_instance":                resourceInstance(),
    59  			"opc_compute_ip_address_reservation":  resourceOPCIPAddressReservation(),
    60  			"opc_compute_ip_association":          resourceOPCIPAssociation(),
    61  			"opc_compute_ip_network_exchange":     resourceOPCIPNetworkExchange(),
    62  			"opc_compute_ip_reservation":          resourceOPCIPReservation(),
    63  			"opc_compute_route":                   resourceOPCRoute(),
    64  			"opc_compute_security_application":    resourceOPCSecurityApplication(),
    65  			"opc_compute_security_association":    resourceOPCSecurityAssociation(),
    66  			"opc_compute_security_ip_list":        resourceOPCSecurityIPList(),
    67  			"opc_compute_security_list":           resourceOPCSecurityList(),
    68  			"opc_compute_security_rule":           resourceOPCSecurityRule(),
    69  			"opc_compute_sec_rule":                resourceOPCSecRule(),
    70  			"opc_compute_ssh_key":                 resourceOPCSSHKey(),
    71  			"opc_compute_storage_volume":          resourceOPCStorageVolume(),
    72  			"opc_compute_storage_volume_snapshot": resourceOPCStorageVolumeSnapshot(),
    73  			"opc_compute_vnic_set":                resourceOPCVNICSet(),
    74  			"opc_compute_security_protocol":       resourceOPCSecurityProtocol(),
    75  			"opc_compute_ip_address_prefix_set":   resourceOPCIPAddressPrefixSet(),
    76  			"opc_compute_ip_address_association":  resourceOPCIPAddressAssociation(),
    77  		},
    78  
    79  		ConfigureFunc: providerConfigure,
    80  	}
    81  }
    82  
    83  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    84  	config := Config{
    85  		User:            d.Get("user").(string),
    86  		Password:        d.Get("password").(string),
    87  		IdentityDomain:  d.Get("identity_domain").(string),
    88  		Endpoint:        d.Get("endpoint").(string),
    89  		MaxRetryTimeout: d.Get("max_retry_timeout").(int),
    90  	}
    91  
    92  	return config.Client()
    93  }