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

Please add support for BGP network statements #162

Closed mobig closed 1 year ago

mobig commented 1 year ago

We need the ability to add BGP network statements to our BGP configuration. here is an example

router bgp 65000
  router-id 192.168.0.158
  graceful-restart restart-time 240
  graceful-restart stalepath-time 1800
  address-family ipv4 unicast
    network 2.2.2.3/32
  neighbor 5.5.5.2
    remote-as 65000
    description BGP Neighbor 1
    address-family ipv4 unicast
      send-community
      send-community extended

I am using the following nxos_rest resource to configure this and it works, but terraform keeps telling me that it's adding the addr value every time we apply

resource "nxos_rest" "bgp_networks" {
  for_each   = {for bgp_network in local.bgp_networks_configs : bgp_network.key => bgp_network}
  device     = each.value.device
  dn         = "sys/bgp/inst/dom-default/af-[ipv4-ucast]"
  class_name = "bgpDomAf"
  children   = [
    {
      rn         = "prefix-[${each.value.network_address}/${each.value.mask}]"
      class_name = "bgpAdvPrefix"
      content    = {
        addr = "${each.value.network_address}${each.value.mask}"
      }
    }
  ]
}

This is what terraform tells me

  # nxos_rest.bgp_networks["switch_2-2.2.2.3"] will be updated in-place
  ~ resource "nxos_rest" "bgp_networks" {
      ~ children   = [
          ~ {
              + content    = {
                  + "addr" = "2.2.2.3/32"
                }
                # (2 unchanged attributes hidden)
            },
        ]
        id         = "sys/bgp/inst/dom-default/af-[ipv4-ucast]"
        # (4 unchanged attributes hidden)
    }

Like i said, it still pushes the change and configures the network statement in the BGP config, but I don't like Terraform telling me that it's changing something that's not really changing. I'm sure it has something to do with how the NX-API is presenting the data after it's added and it's throwing Terraform off, so it thinks it's a change.

BTW, I appreciate all the support thus far with all the new features added. It seems like the provider is really coming along.

jgomezve commented 1 year ago

Hi @mobig

Unfortunately the nxos_rest resource does not detect drifts on its children. Thus, the recommendation is to use dedicated instances of the nxos_rest resource for each MO, as the example below shows:

resource "nxos_rest" "bgp_af" {
  dn         = "sys/bgp/inst/dom-default/af-[ipv4-ucast]"
  class_name = "bgpDomAf"
  content = {
    type = "ipv4-ucast"
  }
}

resource "nxos_rest" "bgp_prefix" {
  dn         = "${nxos_rest.bgp_af.id}/prefix-[192.168.1.0/24]"
  class_name = "bgpAdvPrefix"
  content = {
    addr = "192.168.1.0/24"
  }
}

I have tested this HCL configuration and it is idempotent.

Anyways, we are also currently working on a dedicated resource for the BGP Prefixes. It will come in the next release

danischm commented 1 year ago

A dedicated resource is available in v0.5.1 .