Reputation: 101
I'm using Terraform's vSphere Provider. I have a local OVF template that I'm trying to deploy a VM from. I wish to set a static IP address for the soon-to-be-deployed VM, but Terraform keeps complaining
ipv4_address
is not expected here."ipv4_netmask
is not expected here."DHCP is not an option so I have to set it manually. Terraform gives an option to allocate IPs manually, so what can I do?
This is the Template I'm using:
data "vsphere_ovf_vm_template" "ovfRemote" {
name = "foo"
disk_provisioning = "thick"
datastore_id = data.vsphere_datastore.datastore.id
host_system_id = data.vsphere_host.host.id
resource_pool_id = data.vsphere_resource_pool.default.id
local_ovf_path = "/path/to/ovf"
ip_protocol = "IPV4"
ip_allocation_policy = "STATIC_MANUAL"
ovf_network_map = {
"Network" : data.vsphere_network.network.id
}
}
and here's the Virtual Machine's I'm trying to create:
resource "vsphere_virtual_machine" "vmFromLocalOvf" {
name = "terraform-using-ovf-template"
datacenter_id = data.vsphere_datacenter.datacenter.id
datastore_id = data.vsphere_datastore.datastore.id
host_system_id = data.vsphere_host.host.id
resource_pool_id = data.vsphere_resource_pool.default.id
wait_for_guest_net_timeout = 0
wait_for_guest_ip_timeout = 0
num_cpus = data.vsphere_ovf_vm_template.ovfRemote.num_cpus
memory = data.vsphere_ovf_vm_template.ovfRemote.memory
guest_id = data.vsphere_ovf_vm_template.ovfRemote.guest_id
ovf_deploy {
allow_unverified_ssl_cert = false
enable_hidden_properties = false
local_ovf_path = data.vsphere_ovf_vm_template.ovfRemote.local_ovf_path
disk_provisioning = data.vsphere_ovf_vm_template.ovfRemote.disk_provisioning
ip_protocol = data.vsphere_ovf_vm_template.ovfRemote.ip_protocol
ip_allocation_policy = data.vsphere_ovf_vm_template.ovfRemote.ip_allocation_policy
ovf_network_map = data.vsphere_ovf_vm_template.ovfRemote.ovf_network_map
}
#### HERE IS THE PROBLEM I'M FACING ###
# With the provider 'vsphere_virtual_machine' I should be able to specify
# a network interface. Specifically, I'm interested in setting a
# * ipv4_address
# * ipv4_netmask
# * ipv4_gateway
network_interface {
ipv4_address = "11.22.33.44"
ipv4_netmask = 24
}
ipv4_gateway = "55.66.77.88"
Errors:
$ terraform plan
╷
│ Error: Unsupported argument
│
│ on main.tf line 82, in resource "vsphere_virtual_machine" "vmFromLocalOvf":
│ 82: ipv4_address = "10.112.128.22"
│
│ An argument named "ipv4_address" is not expected here.
╵
╷
│ Error: Unsupported argument
│
│ on main.tf line 83, in resource "vsphere_virtual_machine" "vmFromLocalOvf":
│ 83: ipv4_netmask = 24
│
│ An argument named "ipv4_netmask" is not expected here.
╵
╷
│ Error: Unsupported argument
│
│ on main.tf line 86, in resource "vsphere_virtual_machine" "vmFromLocalOvf":
│ 86: ipv4_gateway = "10.112.128.1"
│
│ An argument named "ipv4_gateway" is not expected here.
Upvotes: 0
Views: 1635
Reputation: 13451
To clone and customize a VM from local OVF/OVA template you have to use the properties that the OVF/OVA template supports. These properties are defined inside the OVF (XML) file.
To set these properties in Terraform, use the vapp
block inside your vsphere_virtual_machine
resource, e. g.:
vapp {
properties = {
"guestinfo.ipaddress" = "172.16.11.101",
"guestinfo.netmask" = "255.255.255.0",
"guestinfo.gateway" = "172.16.11.1"
}
}
There also is a full example in the docs you already linked.
Upvotes: 0