I’m new to Terraform so forgive me I do not explain my issue correctly.
We are working on vsphere vsphere_distributed_port_group.pgs
I create a list of distributed_port_groups and define as a map
variable “pgs” {
description = “Key value used to set name of vlan and vlan_id”
default = {
vlan1 = {
name = “vlan1”
vlan = “0001”
}
vlan2 = {
name = “vlan2”
vlan = “0002”
}
and create resources base on variable “pgs”
resource “vsphere_distributed_port_group” “pgs” {
for_each = var.pgs
name = each.value.name
distributed_virtual_switch_uuid = “${data.vsphere_distributed_virtual_switch.dvs.id}”
vlan_id = each.value.vlan
if run this plan it works well.
Plan: 2 to add, 0 to change, 0 to destroy.
However here is issue I’m having . When I add more VLAN to variable “pgs” it tries to destory vlan I create before and recreate again.
variable “pgs” {
description = “Key value used to set name of vlan and vlan_id”
default = {
vlan1 = {
name = “vlan1”
vlan = “0001”
}
vlan2 = {
name = “vlan2”
vlan = “0002”
}
vlan3 = {
name = “vlan3”
vlan = “0003”
}
Plan: 3 to add, 0 to change, 2 to destroy.
I’m not sure I’m doing something wrong or I’m missing something from my code. any advice is appreciated.