diff --git a/client/vm.go b/client/vm.go index f7089989..69dc7420 100644 --- a/client/vm.go +++ b/client/vm.go @@ -83,7 +83,6 @@ func (c *Client) CreateVm(name_label, name_description, template, cloudConfig, r "name_label": name_label, "name_description": name_description, "template": template, - "cloudConfig": cloudConfig, "coreOs": false, "cpuCap": nil, "cpuWeight": nil, @@ -93,6 +92,10 @@ func (c *Client) CreateVm(name_label, name_description, template, cloudConfig, r "VIFs": vifs, } + if cloudConfig != "" { + params["cloudConfig"] = cloudConfig + } + if resourceSet != "" { params["resourceSet"] = resourceSet } diff --git a/docs/resources/vm.md b/docs/resources/vm.md index 789e23f1..ee56cacc 100644 --- a/docs/resources/vm.md +++ b/docs/resources/vm.md @@ -49,7 +49,7 @@ resource "xenorchestra_vm" "bar" { * name_label - (Required) The name of VM. * name_description - (Optional) The description of the VM. * template - (Required) The ID of the VM template to create the new VM from. -* cloud_config - (Required) The ID of the cloud config to use +* cloud_config - (Optional) The content of the cloud config to use * cpus - (Required) The number of CPUs the VM will have. * memory_max - (Required) The amount of memory in bytes the VM will have. * high_availabililty - (Optional) The restart priority for the VM. Possible values are `best-effort`, `restart` and empty string (no restarts on failure. Defaults to empty string. diff --git a/xoa/resource_xenorchestra_vm.go b/xoa/resource_xenorchestra_vm.go index 04768948..2b90880f 100644 --- a/xoa/resource_xenorchestra_vm.go +++ b/xoa/resource_xenorchestra_vm.go @@ -84,7 +84,7 @@ func resourceRecord() *schema.Resource { }, "cloud_config": &schema.Schema{ Type: schema.TypeString, - Required: true, + Optional: true, }, "core_os": &schema.Schema{ Type: schema.TypeBool, diff --git a/xoa/resource_xenorchestra_vm_test.go b/xoa/resource_xenorchestra_vm_test.go index 42e113a2..2434a68a 100644 --- a/xoa/resource_xenorchestra_vm_test.go +++ b/xoa/resource_xenorchestra_vm_test.go @@ -29,6 +29,24 @@ func TestAccXenorchestraVm_create(t *testing.T) { }) } +func TestAccXenorchestraVm_createWithoutCloudConfig(t *testing.T) { + resourceName := "xenorchestra_vm.bar" + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckXenorchestraVmDestroy, + Steps: []resource.TestStep{ + { + Config: testAccVmWithoutCloudInitConfig(), + Check: resource.ComposeAggregateTestCheckFunc( + testAccVmExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "id"), + internal.TestCheckTypeSetElemAttrPair(resourceName, "network.*.*", "data.xenorchestra_network.network", "id")), + }, + }, + }) +} + func TestAccXenorchestraVm_createWithMacAddress(t *testing.T) { resourceName := "xenorchestra_vm.bar" macAddress := "00:0a:83:b1:c0:83" @@ -268,6 +286,38 @@ func testAccVmExists(resourceName string) resource.TestCheckFunc { } } +func testAccVmWithoutCloudInitConfig() string { + return fmt.Sprintf(` +data "xenorchestra_template" "template" { + name_label = "%s" + pool_id = "%s" +} + +data "xenorchestra_network" "network" { + // TODO: Replace this with a better solution + name_label = "Pool-wide network associated with eth0" + pool_id = "%[2]s" +} + +resource "xenorchestra_vm" "bar" { + memory_max = 256000000 + cpus = 1 + name_label = "Terraform testing" + name_description = "description" + template = "${data.xenorchestra_template.template.id}" + network { + network_id = "${data.xenorchestra_network.network.id}" + } + + disk { + sr_id = "%s" + name_label = "xo provider root" + size = 10000000000 + } +} +`, accTemplateName, accTestPool.Id, accDefaultSr.Id) +} + func testAccVmConfig() string { return testAccCloudConfigConfig("vm-template", "template") + fmt.Sprintf(` data "xenorchestra_template" "template" {