@@ -100,8 +100,35 @@ func TestAccResourceVSphereVirtualMachine_hardwareVersionBare(t *testing.T) {
100
100
})
101
101
}
102
102
103
+ func TestAccResourceVSphereVirtualMachine_fromSparseVmdk (t * testing.T ) {
104
+ t .Skipf ("requires an existing 2gbsparse vmdk" )
105
+ // to run this test you need to create a vmdk on the target datastore
106
+ // 1. ssh to an ESXi host with connection to the datastore
107
+ // 2. create an empty folder on the datastore and `cd` inside (e.g. /vmfs/volumes/67fe111f-489f3741-b381-02007873e8d0/sparsedisks)
108
+ // 3. create a regular sparse vmdk - vmkfstools -c 2g -d sesparse sparse.vmdk
109
+ // 4. create a 2gbsparse vmdk from the regular one - vmkfstools -i sparse.vmdk sparse2.vmdk -d 2gbsparse
110
+ // the test is pre-configured to look for a disk at [acc-test-nfs] sparsedisks/sparse2.vmdk. change if necessary
111
+ resource .Test (t , resource.TestCase {
112
+ PreCheck : func () {
113
+ RunSweepers ()
114
+ testAccPreCheck (t )
115
+ },
116
+ Providers : testAccProviders ,
117
+ CheckDestroy : testAccResourceVSphereVirtualMachineCheckExists (false ),
118
+ Steps : []resource.TestStep {
119
+ {
120
+ Config : testAccResourceVSphereVirtualMachineConfigFromSparseVmdk (),
121
+ Check : resource .ComposeTestCheckFunc (
122
+ testAccResourceVSphereVirtualMachineCheckExists (true ),
123
+ resource .TestMatchResourceAttr ("vsphere_virtual_machine.vm" , "moid" , regexp .MustCompile ("^vm-" )),
124
+ ),
125
+ },
126
+ },
127
+ })
128
+ }
129
+
103
130
func TestAccResourceVSphereVirtualMachine_vtpmCreate (t * testing.T ) {
104
- t .Skipf ("Requires key management server to run" )
131
+ t .Skipf ("requires key management server to run" )
105
132
resource .Test (t , resource.TestCase {
106
133
PreCheck : func () {
107
134
RunSweepers ()
@@ -122,7 +149,7 @@ func TestAccResourceVSphereVirtualMachine_vtpmCreate(t *testing.T) {
122
149
}
123
150
124
151
func TestAccResourceVSphereVirtualMachine_vtpmAdd (t * testing.T ) {
125
- t .Skipf ("Requires key management server to run" )
152
+ t .Skipf ("requires key management server to run" )
126
153
resource .Test (t , resource.TestCase {
127
154
PreCheck : func () {
128
155
RunSweepers ()
@@ -150,7 +177,7 @@ func TestAccResourceVSphereVirtualMachine_vtpmAdd(t *testing.T) {
150
177
}
151
178
152
179
func TestAccResourceVSphereVirtualMachine_vtpmRemove (t * testing.T ) {
153
- t .Skipf ("Requires key management server to run" )
180
+ t .Skipf ("requires key management server to run" )
154
181
resource .Test (t , resource.TestCase {
155
182
PreCheck : func () {
156
183
RunSweepers ()
@@ -178,7 +205,7 @@ func TestAccResourceVSphereVirtualMachine_vtpmRemove(t *testing.T) {
178
205
}
179
206
180
207
func TestAccResourceVSphereVirtualMachine_vtpmClone (t * testing.T ) {
181
- t .Skipf ("Requires key management server to run" )
208
+ t .Skipf ("requires key management server to run" )
182
209
resource .Test (t , resource.TestCase {
183
210
PreCheck : func () {
184
211
RunSweepers ()
@@ -4145,6 +4172,48 @@ resource "vsphere_virtual_machine" "vm" {
4145
4172
)
4146
4173
}
4147
4174
4175
+ func testAccResourceVSphereVirtualMachineConfigFromSparseVmdk () string {
4176
+ return fmt .Sprintf (`
4177
+
4178
+
4179
+ %s // Mix and match config
4180
+
4181
+ resource "vsphere_virtual_machine" "vm" {
4182
+ name = "testacc-test"
4183
+ resource_pool_id = vsphere_resource_pool.pool1.id
4184
+ datastore_id = data.vsphere_datastore.rootds1.id
4185
+
4186
+ num_cpus = 2
4187
+ memory = 2048
4188
+ guest_id = "other3xLinuxGuest"
4189
+ firmware = "efi"
4190
+
4191
+ wait_for_guest_net_timeout = 0
4192
+
4193
+ cdrom {
4194
+ client_device = true
4195
+ }
4196
+
4197
+ network_interface {
4198
+ network_id = data.vsphere_network.network1.id
4199
+ }
4200
+
4201
+ disk {
4202
+ label = "disk0"
4203
+ attach = true
4204
+ datastore_id = data.vsphere_datastore.rootds1.id
4205
+ path = "[acc-test-nfs] sparsedisks/sparse2.vmdk"
4206
+ controller_type = "ide"
4207
+ unit_number = 1
4208
+ io_reservation = 1
4209
+ }
4210
+ }
4211
+ ` ,
4212
+
4213
+ testAccResourceVSphereVirtualMachineConfigBase (),
4214
+ )
4215
+ }
4216
+
4148
4217
func testAccResourceVSphereVirtualMachineConfigSharedSCSIBus () string {
4149
4218
return fmt .Sprintf (`
4150
4219
0 commit comments