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

Interface VRF change does not reapply HSRP config #251

Open mobig opened 1 month ago

mobig commented 1 month ago

It seems that when you change the VRF on an interface, the provider is smart enough to detect that the interface IP needs to be reapplied as NXOS removes the IP (stealthy). However, this does not seem to be the case with HSRP config. I request the same functionality for HSRP config so it persists after an interface VRF assignment change.

jgomezve commented 1 month ago

Hi @mobig

In the example you mentioned, after modifying the VRF name, Terraform is smart enough to re-create the IP address resource (nxos_ipv4_interface_address) because the vrf attribute is marked internally as RequiresReplace().

Unfortunately, the same approach cannot be taken for the HSRP resources, as those resources do not have any relationship with the VRF objects inside the DME tree. However, you could leverage the attribute replace_triggered_by inside the meta-argument lifecycle, which as the name implies forces a resource to be re-created if a specific attribute of another resource changes. Here is a basic example:

resource "nxos_rest" "hsrpIf" {
  dn         = "${nxos_rest.hsrpInst.id}/if-[eth1/11]"
  class_name = "hsrpIf"
  content = {
    id      = "eth1/11"
    version = "v2"
  }
    lifecycle {
    replace_triggered_by = [
      nxos_ipv4_interface_address.example.id
    ]
  }
}

I have created a full Terraform plan with you use-case here https://gist.github.com/jgomezve/8db59dfc52b62bd4adf6d08a0fb3c573

In this Terraform plan I am forcing the creation the MOs hsrpIf and hsrpGroup if the IP address of an interface changes

Let me know if this works