github.com/mohanarpit/terraform@v0.6.16-0.20160909104007-291f29853544/builtin/providers/cloudstack/provider.go (about)

     1  package cloudstack
     2  
     3  import (
     4  	"github.com/hashicorp/terraform/helper/schema"
     5  	"github.com/hashicorp/terraform/terraform"
     6  )
     7  
     8  // Provider returns a terraform.ResourceProvider.
     9  func Provider() terraform.ResourceProvider {
    10  	return &schema.Provider{
    11  		Schema: map[string]*schema.Schema{
    12  			"api_url": &schema.Schema{
    13  				Type:        schema.TypeString,
    14  				Required:    true,
    15  				DefaultFunc: schema.EnvDefaultFunc("CLOUDSTACK_API_URL", nil),
    16  			},
    17  
    18  			"api_key": &schema.Schema{
    19  				Type:        schema.TypeString,
    20  				Required:    true,
    21  				DefaultFunc: schema.EnvDefaultFunc("CLOUDSTACK_API_KEY", nil),
    22  			},
    23  
    24  			"secret_key": &schema.Schema{
    25  				Type:        schema.TypeString,
    26  				Required:    true,
    27  				DefaultFunc: schema.EnvDefaultFunc("CLOUDSTACK_SECRET_KEY", nil),
    28  			},
    29  
    30  			"http_get_only": &schema.Schema{
    31  				Type:        schema.TypeBool,
    32  				Required:    true,
    33  				DefaultFunc: schema.EnvDefaultFunc("CLOUDSTACK_HTTP_GET_ONLY", false),
    34  			},
    35  
    36  			"timeout": &schema.Schema{
    37  				Type:        schema.TypeInt,
    38  				Required:    true,
    39  				DefaultFunc: schema.EnvDefaultFunc("CLOUDSTACK_TIMEOUT", 900),
    40  			},
    41  		},
    42  
    43  		ResourcesMap: map[string]*schema.Resource{
    44  			"cloudstack_affinity_group":       resourceCloudStackAffinityGroup(),
    45  			"cloudstack_disk":                 resourceCloudStackDisk(),
    46  			"cloudstack_egress_firewall":      resourceCloudStackEgressFirewall(),
    47  			"cloudstack_firewall":             resourceCloudStackFirewall(),
    48  			"cloudstack_instance":             resourceCloudStackInstance(),
    49  			"cloudstack_ipaddress":            resourceCloudStackIPAddress(),
    50  			"cloudstack_loadbalancer_rule":    resourceCloudStackLoadBalancerRule(),
    51  			"cloudstack_network":              resourceCloudStackNetwork(),
    52  			"cloudstack_network_acl":          resourceCloudStackNetworkACL(),
    53  			"cloudstack_network_acl_rule":     resourceCloudStackNetworkACLRule(),
    54  			"cloudstack_nic":                  resourceCloudStackNIC(),
    55  			"cloudstack_port_forward":         resourceCloudStackPortForward(),
    56  			"cloudstack_secondary_ipaddress":  resourceCloudStackSecondaryIPAddress(),
    57  			"cloudstack_ssh_keypair":          resourceCloudStackSSHKeyPair(),
    58  			"cloudstack_static_nat":           resourceCloudStackStaticNAT(),
    59  			"cloudstack_template":             resourceCloudStackTemplate(),
    60  			"cloudstack_vpc":                  resourceCloudStackVPC(),
    61  			"cloudstack_vpn_connection":       resourceCloudStackVPNConnection(),
    62  			"cloudstack_vpn_customer_gateway": resourceCloudStackVPNCustomerGateway(),
    63  			"cloudstack_vpn_gateway":          resourceCloudStackVPNGateway(),
    64  		},
    65  
    66  		ConfigureFunc: providerConfigure,
    67  	}
    68  }
    69  
    70  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    71  	config := Config{
    72  		APIURL:      d.Get("api_url").(string),
    73  		APIKey:      d.Get("api_key").(string),
    74  		SecretKey:   d.Get("secret_key").(string),
    75  		HTTPGETOnly: d.Get("http_get_only").(bool),
    76  		Timeout:     int64(d.Get("timeout").(int)),
    77  	}
    78  
    79  	return config.NewClient()
    80  }