Merge pull request #1800 from svanharmelen/b-cloudstack-name-vs-uuid

provider/cloudstack name vs uuid
This commit is contained in:
Sander van Harmelen 2015-05-05 12:37:15 +02:00
commit 4d1b663cdb
25 changed files with 213 additions and 116 deletions

View File

@ -28,6 +28,28 @@ func TestProvider_impl(t *testing.T) {
var _ terraform.ResourceProvider = Provider() var _ terraform.ResourceProvider = Provider()
} }
func testSetValueOnResourceData(t *testing.T) {
d := schema.ResourceData{}
d.Set("id", "name")
setValueOrUUID(&d, "id", "name", "54711781-274e-41b2-83c0-17194d0108f7")
if d.Get("id").(string) != "name" {
t.Fatal("err: 'id' does not match 'name'")
}
}
func testSetUuidOnResourceData(t *testing.T) {
d := schema.ResourceData{}
d.Set("id", "54711781-274e-41b2-83c0-17194d0108f7")
setValueOrUUID(&d, "id", "name", "54711781-274e-41b2-83c0-17194d0108f7")
if d.Get("id").(string) != "54711781-274e-41b2-83c0-17194d0108f7" {
t.Fatal("err: 'id' doest not match '54711781-274e-41b2-83c0-17194d0108f7'")
}
}
func testAccPreCheck(t *testing.T) { func testAccPreCheck(t *testing.T) {
if v := os.Getenv("CLOUDSTACK_API_URL"); v == "" { if v := os.Getenv("CLOUDSTACK_API_URL"); v == "" {
t.Fatal("CLOUDSTACK_API_URL must be set for acceptance tests") t.Fatal("CLOUDSTACK_API_URL must be set for acceptance tests")
@ -41,16 +63,18 @@ func testAccPreCheck(t *testing.T) {
} }
// SET THESE VALUES IN ORDER TO RUN THE ACC TESTS!! // SET THESE VALUES IN ORDER TO RUN THE ACC TESTS!!
var CLOUDSTACK_2ND_NIC_IPADDRESS = ""
var CLOUDSTACK_2ND_NIC_NETWORK = ""
var CLOUDSTACK_DISK_OFFERING_1 = "" var CLOUDSTACK_DISK_OFFERING_1 = ""
var CLOUDSTACK_DISK_OFFERING_2 = "" var CLOUDSTACK_DISK_OFFERING_2 = ""
var CLOUDSTACK_HYPERVISOR = "" var CLOUDSTACK_HYPERVISOR = ""
var CLOUDSTACK_SERVICE_OFFERING_1 = "" var CLOUDSTACK_SERVICE_OFFERING_1 = ""
var CLOUDSTACK_SERVICE_OFFERING_2 = "" var CLOUDSTACK_SERVICE_OFFERING_2 = ""
var CLOUDSTACK_NETWORK_1 = "" var CLOUDSTACK_NETWORK_1 = ""
var CLOUDSTACK_NETWORK_1_CIDR = ""
var CLOUDSTACK_NETWORK_1_OFFERING = ""
var CLOUDSTACK_NETWORK_1_IPADDRESS = "" var CLOUDSTACK_NETWORK_1_IPADDRESS = ""
var CLOUDSTACK_NETWORK_2 = "" var CLOUDSTACK_NETWORK_2 = ""
var CLOUDSTACK_NETWORK_2_CIDR = ""
var CLOUDSTACK_NETWORK_2_OFFERING = ""
var CLOUDSTACK_NETWORK_2_IPADDRESS = "" var CLOUDSTACK_NETWORK_2_IPADDRESS = ""
var CLOUDSTACK_VPC_CIDR_1 = "" var CLOUDSTACK_VPC_CIDR_1 = ""
var CLOUDSTACK_VPC_CIDR_2 = "" var CLOUDSTACK_VPC_CIDR_2 = ""

View File

@ -140,9 +140,10 @@ func resourceCloudStackDiskRead(d *schema.ResourceData, meta interface{}) error
d.Set("name", v.Name) d.Set("name", v.Name)
d.Set("attach", v.Attached != "") // If attached this will contain a timestamp when attached d.Set("attach", v.Attached != "") // If attached this will contain a timestamp when attached
d.Set("disk_offering", v.Diskofferingname)
d.Set("size", int(v.Size/(1024*1024*1024))) // Needed to get GB's again d.Set("size", int(v.Size/(1024*1024*1024))) // Needed to get GB's again
d.Set("zone", v.Zonename)
setValueOrUUID(d, "disk_offering", v.Diskofferingname, v.Diskofferingid)
setValueOrUUID(d, "zone", v.Zonename, v.Zoneid)
if v.Attached != "" { if v.Attached != "" {
// Get the virtual machine details // Get the virtual machine details

View File

@ -184,12 +184,13 @@ func resourceCloudStackInstanceRead(d *schema.ResourceData, meta interface{}) er
// Update the config // Update the config
d.Set("name", vm.Name) d.Set("name", vm.Name)
d.Set("display_name", vm.Displayname) d.Set("display_name", vm.Displayname)
d.Set("service_offering", vm.Serviceofferingname)
d.Set("network", vm.Nic[0].Networkname)
d.Set("ipaddress", vm.Nic[0].Ipaddress) d.Set("ipaddress", vm.Nic[0].Ipaddress)
d.Set("template", vm.Templatename)
d.Set("zone", vm.Zonename) d.Set("zone", vm.Zonename)
setValueOrUUID(d, "network", vm.Nic[0].Networkname, vm.Nic[0].Networkid)
setValueOrUUID(d, "service_offering", vm.Serviceofferingname, vm.Serviceofferingid)
setValueOrUUID(d, "template", vm.Templatename, vm.Templateid)
return nil return nil
} }

View File

@ -149,8 +149,9 @@ func resourceCloudStackNetworkRead(d *schema.ResourceData, meta interface{}) err
d.Set("name", n.Name) d.Set("name", n.Name)
d.Set("display_text", n.Displaytext) d.Set("display_text", n.Displaytext)
d.Set("cidr", n.Cidr) d.Set("cidr", n.Cidr)
d.Set("network_offering", n.Networkofferingname)
d.Set("zone", n.Zonename) setValueOrUUID(d, "network_offering", n.Networkofferingname, n.Networkofferingid)
setValueOrUUID(d, "zone", n.Zonename, n.Zoneid)
return nil return nil
} }

View File

@ -95,7 +95,7 @@ func resourceCloudStackNetworkACLRead(d *schema.ResourceData, meta interface{})
return err return err
} }
d.Set("vpc", v.Name) setValueOrUUID(d, "vpc", v.Name, v.Id)
return nil return nil
} }

