Find out ID of port group

Suppose I have the following port group:

resource "vsphere_distributed_port_group" "pg-mgm" {
  name                            = "terraform-mgm"
  distributed_virtual_switch_uuid = "${vsphere_distributed_virtual_switch.dvs.id}"

  vlan_id = 1000
  allow_promiscuous = true
  allow_mac_changes = true
  allow_forged_transmits = true
 
  active_uplinks  = ["tfup1"]
  
}

I can create portgroup, So I want to reference to the given port group in network_id in VM block, But I don’t know how to reference to the given port group. such as:


resource "vsphere_virtual_machine" "pah-mgm" {
network_interface{
network_id = ID_OF_PG
}
}

How can I reference to this?

Try:

resource "vsphere_virtual_machine" "pah-mgm" {
network_interface{
network_id = vsphere_distributed_port_group.pg-mgm.id
}

This is a generic terraform pattern ...

The documentation includes available attributes:
https://registry.terraform.io/providers/hashicorp/vsphere/latest/docs/resources/distributed_port_group#attribute-reference

1 Like