Skip to content

Commit

Permalink
Allow the cloud config attribute for vm resource to be optional (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelnano committed Oct 15, 2020
1 parent d4d9316 commit da92770
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
5 changes: 4 additions & 1 deletion client/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion xoa/resource_xenorchestra_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
50 changes: 50 additions & 0 deletions xoa/resource_xenorchestra_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit da92770

Please sign in to comment.