CiscoDevNet / terraform-provider-dcnm

Cisco DCNM Provider
https://registry.terraform.io/providers/CiscoDevNet/dcnm/latest/docs
Mozilla Public License 2.0
8 stars 15 forks source link

unable to add multiple switches in single play #2

Closed dsx1123 closed 3 years ago

dsx1123 commented 3 years ago

Community Note

Terraform Version

DCNM version

Affected Resource(s)

Terraform Configuration Files

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key: https://keybase.io/hashicorp
terraform {
  required_providers {
    dcnm = {
      source = "CiscoDevNet/dcnm"
      version = "0.0.1"
    }
  }
}
provider "dcnm" {
  username = "admin"
  password = "xxx"
  url      = "https://10.20.2.63"
  # expiry   = 900000
}

resource "dcnm_inventory" "leaf1" {
  fabric_name   = "fabric-dmz"
  username      = "admin"
  password      = "xxx"
  ip            = "10.20.2.10"
  role          = "leaf"
  max_hops      = 0
  auth_protocol = 0
  deploy        = true
}

resource "dcnm_inventory" "leaf2" {
  fabric_name   = "fabric-dmz"
  username      = "admin"
  password      = "xxx"
  ip            = "10.20.2.11"
  role          = "leaf"
  max_hops      = 0
  auth_protocol = 0
  deploy        = true
}

resource "dcnm_inventory" "spine1" {
  fabric_name   = "fabric-dmz"
  username      = "admin"
  password      = "xxx"
  ip            = "10.20.2.12"
  role          = "spine"
  max_hops      = 0
  auth_protocol = 0
  deploy        = true
}

Debug Output

output

Panic Output

Expected Behavior

all three switches should be added to fabric

Actual Behavior

only two were added initially, but one of them got deleted, and the plan failed eventually

Steps to Reproduce

  1. terraform apply

Important Factoids

References

nkatarmal-crest commented 3 years ago

Move all the params to blocks, deploy should be at the resource level. deploy logic should only be called when the deploy = true.

qsnyder commented 3 years ago

@nkatarmal-crest:

Move all the params to blocks

Maybe my ignorance here -- but are you referring to nested config such that each switch is nested under a single resource block? Would that be something similar to using a for_each loop in a resource to call multiple devices in a map variable? I'm experiencing similar behaviours to the above -- (2) spine (4) leaf and attempting to add all to DCNM (with and without parallelism=1 with similar results.

main.tf

resource "dcnm_inventory" "Sandbox_Switches" {
  for_each      = var.switches
  fabric_name   = "DevNet_Fabric"
  username      = "admin"
  password      = "admin12345"
  ip            = each.value.ip
  role = each.value.role
  max_hops      = 0
  auth_protocol = 0
  preserve_config = "false"
  deploy = "false"
  config_timeout = "10"
}

variable.tf

variable "switches" {
  description = "Testbed Sandbox Switches"
  type = map
  default = {
    spine1 = {
      ip = "192.168.129.121"
      role = "spine"
    },
    spine2 = {
      ip = "192.168.129.122"
      role = "spine"
    },
    leaf1 = {
      ip = "192.168.129.123"
      role = "leaf"
    },
    leaf2 = {
      ip = "192.168.129.124"
      role = "leaf"
    },
    leaf3 = {
      ip = "192.168.129.125"
      role = "leaf"
    },
    leaf4 = {
      ip = "192.168.129.126"
      role = "leaf"
    },
  }
}

with my most successful run being:

dcnm-terraform ยป terraform apply -auto-approve -parallelism=1                             ~/d/dcnm-terraform
dcnm_inventory.Sandbox_Switches["leaf1"]: Creating...
dcnm_inventory.Sandbox_Switches["leaf1"]: Still creating... [10s elapsed]
dcnm_inventory.Sandbox_Switches["leaf1"]: Still creating... [20s elapsed]
dcnm_inventory.Sandbox_Switches["leaf3"]: Creating...
dcnm_inventory.Sandbox_Switches["leaf3"]: Still creating... [10s elapsed]
dcnm_inventory.Sandbox_Switches["leaf3"]: Still creating... [20s elapsed]
dcnm_inventory.Sandbox_Switches["leaf4"]: Creating...
dcnm_inventory.Sandbox_Switches["leaf4"]: Still creating... [10s elapsed]
dcnm_inventory.Sandbox_Switches["leaf4"]: Still creating... [20s elapsed]
dcnm_inventory.Sandbox_Switches["leaf2"]: Creating...
dcnm_inventory.Sandbox_Switches["leaf2"]: Still creating... [10s elapsed]
dcnm_inventory.Sandbox_Switches["leaf2"]: Still creating... [20s elapsed]
dcnm_inventory.Sandbox_Switches["spine1"]: Creating...
dcnm_inventory.Sandbox_Switches["spine1"]: Still creating... [10s elapsed]
dcnm_inventory.Sandbox_Switches["spine1"]: Still creating... [20s elapsed]
dcnm_inventory.Sandbox_Switches["spine1"]: Still creating... [30s elapsed]
dcnm_inventory.Sandbox_Switches["spine1"]: Still creating... [40s elapsed]
dcnm_inventory.Sandbox_Switches["spine1"]: Still creating... [50s elapsed]
dcnm_inventory.Sandbox_Switches["spine1"]: Still creating... [1m0s elapsed]
dcnm_inventory.Sandbox_Switches["spine1"]: Still creating... [1m10s elapsed]
dcnm_inventory.Sandbox_Switches["spine1"]: Still creating... [1m20s elapsed]
dcnm_inventory.Sandbox_Switches["spine2"]: Creating...
dcnm_inventory.Sandbox_Switches["spine2"]: Still creating... [10s elapsed]
dcnm_inventory.Sandbox_Switches["spine2"]: Still creating... [20s elapsed]

Error: 400 Error : null

Error: 400 Error : null

Error: 400 Error : null

Error: 400 Error : null

Error: 400 Error : null

Error: 400 Error : null

All devices have been added to the inventory -- but roles are not set properly. Links are taking a long time for discovery -- so I don't know if the errors are due to timeouts being hit or if its just cranky due to the amount of work "discovery" entails.

I can't seem to have a full run deploy to completion and have the fabric be discovered as desired.

dsx1123 commented 3 years ago

@qsnyder fix is added in 0.0.3, here is example of plan:

resource "dcnm_inventory" "fabric-demo" {
  fabric_name     = "fabric-demo"
  switch_config {
    username      = "admin"
    password      = ""
    ip            = "172.31.217.122"
    preserve_config = "false"
    config_timeout = 10
    role = "leaf"
  }
  switch_config {
    username      = "admin"
    password      = ""
    ip            = "172.31.217.123"
    preserve_config = "false"
    config_timeout = 10
    role = "leaf"
  }
  switch_config {
    username      = "admin"
    password      = ""
    ip            = "172.31.186.154"
    preserve_config = "false"
    config_timeout = 10
    role = "spine"
  }
}
qsnyder commented 3 years ago

@dsx1123 Thanks! I'll take a look next week when back in front of my computer off PTO in my lab. Curiously, was this an API thing -- or something related to the async processing of the inventory? I've noticed the Ansible modules having similar issues.

dsx1123 commented 3 years ago

@qsnyder the process to add a switch on DCNM take several steps, we need to keep monitoring the state of the switch to perform the next step, you can say it is due to the async processing when onboarding the switch. we are looking to improve the performance of the inventory module of ansible also.

btw, feel free to open an issue on ansible collection if you feel like it is not working well.

dsx1123 commented 3 years ago

the issue is fixed on the latest code, will publish to terraform.