2014-12-10 22:20:52 +01:00
|
|
|
package cloudstack
|
|
|
|
|
|
|
|
import (
|
2017-05-24 15:23:32 +02:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/go-ini/ini"
|
2014-12-10 22:20:52 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Provider returns a terraform.ResourceProvider.
|
|
|
|
func Provider() terraform.ResourceProvider {
|
|
|
|
return &schema.Provider{
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
"api_url": &schema.Schema{
|
2017-05-24 15:23:32 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("CLOUDSTACK_API_URL", nil),
|
|
|
|
ConflictsWith: []string{"config", "profile"},
|
2014-12-10 22:20:52 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
"api_key": &schema.Schema{
|
2017-05-24 15:23:32 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("CLOUDSTACK_API_KEY", nil),
|
|
|
|
ConflictsWith: []string{"config", "profile"},
|
2014-12-10 22:20:52 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
"secret_key": &schema.Schema{
|
2017-05-24 15:23:32 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("CLOUDSTACK_SECRET_KEY", nil),
|
|
|
|
ConflictsWith: []string{"config", "profile"},
|
|
|
|
},
|
|
|
|
|
|
|
|
"config": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
ConflictsWith: []string{"api_url", "api_key", "secret_key"},
|
|
|
|
},
|
|
|
|
|
|
|
|
"profile": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
ConflictsWith: []string{"api_url", "api_key", "secret_key"},
|
2015-01-12 15:57:24 +01:00
|
|
|
},
|
|
|
|
|
2015-07-16 17:40:04 +02:00
|
|
|
"http_get_only": &schema.Schema{
|
|
|
|
Type: schema.TypeBool,
|
|
|
|
Required: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("CLOUDSTACK_HTTP_GET_ONLY", false),
|
|
|
|
},
|
|
|
|
|
2015-01-12 15:57:24 +01:00
|
|
|
"timeout": &schema.Schema{
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
Required: true,
|
2015-12-01 00:36:33 +01:00
|
|
|
DefaultFunc: schema.EnvDefaultFunc("CLOUDSTACK_TIMEOUT", 900),
|
2014-12-10 22:20:52 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
ResourcesMap: map[string]*schema.Resource{
|
2016-09-01 10:48:49 +02:00
|
|
|
"cloudstack_affinity_group": resourceCloudStackAffinityGroup(),
|
2015-03-04 18:51:07 +01:00
|
|
|
"cloudstack_disk": resourceCloudStackDisk(),
|
|
|
|
"cloudstack_egress_firewall": resourceCloudStackEgressFirewall(),
|
|
|
|
"cloudstack_firewall": resourceCloudStackFirewall(),
|
|
|
|
"cloudstack_instance": resourceCloudStackInstance(),
|
|
|
|
"cloudstack_ipaddress": resourceCloudStackIPAddress(),
|
2015-08-04 19:16:42 +02:00
|
|
|
"cloudstack_loadbalancer_rule": resourceCloudStackLoadBalancerRule(),
|
2015-03-04 18:51:07 +01:00
|
|
|
"cloudstack_network": resourceCloudStackNetwork(),
|
|
|
|
"cloudstack_network_acl": resourceCloudStackNetworkACL(),
|
|
|
|
"cloudstack_network_acl_rule": resourceCloudStackNetworkACLRule(),
|
|
|
|
"cloudstack_nic": resourceCloudStackNIC(),
|
|
|
|
"cloudstack_port_forward": resourceCloudStackPortForward(),
|
2016-10-27 21:06:39 +02:00
|
|
|
"cloudstack_private_gateway": resourceCloudStackPrivateGateway(),
|
2015-07-16 17:40:04 +02:00
|
|
|
"cloudstack_secondary_ipaddress": resourceCloudStackSecondaryIPAddress(),
|
2016-10-26 09:29:37 +02:00
|
|
|
"cloudstack_security_group": resourceCloudStackSecurityGroup(),
|
2016-10-27 11:10:15 +02:00
|
|
|
"cloudstack_security_group_rule": resourceCloudStackSecurityGroupRule(),
|
2015-05-07 16:10:57 +02:00
|
|
|
"cloudstack_ssh_keypair": resourceCloudStackSSHKeyPair(),
|
2016-04-04 15:48:14 +02:00
|
|
|
"cloudstack_static_nat": resourceCloudStackStaticNAT(),
|
2016-10-27 21:06:39 +02:00
|
|
|
"cloudstack_static_route": resourceCloudStackStaticRoute(),
|
2015-03-18 11:11:56 +01:00
|
|
|
"cloudstack_template": resourceCloudStackTemplate(),
|
2015-03-04 18:51:07 +01:00
|
|
|
"cloudstack_vpc": resourceCloudStackVPC(),
|
|
|
|
"cloudstack_vpn_connection": resourceCloudStackVPNConnection(),
|
|
|
|
"cloudstack_vpn_customer_gateway": resourceCloudStackVPNCustomerGateway(),
|
|
|
|
"cloudstack_vpn_gateway": resourceCloudStackVPNGateway(),
|
2014-12-10 22:20:52 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
ConfigureFunc: providerConfigure,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
2017-05-24 15:23:32 +02:00
|
|
|
apiURL := d.Get("api_url").(string)
|
|
|
|
apiKey := d.Get("api_key").(string)
|
|
|
|
secretKey := d.Get("secret_key").(string)
|
|
|
|
|
|
|
|
if configFile, ok := d.GetOk("config"); ok {
|
|
|
|
config, err := ini.Load(configFile.(string))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
section, err := config.GetSection(d.Get("profile").(string))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
apiURL = section.Key("url").String()
|
|
|
|
apiKey = section.Key("apikey").String()
|
|
|
|
secretKey = section.Key("secretkey").String()
|
|
|
|
}
|
|
|
|
|
|
|
|
if apiURL == "" || apiKey == "" || secretKey == "" {
|
|
|
|
return nil, fmt.Errorf("No api_url or api_key or secretKey provided")
|
|
|
|
}
|
|
|
|
|
2014-12-10 22:20:52 +01:00
|
|
|
config := Config{
|
2017-05-24 15:23:32 +02:00
|
|
|
APIURL: apiURL,
|
|
|
|
APIKey: apiKey,
|
|
|
|
SecretKey: secretKey,
|
2015-07-16 17:40:04 +02:00
|
|
|
HTTPGETOnly: d.Get("http_get_only").(bool),
|
|
|
|
Timeout: int64(d.Get("timeout").(int)),
|
2014-12-10 22:20:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return config.NewClient()
|
|
|
|
}
|