CiscoDevNet / terraform-provider-sdwan

Terraform Cisco SD-WAN Provider
https://registry.terraform.io/providers/CiscoDevNet/sdwan
Mozilla Public License 2.0
19 stars 11 forks source link

Omiting optional variables in sdwan_attach_feature_device_template results in error: invalid value #108

Open andreasbaekdahl opened 10 months ago

andreasbaekdahl commented 10 months ago

When using full variable names/paths for attaching a device template to a device, it is not possible to omit optional values. In this example a BGP feature template has 2 optional ipv4_neighbors and only 1 of them gets configured with variables during device template attachment, and the following error message is received:

sdwan_attach_feature_device_template.TEST: Creating...
╷
│ Error: Client Error
│ 
│   with sdwan_attach_feature_device_template.TEST,
│   on test.tf line 72, in resource "sdwan_attach_feature_device_template" "TEST":
│   72: resource "sdwan_attach_feature_device_template" "TEST" {
│ 
│ Failed to attach device template, got error: Action push_feature_template_configuration-8660bda5-4921-4911-b778-af308089ec35 for device
│ C8K-BC7066AD-2D0C-2344-E3E8-106432172654 failed. Activity log: ["[26-Nov-2023 12:10:00 UTC] Configuring device with feature template:
│ ANB-Test","[26-Nov-2023 12:10:00 UTC] Failed to update configuration - Error  invalid value for: address in
│ /templates/template/vpn/vpn-instance/router/bgp/neighbor/address\n"]

It is possible to leave out the optional BGP neighbor when configuring the same device template attachment through the GUI.

To reproduce:

resource "sdwan_cisco_bgp_feature_template" "TEST" {
  name         = "Test-BGP"
  description  = "Test BGP template"
  device_types = ["vedge-C8000V"]
  as_number    = "65000"
  ipv4_neighbors = [
    {
      address_variable     = "neighbor_0_address"
      remote_as_variable   = "neighbor_0_remote_as"
      optional             = true
    },
    {
      address_variable     = "neighbor_1_address"
      remote_as_variable   = "neighbor_1_remote_as"
      optional             = true
    }
  ]
}

resource "sdwan_attach_feature_device_template" "TEST" {
  devices = [
    {
      id = "C8K-BC7066AD-2D0C-2344-E3E8-106432172654"
      variables = {
        "//system/host-name"                                     = "TF-Router3"
        "//system/site-id"                                       = "12"
        "//system/system-ip"                                     = "1.1.2.2"
        "/0//router/bgp/neighbor/neighbor_0_address/address"     = "10.11.22.12"
        "/0//router/bgp/neighbor/neighbor_0_address/remote-as"   = "65012"
      }
    },
  ]
  id = sdwan_feature_device_template.TEST.id
}

resource "sdwan_feature_device_template" "TEST" {
  name        = "ANB-Test"
  description = "Test template"
  device_type = "vedge-C8000V"
  device_role = "sdwan-edge"
  general_templates = [
    {
      id   = data.sdwan_cisco_system_feature_template.default.id
      type = "cisco_system"
      sub_templates = [
        {
          id   = data.sdwan_cisco_logging_feature_template.default.id
          type = "cisco_logging"
        }
      ]
    },
    {
      id   = data.sdwan_cisco_bfd_feature_template.default.id
      type = "cisco_bfd"
    },
    {
      id   = data.sdwan_cisco_omp_feature_template.default.id
      type = "cisco_omp"
    },
    {
      id   = data.sdwan_cisco_security_feature_template.default.id
      type = "cisco_security"
    },
    {
      id   = data.sdwan_cedge_global_feature_template.default.id
      type = "cedge_global"
    },
    {
      type = "cisco_vpn"
      id   = data.sdwan_cisco_vpn_feature_template.default512.id
    },
    {
      type = "cisco_vpn"
      id   = data.sdwan_cisco_vpn_feature_template.default0.id
      sub_templates = [{
        id   = sdwan_cisco_bgp_feature_template.TEST.id
        type = "cisco_bgp"
      }]
    }
  ]
}

data "sdwan_cisco_vpn_feature_template" "default0" {
  name = "Default_AWS_TGW_CSR_VPN0_V01"
}

data "sdwan_cisco_vpn_feature_template" "default512" {
  name = "Default_AWS_TGW_CSR_VPN512_V01"
}

data "sdwan_cisco_system_feature_template" "default" {
  name = "Default_BootStrap_Cisco_System_Template"
}

data "sdwan_cedge_global_feature_template" "default" {
  name = "Default_EQUINIX_C8000V_GLOBAL_CISCO_V01"
}

data "sdwan_cisco_logging_feature_template" "default" {
  name = "Default_Logging_Cisco_V01"
}

data "sdwan_cisco_bfd_feature_template" "default" {
  name = "Default_BFD_Cisco_V01"
}

data "sdwan_cisco_omp_feature_template" "default" {
  name = "Default_AWS_TGW_CSR_OMP_IPv46_V01"
}

data "sdwan_cisco_security_feature_template" "default" {
  name = "Default_Security_Cisco_V01"
}

Adding the second optional BGP neighbor variables allows the template to be configured successfully.

resource "sdwan_attach_feature_device_template" "TEST" {
  devices = [
    {
      id = "C8K-BC7066AD-2D0C-2344-E3E8-106432172654"
      variables = {
        "//system/host-name"                                     = "TF-Router3"
        "//system/site-id"                                       = "12"
        "//system/system-ip"                                     = "1.1.2.2"
        "/0//router/bgp/neighbor/neighbor_0_address/address"     = "10.11.22.12"
        "/0//router/bgp/neighbor/neighbor_0_address/remote-as"   = "65012"
        "/0//router/bgp/neighbor/neighbor_1_address/address"     = "10.22.22.12"
        "/0//router/bgp/neighbor/neighbor_1_address/remote-as"   = "65022"
      }
    },
  ]
  id = sdwan_feature_device_template.TEST.id
}
lap-wingmen commented 6 months ago

Any News on this one?

danischm commented 6 months ago

Apologies for the long delay, could you maybe provide the captured payload when attaching the device template via the GUI (with one optional variable being configured)?

wcmder commented 5 months ago

to not use the optional variable, try set it to TEMPLATE_IGNORE example - vpn0_inet_defeault_route = "TEMPLATE_IGNORE"