terraform-provider-vsphere
terraform-provider-vsphere copied to clipboard
Virtual machine's networks with the same `deviceConfigId` causing conflict
Community Guidelines
- [X] I have read and agree to the HashiCorp Community Guidelines .
- [X] Vote on this issue by adding a 👍 reaction to the original issue initial description to help the maintainers prioritize.
- [X] Do not leave "+1" or other comments that do not add relevant information or questions.
- [X] If you are interested in working on this issue or have submitted a pull request, please leave a comment.
Terraform
v1.5.0
Terraform Provider
v2.4.0
VMware vSphere
v7.0.3
Description
I've deployed a virtual machine (Ubuntu 18.04) with one network, connected to DHCP. Then, i launched a few services using docker-compose file, which exposed three IP addresses: 172.18.0.1, 172.19.0.1, 172.20.0.1.
After running terraform output i expect to see four different IP addresses: three of them, exposed by docker, and one from DHCP server.
Affected Resources or Data Sources
resource/resource_vsphere_virtual_machine
Terraform Configuration
resource "vsphere_virtual_machine" "virtual_machine" {
for_each = {
for vm in var.virtual_machines : vm.uuid => vm
if vm.is_router == false && length(vm.vlans) > 0
}
datastore_id = data.vsphere_datastore.datastore.id
resource_pool_id = data.vsphere_resource_pool.resource_pool.id
name = each.value.name
folder = vsphere_folder.folder.path
guest_id = data.vsphere_virtual_machine.templates[each.key].guest_id
num_cpus = coalesce(each.value.cpu_number, data.vsphere_virtual_machine.templates[each.key].num_cpus)
memory = coalesce(each.value.memory_mb, data.vsphere_virtual_machine.templates[each.key].memory)
firmware = data.vsphere_virtual_machine.templates[each.key].firmware
# Wait for ip address only if virtual machine is connected to a port group.
wait_for_guest_ip_timeout = length(each.value.vlans) > 0 ? 20 : 0
wait_for_guest_net_timeout = length(each.value.vlans) > 0 ? 20 : 0
clone {
template_uuid = data.vsphere_virtual_machine.templates[each.key].id
customize {
dynamic "network_interface" {
for_each = range(length({
for pg in data.vsphere_network.distributed_port_group : pg.id => pg
if contains([for vlan in each.value.vlans : vlan], pg.name)
}))
content {}
}
}
}
custom_attributes = tomap({
"${vsphere_custom_attribute.vm_uuid.id}" = each.value.uuid
})
dynamic "network_interface" {
for_each = {
for pg in data.vsphere_network.distributed_port_group : pg.id => pg
if contains([for vlan in each.value.vlans : vlan], pg.name)
}
iterator = network
content {
network_id = network.key
}
}
...
lifecycle {
ignore_changes = [custom_attributes]
}
}
Debug Output
None
Panic Output
No response
Expected Behavior
Expected to see three different IP addresses using terraform output, despite that their network's deviceConfigId attribute is the same (deviceConfigId=-1) :
virtual_machines_data = tomap({
"vm-uuid" = {
"ip_addresses" = tolist([
"172.18.0.1",
"fe80::42:17ff:fe85:90c0",
"172.19.0.1",
"fe80::42:7bff:fef2:76e4",
"172.20.0.1",
"fe80::42:1bff:fea3:100a",
])
}
})
Actual Behavior
After running terraform output i get three identical IP addresses
virtual_machines_data = tomap({
"vm-uuid" = {
"ip_addresses" = tolist([
"172.20.0.1",
"fe80::42:1bff:fea3:100a",
"172.20.0.1",
"fe80::42:1bff:fea3:100a",
"172.20.0.1",
"fe80::42:1bff:fea3:100a",
])
}
})
Steps to Reproduce
- Deploy Linux virtual machine
- Expose two or more IP addresses with docker
Environment Details
No response
Screenshots
References
No response
Hello, AlexPetul! 🖐
Thank you for submitting an issue for this provider. The issue will now enter into the issue lifecycle.
If you want to contribute to this project, please review the contributing guidelines and information on submitting pull requests.
I have investigated the issue, and it appears, that this behavior is caused by buildAndSelectGuestIPs function.
https://github.com/hashicorp/terraform-provider-vsphere/blob/97f3d80ffc6b7e51c85a0aff76837f5d80112971/vsphere/virtual_machine_guest_structure.go#L72-L95
Is this an expected behavior? I've successfully reached my goal just replacing deviceConfigId with MacAddress. Should i open a PR?
More detailed steps to reproduce:
- Deploy in vSphere any linux machine (i've used Ubuntu 22 Server)
- Install docker compose on it
- Create docker-compose.yml and bring the services up:
version: '3.4'
services:
web:
image: crccheck/hello-world
ports:
- "8000:8000"
networks:
- ig_webapp
web_2:
image: crccheck/hello-world
ports:
- "8001:8000"
networks:
- ig_webapp2
networks:
ig_webapp:
ig_webapp2:
Now docker should create two different network interfaces. See the list of ip addresses:
ip a
This is the screenshot from my output:
This is the output of terraform refresh:
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.