View File

@ -227,7 +227,7 @@ resource "cloudstack_vpc" "foobar" {
resource "cloudstack_network_acl" "foo" { resource "cloudstack_network_acl" "foo" {
name = "terraform-acl" name = "terraform-acl"
description = "terraform-acl-text" description = "terraform-acl-text"
vpc = "${cloudstack_vpc.foobar.name}" vpc = "${cloudstack_vpc.foobar.id}"
} }
resource "cloudstack_network_acl_rule" "foo" { resource "cloudstack_network_acl_rule" "foo" {

View File

@ -29,7 +29,7 @@ func TestAccCloudStackNetwork_basic(t *testing.T) {
}) })
} }
func TestAccCloudStackNetwork_vpcACL(t *testing.T) { func TestAccCloudStackNetwork_vpc(t *testing.T) {
var network cloudstack.Network var network cloudstack.Network
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
@ -38,11 +38,11 @@ func TestAccCloudStackNetwork_vpcACL(t *testing.T) {
CheckDestroy: testAccCheckCloudStackNetworkDestroy, CheckDestroy: testAccCheckCloudStackNetworkDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccCloudStackNetwork_vpcACL, Config: testAccCloudStackNetwork_vpc,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckCloudStackNetworkExists( testAccCheckCloudStackNetworkExists(
"cloudstack_network.foo", &network), "cloudstack_network.foo", &network),
testAccCheckCloudStackNetworkVPCACLAttributes(&network), testAccCheckCloudStackNetworkVPCAttributes(&network),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"cloudstack_network.foo", "vpc", "terraform-vpc"), "cloudstack_network.foo", "vpc", "terraform-vpc"),
), ),
@ -92,11 +92,11 @@ func testAccCheckCloudStackNetworkBasicAttributes(
return fmt.Errorf("Bad display name: %s", network.Displaytext) return fmt.Errorf("Bad display name: %s", network.Displaytext)
} }
if network.Cidr != CLOUDSTACK_NETWORK_1_CIDR { if network.Cidr != CLOUDSTACK_NETWORK_2_CIDR {
return fmt.Errorf("Bad service offering: %s", network.Cidr) return fmt.Errorf("Bad service offering: %s", network.Cidr)
} }
if network.Networkofferingname != CLOUDSTACK_NETWORK_1_OFFERING { if network.Networkofferingname != CLOUDSTACK_NETWORK_2_OFFERING {
return fmt.Errorf("Bad template: %s", network.Networkofferingname) return fmt.Errorf("Bad template: %s", network.Networkofferingname)
} }
@ -104,7 +104,7 @@ func testAccCheckCloudStackNetworkBasicAttributes(
} }
} }
func testAccCheckCloudStackNetworkVPCACLAttributes( func testAccCheckCloudStackNetworkVPCAttributes(
network *cloudstack.Network) resource.TestCheckFunc { network *cloudstack.Network) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
@ -117,11 +117,11 @@ func testAccCheckCloudStackNetworkVPCACLAttributes(
} }
if network.Cidr != CLOUDSTACK_VPC_NETWORK_CIDR { if network.Cidr != CLOUDSTACK_VPC_NETWORK_CIDR {
return fmt.Errorf("Bad service offering: %s", network.Cidr) return fmt.Errorf("Bad CIDR: %s", network.Cidr)
} }
if network.Networkofferingname != CLOUDSTACK_VPC_NETWORK_OFFERING { if network.Networkofferingname != CLOUDSTACK_VPC_NETWORK_OFFERING {
return fmt.Errorf("Bad template: %s", network.Networkofferingname) return fmt.Errorf("Bad network offering: %s", network.Networkofferingname)
} }
return nil return nil
@ -160,11 +160,11 @@ resource "cloudstack_network" "foo" {
network_offering = "%s" network_offering = "%s"
zone = "%s" zone = "%s"
}`, }`,
CLOUDSTACK_NETWORK_1_CIDR, CLOUDSTACK_NETWORK_2_CIDR,
CLOUDSTACK_NETWORK_1_OFFERING, CLOUDSTACK_NETWORK_2_OFFERING,
CLOUDSTACK_ZONE) CLOUDSTACK_ZONE)
var testAccCloudStackNetwork_vpcACL = fmt.Sprintf(` var testAccCloudStackNetwork_vpc = fmt.Sprintf(`
resource "cloudstack_vpc" "foobar" { resource "cloudstack_vpc" "foobar" {
name = "terraform-vpc" name = "terraform-vpc"
cidr = "%s" cidr = "%s"
@ -172,18 +172,11 @@ resource "cloudstack_vpc" "foobar" {
zone = "%s" zone = "%s"
} }
resource "cloudstack_network_acl" "foo" {
name = "terraform-acl"
description = "terraform-acl-text"
vpc = "${cloudstack_vpc.foobar.name}"
}
resource "cloudstack_network" "foo" { resource "cloudstack_network" "foo" {
name = "terraform-network" name = "terraform-network"
cidr = "%s" cidr = "%s"
network_offering = "%s" network_offering = "%s"
vpc = "${cloudstack_vpc.foobar.name}" vpc = "${cloudstack_vpc.foobar.name}"
aclid = "${cloudstack_network_acl.foo.id}"
zone = "${cloudstack_vpc.foobar.zone}" zone = "${cloudstack_vpc.foobar.zone}"
}`, }`,
CLOUDSTACK_VPC_CIDR_1, CLOUDSTACK_VPC_CIDR_1,

View File

@ -102,9 +102,9 @@ func resourceCloudStackNICRead(d *schema.ResourceData, meta interface{}) error {
found := false found := false
for _, n := range vm.Nic { for _, n := range vm.Nic {
if n.Id == d.Id() { if n.Id == d.Id() {
d.Set("network", n.Networkname)
d.Set("ipaddress", n.Ipaddress) d.Set("ipaddress", n.Ipaddress)
d.Set("virtual_machine", vm.Name) setValueOrUUID(d, "network", n.Networkname, n.Networkid)
setValueOrUUID(d, "virtual_machine", vm.Name, vm.Id)
found = true found = true
break break
} }

View File

@ -53,7 +53,7 @@ func TestAccCloudStackNIC_update(t *testing.T) {
"cloudstack_instance.foobar", "cloudstack_nic.foo", &nic), "cloudstack_instance.foobar", "cloudstack_nic.foo", &nic),
testAccCheckCloudStackNICIPAddress(&nic), testAccCheckCloudStackNICIPAddress(&nic),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"cloudstack_nic.foo", "ipaddress", CLOUDSTACK_NETWORK_2_IPADDRESS), "cloudstack_nic.foo", "ipaddress", CLOUDSTACK_2ND_NIC_IPADDRESS),
), ),
}, },
}, },
@ -103,7 +103,7 @@ func testAccCheckCloudStackNICAttributes(
nic *cloudstack.Nic) resource.TestCheckFunc { nic *cloudstack.Nic) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
if nic.Networkname != CLOUDSTACK_NETWORK_2 { if nic.Networkname != CLOUDSTACK_2ND_NIC_NETWORK {
return fmt.Errorf("Bad network: %s", nic.Networkname) return fmt.Errorf("Bad network: %s", nic.Networkname)
} }
@ -115,11 +115,11 @@ func testAccCheckCloudStackNICIPAddress(
nic *cloudstack.Nic) resource.TestCheckFunc { nic *cloudstack.Nic) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
if nic.Networkname != CLOUDSTACK_NETWORK_2 { if nic.Networkname != CLOUDSTACK_2ND_NIC_NETWORK {
return fmt.Errorf("Bad network: %s", nic.Networkname) return fmt.Errorf("Bad network: %s", nic.Networkname)
} }
if nic.Ipaddress != CLOUDSTACK_NETWORK_2_IPADDRESS { if nic.Ipaddress != CLOUDSTACK_2ND_NIC_IPADDRESS {
return fmt.Errorf("Bad IP address: %s", nic.Ipaddress) return fmt.Errorf("Bad IP address: %s", nic.Ipaddress)
} }
@ -172,7 +172,7 @@ resource "cloudstack_nic" "foo" {
CLOUDSTACK_NETWORK_1, CLOUDSTACK_NETWORK_1,
CLOUDSTACK_TEMPLATE, CLOUDSTACK_TEMPLATE,
CLOUDSTACK_ZONE, CLOUDSTACK_ZONE,
CLOUDSTACK_NETWORK_2) CLOUDSTACK_2ND_NIC_NETWORK)
var testAccCloudStackNIC_ipaddress = fmt.Sprintf(` var testAccCloudStackNIC_ipaddress = fmt.Sprintf(`
resource "cloudstack_instance" "foobar" { resource "cloudstack_instance" "foobar" {
@ -194,5 +194,5 @@ resource "cloudstack_nic" "foo" {
CLOUDSTACK_NETWORK_1, CLOUDSTACK_NETWORK_1,
CLOUDSTACK_TEMPLATE, CLOUDSTACK_TEMPLATE,
CLOUDSTACK_ZONE, CLOUDSTACK_ZONE,
CLOUDSTACK_NETWORK_2, CLOUDSTACK_2ND_NIC_NETWORK,
CLOUDSTACK_NETWORK_2_IPADDRESS) CLOUDSTACK_2ND_NIC_IPADDRESS)

View File

@ -204,7 +204,6 @@ resource "cloudstack_port_forward" "foo" {
public_port = 8080 public_port = 8080
virtual_machine = "${cloudstack_instance.foobar.name}" virtual_machine = "${cloudstack_instance.foobar.name}"
} }
}`, }`,
CLOUDSTACK_SERVICE_OFFERING_1, CLOUDSTACK_SERVICE_OFFERING_1,
CLOUDSTACK_NETWORK_1, CLOUDSTACK_NETWORK_1,

