citrix / terraform-provider-citrixadc

Part of NetScaler Automation Toolkit | https://github.com/netscaler/automation-toolkit
https://registry.terraform.io/providers/citrix/citrixadc
Apache License 2.0
119 stars 59 forks source link

[Bug]: Dynamic route - String length exceeds maximum [commandString, 711] #1179

Open reckio123 opened 4 months ago

reckio123 commented 4 months ago

Terraform Core Version

1.9.1

citrixadc Provider Version

1.39.0

Operating system

Windows

Affected Resource(s)

citrixadc_routerdynamicrouting

Equivalent NetScaler CLI Command

ns route-install default ! ns route-install bgp ! bgp extended-asn-cap ! ip prefix-list PL_DENY_DEFAULT_ROUTE seq 5 deny 0.0.0.0/0 ip prefix-list PL_PERMIT_VIP_NET_ADV seq 5 permit 10.100.200.128/25 ! route-map RM_BGP_ADVERTISE permit 10 match ip address prefix-list PL_PERMIT_VIP_NET_ADV ! route-map RM_BGP_ADVERTISE deny 15 match ip address prefix-list PL_DENY_DEFAULT_ROUTE ! router bgp 4205696395 max-paths ebgp 2 bgp graceful-restart network 10.100.200.128/25 redistribute kernel neighbor 10.100.250.1 remote-as 4205016395 neighbor 10.100.250.1 fall-over bfd neighbor 10.100.250.1 soft-reconfiguration inbound neighbor 10.100.250.1 route-map RM_BGP_ADVERTISE out neighbor 10.100.250.5 remote-as 4205016395 neighbor 10.100.250.5 fall-over bfd neighbor 10.100.250.5 soft-reconfiguration inbound neighbor 10.100.250.5 route-map RM_BGP_ADVERTISE out ! end

Expected Behavior

The provider should install the bgp routes on the NetScaler appliance

Actual Behavior

The provider is presenting an error to execute because the configuration is longer than 711 characters

Relevant Error/Panic Output Snippet

│ Error: [ERROR] nitro-go: Failed to apply action on resource of type routerdynamicrouting,  action=apply err=failed: 599 Netscaler specific error ({ "errorcode": 1106, "message": "String length exceeds maximum [commandString, 711]", "severity": "ERROR" })  
│
│   with citrixadc_routerdynamicrouting.tf_dynamicrouting,
│   on bgp.tf line 22, in resource "citrixadc_routerdynamicrouting" "tf_dynamicrouting":
│   22: resource "citrixadc_routerdynamicrouting" "tf_dynamicrouting" {

Terraform Configuration Files

# provider
terraform {
  required_providers {
    citrixadc = {
      source  = "citrix/citrixadc"
      version = "1.39.0" 
    }
  }
}

provider "citrixadc" {
  endpoint = "http://192.168.0.48"
  username = "nsroot" # NS_LOGIN env variable
  password = "nsroot123" # NS_PASSWORD env variable
}

# locals {
#     bgp_file = split("\n", chomp(file("bgp.txt")))
# }

resource "citrixadc_routerdynamicrouting" "tf_dynamicrouting" {
    provider = citrixadc
    # commandlines = local.bgp_file
    commandlines = [
        "ns route-install default",
        "!",
        "ns route-install bgp",
        "!",
        "bgp extended-asn-cap",
        "!",
        "ip prefix-list PL_DENY_DEFAULT_ROUTE seq 5 deny 0.0.0.0/0",
        "ip prefix-list PL_PERMIT_VIP_NET_ADV seq 5 permit 10.100.200.128/25",
        "!",
        "route-map RM_BGP_ADVERTISE permit 10",
        "match ip address prefix-list PL_PERMIT_VIP_NET_ADV",
        "!",
        "route-map RM_BGP_ADVERTISE deny 15",
        "match ip address prefix-list PL_DENY_DEFAULT_ROUTE",
        "!",
        "router bgp 4205696395",
        "max-paths ebgp 2",
        "bgp graceful-restart",
        "network 10.100.200.128/25",
        "redistribute kernel",
        "neighbor 10.100.250.1 remote-as 4205016395",
        "neighbor 10.100.250.1 fall-over bfd",
        "neighbor 10.100.250.1 soft-reconfiguration inbound",
        "neighbor 10.100.250.1 route-map RM_BGP_ADVERTISE out",
        "neighbor 10.100.250.5 remote-as 4205016395",
        "neighbor 10.100.250.5 fall-over bfd",
        "neighbor 10.100.250.5 soft-reconfiguration inbound",
        "neighbor 10.100.250.5 route-map RM_BGP_ADVERTISE out",
    ]
}

Steps to Reproduce

terraform apply -auto-approve

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

rohit-myali commented 3 months ago

Hey @reckio123 Thanks for raising this issue.

That was the limitation from the NetScaler's resource. There is a threshold max length for the attribute commandlines.

But we have a workaround for the same.

Please split your commandlines and create different resource. Below is the alternative configuration for your above provided configuration.

resource "citrixadc_routerdynamicrouting" "tf_dynamicrouting" {
  # provider = citrixadc
  # commandlines = local.bgp_file
  commandlines = [
    "ns route-install default",
    "!",
    "ns route-install bgp",
    "!",
    "bgp extended-asn-cap",
    "!",
    "ip prefix-list PL_DENY_DEFAULT_ROUTE seq 5 deny [0.0.0.0/0](http://0.0.0.0/0)",
    "ip prefix-list PL_PERMIT_VIP_NET_ADV seq 5 permit [10.100.200.128/25](http://10.100.200.128/25)",
    "!",
    "route-map RM_BGP_ADVERTISE permit 10",
    "match ip address prefix-list PL_PERMIT_VIP_NET_ADV",
    "!",
    "route-map RM_BGP_ADVERTISE deny 15",
    "match ip address prefix-list PL_DENY_DEFAULT_ROUTE",
    "!",
  ]
}
resource "citrixadc_routerdynamicrouting" "tf_dynamicrouting_1" {
  # provider = citrixadc
  # commandlines = local.bgp_file
  commandlines = [
    "router bgp 4205696395",
    "max-paths ebgp 2",
    "bgp graceful-restart",
    "network [10.100.200.128/25](http://10.100.200.128/25)",
    "redistribute kernel",
    "neighbor 10.100.250.1 remote-as 4205016395",
    "neighbor 10.100.250.1 fall-over bfd",
    "neighbor 10.100.250.1 soft-reconfiguration inbound",
    "neighbor 10.100.250.1 route-map RM_BGP_ADVERTISE out",
    "neighbor 10.100.250.5 remote-as 4205016395",
    "neighbor 10.100.250.5 fall-over bfd",
    "neighbor 10.100.250.5 soft-reconfiguration inbound",
    "neighbor 10.100.250.5 route-map RM_BGP_ADVERTISE out",
  ]
}