Skip to content

TF Provider tries to change order auf VTI Default Rules in nsxt_policy_predefined_gateway_policy #1534

Open
@benzander

Description

@benzander

Describe the bug

I use nsxt_policy_predefined_gateway_policy to change the default rule action from ALLOW to Drop in all gateway Firewalls.
For every Route Based VPN the NSX Manager creates a default rule. So I use the same ressource to set those rules to DROP as well.

Unfortunately I run into an issue in case there are multiple Route Based VPNs in the Same T1 or T0.
The TF Providers tries to change the order of those default rules. That is how the Change looks like with 4 Route Based VPNs:

Terraform will perform the following actions:

  # module.vrf_On_CustomerT0_t0V-001.nsxt_policy_predefined_gateway_policy.gwFW-predefinedGatewayPolicy will be updated in-place
  ~ resource "nsxt_policy_predefined_gateway_policy" "gwFW-predefinedGatewayPolicy" {
        id          = "Policy_Default_Infra-tier0-df1f3954-0683-43db-89a0-f5bfe52fe142"
        # (3 unchanged attributes hidden)

      ~ default_rule {
          ~ scope           = "/infra/tier-0s/df1f3954-0683-43db-89a0-f5bfe52fe142/ipsec-vpn-services/8241df91-878f-45f9-8902-8d16a39d511e/sessions/84f05f4a-e89c-4d1e-a1bc-106a08a8e724" -> "/infra/tier-0s/df1f3954-0683-43db-89a0-f5bfe52fe142/ipsec-vpn-services/8241df91-878f-45f9-8902-8d16a39d511e/sessions/50c5e8d2-42b9-48d4-b705-640ffbe224b7"
            # (8 unchanged attributes hidden)
        }
      ~ default_rule {
          ~ scope           = "/infra/tier-0s/df1f3954-0683-43db-89a0-f5bfe52fe142/ipsec-vpn-services/8241df91-878f-45f9-8902-8d16a39d511e/sessions/8ed8467a-deed-4d01-84eb-7623d6cd8814" -> "/infra/tier-0s/df1f3954-0683-43db-89a0-f5bfe52fe142/ipsec-vpn-services/8241df91-878f-45f9-8902-8d16a39d511e/sessions/84f05f4a-e89c-4d1e-a1bc-106a08a8e724"
            # (8 unchanged attributes hidden)
        }
      ~ default_rule {
          ~ scope           = "/infra/tier-0s/df1f3954-0683-43db-89a0-f5bfe52fe142/ipsec-vpn-services/8241df91-878f-45f9-8902-8d16a39d511e/sessions/f71d6083-d34d-456c-847c-142156b0983d" -> "/infra/tier-0s/df1f3954-0683-43db-89a0-f5bfe52fe142/ipsec-vpn-services/8241df91-878f-45f9-8902-8d16a39d511e/sessions/8ed8467a-deed-4d01-84eb-7623d6cd8814"
            # (8 unchanged attributes hidden)
        }
      ~ default_rule {
          ~ scope           = "/infra/tier-0s/df1f3954-0683-43db-89a0-f5bfe52fe142/ipsec-vpn-services/8241df91-878f-45f9-8902-8d16a39d511e/sessions/50c5e8d2-42b9-48d4-b705-640ffbe224b7" -> "/infra/tier-0s/df1f3954-0683-43db-89a0-f5bfe52fe142/ipsec-vpn-services/8241df91-878f-45f9-8902-8d16a39d511e/sessions/f71d6083-d34d-456c-847c-142156b0983d"
            # (8 unchanged attributes hidden)
        }

        # (2 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

That is how the TF Code looks like:

resource "nsxt_policy_predefined_gateway_policy" "gwFW-predefinedGatewayPolicy" {
  path = "/infra/domains/default/gateway-policies/Policy_Default_Infra-tier0-${nsxt_policy_tier0_gateway.t0V.id}"

  dynamic "default_rule" {

    for_each = toset(concat(length(keys(var.vpnConfiguration)) > 0 ? [for session in module.VpnTunnels["1"].vpnSessions : session.path if session.vpn_type == "RouteBased"] : []))

    content {
      scope     = default_rule.value
      logged    = true
      log_label = local.fwRuleLogLabel
      action    = "DROP"
    }
  }

  default_rule {
    scope     = nsxt_policy_tier0_gateway.t0V.path
    logged    = true
    log_label = local.fwRuleLogLabel
    action    = "DROP"
  }
}

I can apply those changes without an error message but during the next tf plan the same change is detected again.
I would sort the input for my for_each statement into the same order as the NSX Manager is sorting the VTI Default Rules, but I don't know what the correct order is.

Or do you have the possibility to fix that somehow in the nsx tf provider?

Reproduction steps

See description

Expected behavior

See description

Additional context

Terraform Version: 1.8.5
NSX TF Provider: v3.8.0
NSX Manager: 4.1.2.4.0.23786742

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions