user312307
user312307

Reputation: 140

How to add additional disks to vmware server using terraform after it is provisioned

I have found this online but getting error when I add disk block.

resource "vsphere_virtual_disk" "disk_2" {
  vmdk_path = "${var.name}.2.vmdk"
  size = 112
  datacenter = "${var.datacenter}"
  datastore = "${var.storage}"
  type = "thin"

disk {
  attach = true
  path = "${vsphere_virtual_disk.disk_2.vmdk}"
  label = "diskshared"
  unit_number = 2
  datastore_id = "${data.vsphere_datastore.datastore.id}"
}

}


But seems I can't add disk to vsphere_virtual_disk block.

Error message:

Blocks of type "disk" are not expected here.

Upvotes: 1

Views: 415

Answers (2)

Rui Jarimba
Rui Jarimba

Reputation: 17994

The disk block is not supported in vsphere_virtual_disk.

Example usage:

data "vsphere_datacenter" "datacenter" {
  name = "dc-01"
}

data "vsphere_datacenter" "datastore" {
  name = "datastore-01"
}

resource "vsphere_virtual_disk" "virtual_disk" {
  size               = 40
  type               = "thin"
  vmdk_path          = "/foo/foo.vmdk"
  create_directories = true
  
  # required
  datacenter = data.vsphere_datacenter.datacenter.name
  
  # optional
  datastore  = data.vsphere_datastore.datastore.name
}

One or more disk blocks can be configured in the vsphere_virtual_machine resource instead.

Example usage:

resource "vsphere_virtual_machine" "vm" {
  # ... other configuration ...
  disk {
    label       = "disk0"
    size        = "10"
  }
  disk {
    label       = "disk1"
    size        = "100"
    unit_number = 1
  }
  # ... other configuration ...
}

Please refer to the documentation of the provider for more details.

Upvotes: 2

joao
joao

Reputation: 2293

The "disk" block should go inside the "resource" block. Try using "terraform fmt", it will give you a first level of error checking.

Upvotes: 0

Related Questions