View File

@ -106,6 +106,10 @@ func resourceCloudStackTemplate() *schema.Resource {
func resourceCloudStackTemplateCreate(d *schema.ResourceData, meta interface{}) error { func resourceCloudStackTemplateCreate(d *schema.ResourceData, meta interface{}) error {
cs := meta.(*cloudstack.CloudStackClient) cs := meta.(*cloudstack.CloudStackClient)
if err := verifyTemplateParams(d); err != nil {
return err
}
name := d.Get("name").(string) name := d.Get("name").(string)
// Compute/set the display text // Compute/set the display text
@ -169,6 +173,10 @@ func resourceCloudStackTemplateCreate(d *schema.ResourceData, meta interface{})
currentTime := time.Now().Unix() currentTime := time.Now().Unix()
timeout := int64(d.Get("is_ready_timeout").(int)) timeout := int64(d.Get("is_ready_timeout").(int))
for { for {
// Start with the sleep so the register action has a few seconds
// to process the registration correctly. Without this wait
time.Sleep(10 * time.Second)
err := resourceCloudStackTemplateRead(d, meta) err := resourceCloudStackTemplateRead(d, meta)
if err != nil { if err != nil {
return err return err
@ -181,7 +189,6 @@ func resourceCloudStackTemplateCreate(d *schema.ResourceData, meta interface{})
if time.Now().Unix()-currentTime > timeout { if time.Now().Unix()-currentTime > timeout {
return fmt.Errorf("Timeout while waiting for template to become ready") return fmt.Errorf("Timeout while waiting for template to become ready")
} }
time.Sleep(5 * time.Second)
} }
} }
@ -205,8 +212,6 @@ func resourceCloudStackTemplateRead(d *schema.ResourceData, meta interface{}) er
d.Set("display_text", t.Displaytext) d.Set("display_text", t.Displaytext)
d.Set("format", t.Format) d.Set("format", t.Format)
d.Set("hypervisor", t.Hypervisor) d.Set("hypervisor", t.Hypervisor)
d.Set("os_type", t.Ostypename)
d.Set("zone", t.Zonename)
d.Set("is_dynamically_scalable", t.Isdynamicallyscalable) d.Set("is_dynamically_scalable", t.Isdynamicallyscalable)
d.Set("is_extractable", t.Isextractable) d.Set("is_extractable", t.Isextractable)
d.Set("is_featured", t.Isfeatured) d.Set("is_featured", t.Isfeatured)
@ -214,6 +219,9 @@ func resourceCloudStackTemplateRead(d *schema.ResourceData, meta interface{}) er
d.Set("password_enabled", t.Passwordenabled) d.Set("password_enabled", t.Passwordenabled)
d.Set("is_ready", t.Isready) d.Set("is_ready", t.Isready)
setValueOrUUID(d, "os_type", t.Ostypename, t.Ostypeid)
setValueOrUUID(d, "zone", t.Zonename, t.Zoneid)
return nil return nil
} }
@ -281,3 +289,13 @@ func resourceCloudStackTemplateDelete(d *schema.ResourceData, meta interface{})
} }
return nil return nil
} }
func verifyTemplateParams(d *schema.ResourceData) error {
format := d.Get("format").(string)
if format != "QCOW2" && format != "RAW" && format != "VHD" && format != "VMDK" {
return fmt.Errorf(
"%s is not a valid format. Valid options are 'QCOW2', 'RAW', 'VHD' and 'VMDK'", format)
}
return nil
}

