2014-12-10 22:20:52 +01:00
|
|
|
package cloudstack
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
var testAccProviders map[string]terraform.ResourceProvider
|
|
|
|
var testAccProvider *schema.Provider
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
testAccProvider = Provider().(*schema.Provider)
|
|
|
|
testAccProviders = map[string]terraform.ResourceProvider{
|
|
|
|
"cloudstack": testAccProvider,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProvider(t *testing.T) {
|
|
|
|
if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProvider_impl(t *testing.T) {
|
|
|
|
var _ terraform.ResourceProvider = Provider()
|
|
|
|
}
|
|
|
|
|
2015-04-29 11:21:37 +02:00
|
|
|
func testSetValueOnResourceData(t *testing.T) {
|
|
|
|
d := schema.ResourceData{}
|
|
|
|
d.Set("id", "name")
|
|
|
|
|
2015-10-05 14:05:21 +02:00
|
|
|
setValueOrID(&d, "id", "name", "54711781-274e-41b2-83c0-17194d0108f7")
|
2015-04-29 11:21:37 +02:00
|
|
|
|
|
|
|
if d.Get("id").(string) != "name" {
|
|
|
|
t.Fatal("err: 'id' does not match 'name'")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-05 14:05:21 +02:00
|
|
|
func testSetIDOnResourceData(t *testing.T) {
|
2015-04-29 11:21:37 +02:00
|
|
|
d := schema.ResourceData{}
|
|
|
|
d.Set("id", "54711781-274e-41b2-83c0-17194d0108f7")
|
|
|
|
|
2015-10-05 14:05:21 +02:00
|
|
|
setValueOrID(&d, "id", "name", "54711781-274e-41b2-83c0-17194d0108f7")
|
2015-04-29 11:21:37 +02:00
|
|
|
|
|
|
|
if d.Get("id").(string) != "54711781-274e-41b2-83c0-17194d0108f7" {
|
|
|
|
t.Fatal("err: 'id' doest not match '54711781-274e-41b2-83c0-17194d0108f7'")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-10 22:20:52 +01:00
|
|
|
func testAccPreCheck(t *testing.T) {
|
|
|
|
if v := os.Getenv("CLOUDSTACK_API_URL"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_API_URL must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_API_KEY"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_API_KEY must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_SECRET_KEY"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_SECRET_KEY must be set for acceptance tests")
|
|
|
|
}
|
2015-06-09 12:38:05 +02:00
|
|
|
if v := os.Getenv("CLOUDSTACK_2ND_NIC_IPADDRESS"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_2ND_NIC_IPADDRESS must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_2ND_NIC_NETWORK"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_2ND_NIC_NETWORK must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_DISK_OFFERING_1"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_DISK_OFFERING_1 must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_DISK_OFFERING_2"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_DISK_OFFERING_2 must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_HYPERVISOR"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_HYPERVISOR must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_SERVICE_OFFERING_1"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_SERVICE_OFFERING_1 must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_SERVICE_OFFERING_2"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_SERVICE_OFFERING_2 must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_NETWORK_1"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_NETWORK_1 must be set for acceptance tests")
|
|
|
|
}
|
2015-12-03 11:10:42 +01:00
|
|
|
if v := os.Getenv("CLOUDSTACK_NETWORK_1_IPADDRESS1"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_NETWORK_1_IPADDRESS1 must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_NETWORK_1_IPADDRESS2"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_NETWORK_1_IPADDRESS2 must be set for acceptance tests")
|
2015-06-09 12:38:05 +02:00
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_NETWORK_2"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_NETWORK_2 must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_NETWORK_2_CIDR"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_NETWORK_2_CIDR must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_NETWORK_2_OFFERING"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_NETWORK_2_OFFERING must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_NETWORK_2_IPADDRESS"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_NETWORK_2_IPADDRESS must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_VPC_CIDR_1"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_VPC_CIDR_1 must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_VPC_CIDR_2"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_VPC_CIDR_2 must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_VPC_OFFERING"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_VPC_OFFERING must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_VPC_NETWORK_CIDR"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_VPC_NETWORK_CIDR must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_VPC_NETWORK_OFFERING"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_VPC_NETWORK_OFFERING must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_PUBLIC_IPADDRESS"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_PUBLIC_IPADDRESS must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_SSH_PUBLIC_KEY"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_SSH_PUBLIC_KEY must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_TEMPLATE"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_TEMPLATE must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_TEMPLATE_FORMAT"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_TEMPLATE_FORMAT must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_TEMPLATE_URL"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_TEMPLATE_URL must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_TEMPLATE_OS_TYPE"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_TEMPLATE_OS_TYPE must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_PROJECT_NAME"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_PROJECT_NAME must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_PROJECT_NETWORK"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_PROJECT_NETWORK must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_ZONE"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_ZONE must be set for acceptance tests")
|
|
|
|
}
|
2016-10-27 21:06:39 +02:00
|
|
|
if v := os.Getenv("CLOUDSTACK_PRIVGW_GATEWAY"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_PRIVGW_GATEWAY must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_PRIVGW_IPADDRESS"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_PRIVGW_IPADDRESS must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_PRIVGW_NETMASK"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_PRIVGW_NETMASK must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_PRIVGW_VLAN"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_PRIVGW_VLAN must be set for acceptance tests")
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CLOUDSTACK_STATIC_ROUTE_CIDR"); v == "" {
|
|
|
|
t.Fatal("CLOUDSTACK_STATIC_ROUTE_CIDR must be set for acceptance tests")
|
|
|
|
}
|
2014-12-10 22:20:52 +01:00
|
|
|
}
|
|
|
|
|
2015-09-06 19:21:55 +02:00
|
|
|
// Name of a valid disk offering
|
2015-06-09 12:38:05 +02:00
|
|
|
var CLOUDSTACK_DISK_OFFERING_1 = os.Getenv("CLOUDSTACK_DISK_OFFERING_1")
|
2015-09-06 19:21:55 +02:00
|
|
|
|
|
|
|
// Name of a disk offering that CLOUDSTACK_DISK_OFFERING_1 can resize to
|
2015-06-09 12:38:05 +02:00
|
|
|
var CLOUDSTACK_DISK_OFFERING_2 = os.Getenv("CLOUDSTACK_DISK_OFFERING_2")
|
2015-09-06 19:21:55 +02:00
|
|
|
|
|
|
|
// Name of a valid service offering
|
2015-06-09 12:38:05 +02:00
|
|
|
var CLOUDSTACK_SERVICE_OFFERING_1 = os.Getenv("CLOUDSTACK_SERVICE_OFFERING_1")
|
2015-09-06 19:21:55 +02:00
|
|
|
|
|
|
|
// Name of a service offering that CLOUDSTACK_SERVICE_OFFERING_1 can resize to
|
2015-06-09 12:38:05 +02:00
|
|
|
var CLOUDSTACK_SERVICE_OFFERING_2 = os.Getenv("CLOUDSTACK_SERVICE_OFFERING_2")
|
2015-09-06 19:21:55 +02:00
|
|
|
|
|
|
|
// Name of a network that already exists
|
2015-06-09 12:38:05 +02:00
|
|
|
var CLOUDSTACK_NETWORK_1 = os.Getenv("CLOUDSTACK_NETWORK_1")
|
2015-09-06 19:21:55 +02:00
|
|
|
|
|
|
|
// A valid IP address in CLOUDSTACK_NETWORK_1
|
2015-12-03 11:10:42 +01:00
|
|
|
var CLOUDSTACK_NETWORK_1_IPADDRESS1 = os.Getenv("CLOUDSTACK_NETWORK_1_IPADDRESS1")
|
|
|
|
|
|
|
|
// A valid IP address in CLOUDSTACK_NETWORK_1
|
|
|
|
var CLOUDSTACK_NETWORK_1_IPADDRESS2 = os.Getenv("CLOUDSTACK_NETWORK_1_IPADDRESS2")
|
2015-09-06 19:21:55 +02:00
|
|
|
|
|
|
|
// Name for a network that will be created
|
2015-06-09 12:38:05 +02:00
|
|
|
var CLOUDSTACK_NETWORK_2 = os.Getenv("CLOUDSTACK_NETWORK_2")
|
2015-09-06 19:21:55 +02:00
|
|
|
|
|
|
|
// Any range
|
2015-06-09 12:38:05 +02:00
|
|
|
var CLOUDSTACK_NETWORK_2_CIDR = os.Getenv("CLOUDSTACK_NETWORK_2_CIDR")
|
2015-09-06 19:21:55 +02:00
|
|
|
|
|
|
|
// Name of an available network offering with specifyvlan=false
|
2015-06-09 12:38:05 +02:00
|
|
|
var CLOUDSTACK_NETWORK_2_OFFERING = os.Getenv("CLOUDSTACK_NETWORK_2_OFFERING")
|
2015-09-06 19:21:55 +02:00
|
|
|
|
|
|
|
// An IP address in CLOUDSTACK_NETWORK_2_CIDR
|
2015-06-09 12:38:05 +02:00
|
|
|
var CLOUDSTACK_NETWORK_2_IPADDRESS = os.Getenv("CLOUDSTACK_NETWORK_2_IPADDRESS")
|
2015-09-06 19:21:55 +02:00
|
|
|
|
2015-09-11 20:56:20 +02:00
|
|
|
// A network that already exists and isn't CLOUDSTACK_NETWORK_1
|
2015-09-06 19:21:55 +02:00
|
|
|
var CLOUDSTACK_2ND_NIC_NETWORK = os.Getenv("CLOUDSTACK_2ND_NIC_NETWORK")
|
|
|
|
|
|
|
|
// An IP address in CLOUDSTACK_2ND_NIC_NETWORK
|
|
|
|
var CLOUDSTACK_2ND_NIC_IPADDRESS = os.Getenv("CLOUDSTACK_2ND_NIC_IPADDRESS")
|
|
|
|
|
|
|
|
// Any range
|
2015-06-09 12:38:05 +02:00
|
|
|
var CLOUDSTACK_VPC_CIDR_1 = os.Getenv("CLOUDSTACK_VPC_CIDR_1")
|
2015-09-06 19:21:55 +02:00
|
|
|
|
|
|
|
// Any range that doesn't overlap to CLOUDSTACK_VPC_CIDR_1, will be VPNed
|
2015-06-09 12:38:05 +02:00
|
|
|
var CLOUDSTACK_VPC_CIDR_2 = os.Getenv("CLOUDSTACK_VPC_CIDR_2")
|
2015-09-06 19:21:55 +02:00
|
|
|
|
|
|
|
// An available VPC offering
|
2015-06-09 12:38:05 +02:00
|
|
|
var CLOUDSTACK_VPC_OFFERING = os.Getenv("CLOUDSTACK_VPC_OFFERING")
|
2015-09-06 19:21:55 +02:00
|
|
|
|
|
|
|
// A sub-range of CLOUDSTACK_VPC_CIDR_1 with same starting point
|
2015-06-09 12:38:05 +02:00
|
|
|
var CLOUDSTACK_VPC_NETWORK_CIDR = os.Getenv("CLOUDSTACK_VPC_NETWORK_CIDR")
|
2015-09-06 19:21:55 +02:00
|
|
|
|
|
|
|
// Name of an available network offering with forvpc=true
|
2015-06-09 12:38:05 +02:00
|
|
|
var CLOUDSTACK_VPC_NETWORK_OFFERING = os.Getenv("CLOUDSTACK_VPC_NETWORK_OFFERING")
|
2015-09-06 19:21:55 +02:00
|
|
|
|
|
|
|
// Path to a public IP that exists for CLOUDSTACK_NETWORK_1
|
2015-06-09 12:38:05 +02:00
|
|
|
var CLOUDSTACK_PUBLIC_IPADDRESS = os.Getenv("CLOUDSTACK_PUBLIC_IPADDRESS")
|
2015-09-06 19:21:55 +02:00
|
|
|
|
|
|
|
// Path to a public key on local disk
|
2015-06-09 12:38:05 +02:00
|
|
|
var CLOUDSTACK_SSH_PUBLIC_KEY = os.Getenv("CLOUDSTACK_SSH_PUBLIC_KEY")
|
2015-09-06 19:21:55 +02:00
|
|
|
|
|
|
|
// Name of a template that exists already for building VMs
|
2015-06-09 12:38:05 +02:00
|
|
|
var CLOUDSTACK_TEMPLATE = os.Getenv("CLOUDSTACK_TEMPLATE")
|
2015-09-06 19:21:55 +02:00
|
|
|
|
|
|
|
// Details of a template that will be added
|
2015-06-09 12:38:05 +02:00
|
|
|
var CLOUDSTACK_TEMPLATE_FORMAT = os.Getenv("CLOUDSTACK_TEMPLATE_FORMAT")
|
2015-09-06 19:21:55 +02:00
|
|
|
var CLOUDSTACK_HYPERVISOR = os.Getenv("CLOUDSTACK_HYPERVISOR")
|
2015-06-09 12:38:05 +02:00
|
|
|
var CLOUDSTACK_TEMPLATE_URL = os.Getenv("CLOUDSTACK_TEMPLATE_URL")
|
|
|
|
var CLOUDSTACK_TEMPLATE_OS_TYPE = os.Getenv("CLOUDSTACK_TEMPLATE_OS_TYPE")
|
2015-09-06 19:21:55 +02:00
|
|
|
|
|
|
|
// Name of a project that exists already
|
2015-06-09 12:38:05 +02:00
|
|
|
var CLOUDSTACK_PROJECT_NAME = os.Getenv("CLOUDSTACK_PROJECT_NAME")
|
2015-09-06 19:21:55 +02:00
|
|
|
|
|
|
|
// Name of a network that exists already in CLOUDSTACK_PROJECT_NAME
|
2015-06-09 12:38:05 +02:00
|
|
|
var CLOUDSTACK_PROJECT_NETWORK = os.Getenv("CLOUDSTACK_PROJECT_NETWORK")
|
2015-09-06 19:21:55 +02:00
|
|
|
|
|
|
|
// Name of a zone that exists already
|
2015-06-09 12:38:05 +02:00
|
|
|
var CLOUDSTACK_ZONE = os.Getenv("CLOUDSTACK_ZONE")
|
2016-10-27 21:06:39 +02:00
|
|
|
|
|
|
|
// Details of the private gateway that will be added to VPC testing this, should be done using ROOT keys
|
|
|
|
var CLOUDSTACK_PRIVGW_GATEWAY = os.Getenv("CLOUDSTACK_PRIVGW_GATEWAY")
|
|
|
|
var CLOUDSTACK_PRIVGW_IPADDRESS = os.Getenv("CLOUDSTACK_PRIVGW_IPADDRESS")
|
|
|
|
var CLOUDSTACK_PRIVGW_NETMASK = os.Getenv("CLOUDSTACK_PRIVGW_NETMASK")
|
|
|
|
var CLOUDSTACK_PRIVGW_VLAN = os.Getenv("CLOUDSTACK_PRIVGW_VLAN")
|
|
|
|
|
|
|
|
// Details of the static route that will be added to private gateway testing this.
|
|
|
|
var CLOUDSTACK_STATIC_ROUTE_CIDR = os.Getenv("CLOUDSTACK_STATIC_ROUTE_CIDR")
|