-
Notifications
You must be signed in to change notification settings - Fork 453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
r/virtual_machine: add vApp properties #303
Changes from 4 commits
fe8c313
812d2d3
53925ef
050919e
6cc04ab
3e1d394
8017ae4
817a852
c27efe4
31881de
4cb7e4f
032d70c
dfb9168
3170e96
de8cf26
4cc701b
eb013b2
c3fd7da
c309d3c
646758c
b19e6d3
ab73496
ca780b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -836,6 +836,45 @@ func TestAccResourceVSphereVirtualMachine(t *testing.T) { | |
}, | ||
}, | ||
}, | ||
{ | ||
"clone with vapp properties", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some thoughts on testing this while enforcing present keys only - we might need to test this against a CoreOS template or something else well known, and work on setting well-known cloud-config keys. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've started testing against the CoreOS OVA instead of against a custom-built template. |
||
resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheck(tp) | ||
testAccResourceVSphereVirtualMachinePreCheck(tp) | ||
}, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccResourceVSphereVirtualMachineCheckExists(false), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccResourceVSphereVirtualMachineConfigCloneWithVAppProperties(), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccResourceVSphereVirtualMachineCheckExists(true), | ||
testAccResourceVSphereVirtualMachineCheckVAppConfigKey("example_key", "example value"), | ||
testAccResourceVSphereVirtualMachineCheckVAppConfigKey("another_key", ""), | ||
), | ||
}, | ||
{ | ||
Config: testAccResourceVSphereVirtualMachineConfigCloneUpdatingVAppProperties(), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccResourceVSphereVirtualMachineCheckExists(true), | ||
testAccResourceVSphereVirtualMachineCheckVAppConfigKey("another_key", "another value"), | ||
testAccResourceVSphereVirtualMachineCheckVAppConfigKey("example_key", "new value"), | ||
), | ||
}, | ||
// This test is commented out because removing a value does not work with the current implementation. | ||
// This seems like it may be a limitation of the vSphere API or or client implementation. | ||
// { | ||
// Config: testAccResourceVSphereVirtualMachineConfigCloneWithVAppProperties(), | ||
// Check: resource.ComposeTestCheckFunc( | ||
// testAccResourceVSphereVirtualMachineCheckExists(true), | ||
// testAccResourceVSphereVirtualMachineCheckVAppConfigKey("example_key", "example value"), | ||
// testAccResourceVSphereVirtualMachineCheckVAppConfigKey("another_key", ""), | ||
// ), | ||
// }, | ||
}, | ||
}, | ||
}, | ||
{ | ||
"cpu hot add", | ||
resource.TestCase{ | ||
|
@@ -1285,6 +1324,22 @@ func testAccResourceVSphereVirtualMachineCheckExists(expected bool) resource.Tes | |
} | ||
} | ||
|
||
func testAccResourceVSphereVirtualMachineCheckVAppConfigKey(key, value string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
props, err := testGetVirtualMachineProperties(s, "vm") | ||
if err != nil { | ||
return err | ||
} | ||
actual := props.Config.VAppConfig.GetVmConfigInfo().Property | ||
for _, prop := range actual { | ||
if prop.Id == key && prop.Value != value { | ||
return fmt.Errorf("expected vAppConfig property %s to have value %s, got %s", key, value, prop.Value) | ||
} | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
// testAccResourceVSphereVirtualMachineCheckPowerState is a check to check for | ||
// a VirtualMachine's power state. | ||
func testAccResourceVSphereVirtualMachineCheckPowerState(expected types.VirtualMachinePowerState) resource.TestCheckFunc { | ||
|
@@ -5730,3 +5785,172 @@ resource "vsphere_virtual_machine" "vm" { | |
os.Getenv("VSPHERE_USE_LINKED_CLONE"), | ||
) | ||
} | ||
|
||
func testAccResourceVSphereVirtualMachineConfigCloneWithVAppProperties() string { | ||
return fmt.Sprintf(` | ||
variable "datacenter" { | ||
default = "%s" | ||
} | ||
|
||
variable "resource_pool" { | ||
default = "%s" | ||
} | ||
|
||
variable "network_label" { | ||
default = "%s" | ||
} | ||
|
||
variable "datastore" { | ||
default = "%s" | ||
} | ||
|
||
variable "template" { | ||
default = "%s" | ||
} | ||
|
||
data "vsphere_datacenter" "dc" { | ||
name = "${var.datacenter}" | ||
} | ||
|
||
data "vsphere_datastore" "datastore" { | ||
name = "${var.datastore}" | ||
datacenter_id = "${data.vsphere_datacenter.dc.id}" | ||
} | ||
|
||
data "vsphere_resource_pool" "pool" { | ||
name = "${var.resource_pool}" | ||
datacenter_id = "${data.vsphere_datacenter.dc.id}" | ||
} | ||
|
||
data "vsphere_network" "network" { | ||
name = "${var.network_label}" | ||
datacenter_id = "${data.vsphere_datacenter.dc.id}" | ||
} | ||
|
||
data "vsphere_virtual_machine" "template" { | ||
name = "${var.template}" | ||
datacenter_id = "${data.vsphere_datacenter.dc.id}" | ||
} | ||
|
||
resource "vsphere_virtual_machine" "vm" { | ||
name = "terraform-test" | ||
resource_pool_id = "${data.vsphere_resource_pool.pool.id}" | ||
datastore_id = "${data.vsphere_datastore.datastore.id}" | ||
|
||
num_cpus = 2 | ||
memory = 2048 | ||
guest_id = "${data.vsphere_virtual_machine.template.guest_id}" | ||
|
||
network_interface { | ||
network_id = "${data.vsphere_network.network.id}" | ||
adapter_type = "${data.vsphere_virtual_machine.template.network_interface_types[0]}" | ||
} | ||
|
||
disk { | ||
name = "terraform-test.vmdk" | ||
size = "${data.vsphere_virtual_machine.template.disks.0.size}" | ||
} | ||
|
||
vapp { | ||
properties { | ||
example_key = "example value" | ||
} | ||
} | ||
|
||
clone { | ||
template_uuid = "${data.vsphere_virtual_machine.template.id}" | ||
} | ||
} | ||
`, | ||
os.Getenv("VSPHERE_DATACENTER"), | ||
os.Getenv("VSPHERE_RESOURCE_POOL"), | ||
os.Getenv("VSPHERE_NETWORK_LABEL"), | ||
os.Getenv("VSPHERE_DATASTORE"), | ||
os.Getenv("VSPHERE_TEMPLATE"), | ||
) | ||
} | ||
|
||
func testAccResourceVSphereVirtualMachineConfigCloneUpdatingVAppProperties() string { | ||
return fmt.Sprintf(` | ||
variable "datacenter" { | ||
default = "%s" | ||
} | ||
|
||
variable "resource_pool" { | ||
default = "%s" | ||
} | ||
|
||
variable "network_label" { | ||
default = "%s" | ||
} | ||
|
||
variable "datastore" { | ||
default = "%s" | ||
} | ||
|
||
variable "template" { | ||
default = "%s" | ||
} | ||
|
||
data "vsphere_datacenter" "dc" { | ||
name = "${var.datacenter}" | ||
} | ||
|
||
data "vsphere_datastore" "datastore" { | ||
name = "${var.datastore}" | ||
datacenter_id = "${data.vsphere_datacenter.dc.id}" | ||
} | ||
|
||
data "vsphere_resource_pool" "pool" { | ||
name = "${var.resource_pool}" | ||
datacenter_id = "${data.vsphere_datacenter.dc.id}" | ||
} | ||
|
||
data "vsphere_network" "network" { | ||
name = "${var.network_label}" | ||
datacenter_id = "${data.vsphere_datacenter.dc.id}" | ||
} | ||
|
||
data "vsphere_virtual_machine" "template" { | ||
name = "${var.template}" | ||
datacenter_id = "${data.vsphere_datacenter.dc.id}" | ||
} | ||
|
||
resource "vsphere_virtual_machine" "vm" { | ||
name = "terraform-test" | ||
resource_pool_id = "${data.vsphere_resource_pool.pool.id}" | ||
datastore_id = "${data.vsphere_datastore.datastore.id}" | ||
|
||
num_cpus = 2 | ||
memory = 2048 | ||
guest_id = "${data.vsphere_virtual_machine.template.guest_id}" | ||
|
||
network_interface { | ||
network_id = "${data.vsphere_network.network.id}" | ||
adapter_type = "${data.vsphere_virtual_machine.template.network_interface_types[0]}" | ||
} | ||
|
||
disk { | ||
name = "terraform-test.vmdk" | ||
size = "${data.vsphere_virtual_machine.template.disks.0.size}" | ||
} | ||
|
||
vapp { | ||
properties { | ||
another_key = "another value" | ||
example_key = "new value" | ||
} | ||
} | ||
|
||
clone { | ||
template_uuid = "${data.vsphere_virtual_machine.template.id}" | ||
} | ||
} | ||
`, | ||
os.Getenv("VSPHERE_DATACENTER"), | ||
os.Getenv("VSPHERE_RESOURCE_POOL"), | ||
os.Getenv("VSPHERE_NETWORK_LABEL"), | ||
os.Getenv("VSPHERE_DATASTORE"), | ||
os.Getenv("VSPHERE_TEMPLATE"), | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could probably just put this directly into
schemaVirtualMachineConfigSpec
as it's so small, along with thevapp
key. I'm almost tempted to also just say we flatten it and name itvapp_properties
, but we might need to add more keys at a later time.