View File

@ -105,7 +105,8 @@ func resourceCloudStackVPCRead(d *schema.ResourceData, meta interface{}) error {
d.Set("name", v.Name) d.Set("name", v.Name)
d.Set("display_text", v.Displaytext) d.Set("display_text", v.Displaytext)
d.Set("cidr", v.Cidr) d.Set("cidr", v.Cidr)
d.Set("zone", v.Zonename)
setValueOrUUID(d, "zone", v.Zonename, v.Zoneid)
// Get the VPC offering details // Get the VPC offering details
o, _, err := cs.VPC.GetVPCOfferingByID(v.Vpcofferingid) o, _, err := cs.VPC.GetVPCOfferingByID(v.Vpcofferingid)
@ -113,7 +114,7 @@ func resourceCloudStackVPCRead(d *schema.ResourceData, meta interface{}) error {
return err return err
} }
d.Set("vpc_offering", o.Name) setValueOrUUID(d, "vpc_offering", o.Name, v.Vpcofferingid)
return nil return nil
} }

View File

@ -67,7 +67,7 @@ func TestAccCloudStackVPNCustomerGateway_update(t *testing.T) {
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckCloudStackVPNCustomerGatewayExists( testAccCheckCloudStackVPNCustomerGatewayExists(
"cloudstack_vpn_customer_gateway.foo", &vpnCustomerGateway), "cloudstack_vpn_customer_gateway.foo", &vpnCustomerGateway),
testAccCheckCloudStackVPNCustomerGatewayAttributes(&vpnCustomerGateway), testAccCheckCloudStackVPNCustomerGatewayUpdatedAttributes(&vpnCustomerGateway),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"cloudstack_vpn_customer_gateway.foo", "name", "terraform-foo-bar"), "cloudstack_vpn_customer_gateway.foo", "name", "terraform-foo-bar"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -131,6 +131,26 @@ func testAccCheckCloudStackVPNCustomerGatewayAttributes(
} }
} }
func testAccCheckCloudStackVPNCustomerGatewayUpdatedAttributes(
vpnCustomerGateway *cloudstack.VpnCustomerGateway) resource.TestCheckFunc {
return func(s *terraform.State) error {
if vpnCustomerGateway.Esppolicy != "3des-md5" {
return fmt.Errorf("Bad ESP policy: %s", vpnCustomerGateway.Esppolicy)
}
if vpnCustomerGateway.Ikepolicy != "3des-md5" {
return fmt.Errorf("Bad IKE policy: %s", vpnCustomerGateway.Ikepolicy)
}
if vpnCustomerGateway.Ipsecpsk != "terraform" {
return fmt.Errorf("Bad IPSEC pre-shared key: %s", vpnCustomerGateway.Ipsecpsk)
}
return nil
}
}
func testAccCheckCloudStackVPNCustomerGatewayDestroy(s *terraform.State) error { func testAccCheckCloudStackVPNCustomerGatewayDestroy(s *terraform.State) error {
cs := testAccProvider.Meta().(*cloudstack.CloudStackClient) cs := testAccProvider.Meta().(*cloudstack.CloudStackClient)
@ -204,6 +224,28 @@ resource "cloudstack_vpn_customer_gateway" "bar" {
CLOUDSTACK_ZONE) CLOUDSTACK_ZONE)
var testAccCloudStackVPNCustomerGateway_update = fmt.Sprintf(` var testAccCloudStackVPNCustomerGateway_update = fmt.Sprintf(`
resource "cloudstack_vpc" "foo" {
name = "terraform-vpc-foo"
cidr = "%s"
vpc_offering = "%s"
zone = "%s"
}
resource "cloudstack_vpc" "bar" {
name = "terraform-vpc-bar"
cidr = "%s"
vpc_offering = "%s"
zone = "%s"
}
resource "cloudstack_vpn_gateway" "foo" {
vpc = "${cloudstack_vpc.foo.name}"
}
resource "cloudstack_vpn_gateway" "bar" {
vpc = "${cloudstack_vpc.bar.name}"
}
resource "cloudstack_vpn_customer_gateway" "foo" { resource "cloudstack_vpn_customer_gateway" "foo" {
name = "terraform-foo-bar" name = "terraform-foo-bar"
cidr = "${cloudstack_vpc.foo.cidr}" cidr = "${cloudstack_vpc.foo.cidr}"
@ -220,4 +262,10 @@ resource "cloudstack_vpn_customer_gateway" "bar" {
gateway = "${cloudstack_vpn_gateway.bar.public_ip}" gateway = "${cloudstack_vpn_gateway.bar.public_ip}"
ike_policy = "3des-md5" ike_policy = "3des-md5"
ipsec_psk = "terraform" ipsec_psk = "terraform"
}`) }`,
CLOUDSTACK_VPC_CIDR_1,
CLOUDSTACK_VPC_OFFERING,
CLOUDSTACK_ZONE,
CLOUDSTACK_VPC_CIDR_2,
CLOUDSTACK_VPC_OFFERING,
CLOUDSTACK_ZONE)

View File

@ -69,6 +69,8 @@ func resourceCloudStackVPNGatewayRead(d *schema.ResourceData, meta interface{})
return err return err
} }
setValueOrUUID(d, "vpc", d.Get("vpc").(string), v.Vpcid)
d.Set("public_ip", v.Publicip) d.Set("public_ip", v.Publicip)
return nil return nil

View File

@ -5,6 +5,7 @@ import (
"log" "log"
"regexp" "regexp"
"github.com/hashicorp/terraform/helper/schema"
"github.com/xanzy/go-cloudstack/cloudstack" "github.com/xanzy/go-cloudstack/cloudstack"
) )
@ -18,6 +19,14 @@ func (e *retrieveError) Error() error {
return fmt.Errorf("Error retrieving UUID of %s %s: %s", e.name, e.value, e.err) return fmt.Errorf("Error retrieving UUID of %s %s: %s", e.name, e.value, e.err)
} }
func setValueOrUUID(d *schema.ResourceData, key string, value string, uuid string) {
if isUUID(d.Get(key).(string)) {
d.Set(key, uuid)
} else {
d.Set(key, value)
}
}
func retrieveUUID(cs *cloudstack.CloudStackClient, name, value string) (uuid string, e *retrieveError) { func retrieveUUID(cs *cloudstack.CloudStackClient, name, value string) (uuid string, e *retrieveError) {
// If the supplied value isn't a UUID, try to retrieve the UUID ourselves // If the supplied value isn't a UUID, try to retrieve the UUID ourselves
if isUUID(value) { if isUUID(value) {

View File

@ -36,8 +36,8 @@ The following arguments are supported:
* `device` - (Optional) The device to map the disk volume to within the guest OS. * `device` - (Optional) The device to map the disk volume to within the guest OS.
* `disk_offering` - (Required) The name of the disk offering to use for this * `disk_offering` - (Required) The name or ID of the disk offering to use for
disk volume. this disk volume.
* `size` - (Optional) The size of the disk volume in gigabytes. * `size` - (Optional) The size of the disk volume in gigabytes.
@ -47,7 +47,7 @@ The following arguments are supported:
* `virtual_machine` - (Optional) The name of the virtual machine to which you * `virtual_machine` - (Optional) The name of the virtual machine to which you
want to attach the disk volume. want to attach the disk volume.
* `zone` - (Required) The name of the zone where this disk volume will be available. * `zone` - (Required) The name or ID of the zone where this disk volume will be available.
Changing this forces a new resource to be created. Changing this forces a new resource to be created.
## Attributes Reference ## Attributes Reference

View File

@ -32,15 +32,15 @@ The following arguments are supported:
* `display_name` - (Optional) The display name of the instance. * `display_name` - (Optional) The display name of the instance.
* `service_offering` - (Required) The service offering used for this instance. * `service_offering` - (Required) The name or ID of the service offering used for this instance.
* `network` - (Optional) The name of the network to connect this instance to. * `network` - (Optional) The name or ID of the network to connect this instance to.
Changing this forces a new resource to be created. Changing this forces a new resource to be created.
* `ipaddress` - (Optional) The IP address to assign to this instance. Changing * `ipaddress` - (Optional) The IP address to assign to this instance. Changing
this forces a new resource to be created. this forces a new resource to be created.
* `template` - (Required) The name of the template used for this instance. * `template` - (Required) The name or ID of the template used for this instance.
Changing this forces a new resource to be created. Changing this forces a new resource to be created.
* `zone` - (Required) The name of the zone where this instance will be created. * `zone` - (Required) The name of the zone where this instance will be created.

View File

@ -34,8 +34,8 @@ The following arguments are supported:
* `cidr` - (Required) The CIDR block for the network. Changing this forces a new * `cidr` - (Required) The CIDR block for the network. Changing this forces a new
resource to be created. resource to be created.
* `network_offering` - (Required) The name of the network offering to use for * `network_offering` - (Required) The name or ID of the network offering to use
this network. for this network.
* `vpc` - (Optional) The name of the VPC to create this network for. Changing * `vpc` - (Optional) The name of the VPC to create this network for. Changing
this forces a new resource to be created. this forces a new resource to be created.
@ -43,7 +43,7 @@ The following arguments are supported:
* `aclid` - (Optional) The ID of a network ACL that should be attached to the * `aclid` - (Optional) The ID of a network ACL that should be attached to the
network. Changing this forces a new resource to be created. network. Changing this forces a new resource to be created.
* `zone` - (Required) The name of the zone where this disk volume will be * `zone` - (Required) The name or ID of the zone where this disk volume will be
available. Changing this forces a new resource to be created. available. Changing this forces a new resource to be created.
## Attributes Reference ## Attributes Reference

View File

@ -27,8 +27,8 @@ The following arguments are supported:
to be created. to be created.
* `description` - (Optional) The description of the ACL. Changing this forces a * `description` - (Optional) The description of the ACL. Changing this forces a
new resource to be created. new resource to be created.
* `vpc` - (Required) The name of the VPC to create this ACL for. Changing this * `vpc` - (Required) The name or ID of the VPC to create this ACL for. Changing
forces a new resource to be created. this forces a new resource to be created.
## Attributes Reference ## Attributes Reference

View File

@ -26,14 +26,14 @@ resource "cloudstack_nic" "test" {
The following arguments are supported: The following arguments are supported:
* `network` - (Required) The name of the network to plug the NIC into. Changing * `network` - (Required) The name or ID of the network to plug the NIC into. Changing
this forces a new resource to be created. this forces a new resource to be created.
* `ipaddress` - (Optional) The IP address to assign to the NIC. Changing this * `ipaddress` - (Optional) The IP address to assign to the NIC. Changing this
forces a new resource to be created. forces a new resource to be created.
* `virtual_machine` - (Required) The name of the virtual machine to which to * `virtual_machine` - (Required) The name or ID of the virtual machine to which
attach the NIC. Changing this forces a new resource to be created. to attach the NIC. Changing this forces a new resource to be created.
## Attributes Reference ## Attributes Reference

View File

@ -43,7 +43,7 @@ The following arguments are supported:
* `url` - (Required) The URL of where the template is hosted. Changing this * `url` - (Required) The URL of where the template is hosted. Changing this
forces a new resource to be created. forces a new resource to be created.
* `zone` - (Required) The name of the zone where this template will be created. * `zone` - (Required) The name or ID of the zone where this template will be created.
Changing this forces a new resource to be created. Changing this forces a new resource to be created.
* `is_dynamically_scalable` - (Optional) Set to indicate if the template contains * `is_dynamically_scalable` - (Optional) Set to indicate if the template contains

View File

@ -34,10 +34,10 @@ The following arguments are supported:
* `cidr` - (Required) The CIDR block for the VPC. Changing this forces a new * `cidr` - (Required) The CIDR block for the VPC. Changing this forces a new
resource to be created. resource to be created.
* `vpc_offering` - (Required) The name of the VPC offering to use for this VPC. * `vpc_offering` - (Required) The name or ID of the VPC offering to use for this VPC.
Changing this forces a new resource to be created. Changing this forces a new resource to be created.
* `zone` - (Required) The name of the zone where this disk volume will be * `zone` - (Required) The name or ID of the zone where this disk volume will be
available. Changing this forces a new resource to be created. available. Changing this forces a new resource to be created.
## Attributes Reference ## Attributes Reference

View File

@ -24,7 +24,7 @@ resource "cloudstack_vpn_gateway" "default" {
The following arguments are supported: The following arguments are supported:
* `vpc` - (Required) The name of the VPC for which to create the VPN Gateway. * `vpc` - (Required) The name or ID of the VPC for which to create the VPN Gateway.
Changing this forces a new resource to be created. Changing this forces a new resource to be created.
## Attributes Reference ## Attributes Reference