CiscoDevNet / terraform-provider-nxos

Terraform Cisco NX-OS Provider
https://registry.terraform.io/providers/netascode/nxos
Mozilla Public License 2.0
7 stars 10 forks source link

When "nxos_physical_interface" resource is destroyed, port config is not removed. #179

Closed huntx closed 3 months ago

huntx commented 1 year ago

As per title, when "nxos_physical_interface" resource is destroyed, most of the config lines still remain on device configuration.

For example,

resource "nxos_physical_interface" "access_port_phy_interface" {

  for_each = local.access_port_map

  device                    = each.value.device
  description               = "${each.value.description}[i/ac]"
  layer                     = "Layer2"
  interface_id              = "eth${each.value.interface_id}"
  admin_state               = "up"
  mode                      = "access"
  access_vlan               = "vlan-${each.value.vlan_id}"
}

After resource destroyed, the device "show run interface" still look like below.

interface Ethernet1/45
  description T:Access_Port_01:eth0[i/ac]
  switchport
  switchport access vlan 20
  no shutdown

It is expected to remove the port description and vlan-related configuration, or fall back to default port config.

danischm commented 9 months ago

I believe this is "expected", as the corresponding DME object cannot be deleted. I don't see how this can be fixed on the provider side.

janorga commented 7 months ago

I think that the desired behavior is to destroy the abandoned resource truly. In the case of a physical interface maybe invoking a "default interface X" command could satisfy the use case.

danischm commented 7 months ago

I guess it depends.. technically the object exists already (with whatever configuration was applied before) and is then updated by Terraform. We cannot issue any CLI commands as we are using the REST NX-API to configure the device and we cannot destroy the interface object due to the API preventing this.

janorga commented 7 months ago

Yes, this is non trivial thing. From application point of view what we are tracking is configuration, and tracked configuration dissapears when the resource is destroyed, or moved from one interface to other. In the latest, even Terraform correctly identifies it and signals the warning about resource is going to be recreated.

As i said this topic is not easy but leaving the configuration on the non-tracked object is a stone on the path. From my point of view it limits why choosing at this use case Terraform over other tools such as Ansible.

danischm commented 3 months ago

https://github.com/CiscoDevNet/terraform-provider-nxos/commit/0549672f34e34d65d33e082d878e27f8aad8b844

danischm commented 3 months ago

Enhancement added in v0.5.3 release. Terraform will now reset port to default settings when destroying the resource.