Task01
Design Interface Module

Design Interface Module

Check Branch

Before starting the lab, make sure that the stage branch is the current working branch

    
    git branch --show-current
    

Step 1 - Interface module config

We will use the dcnm_interface resource to create Loopback and vPC interfaces. Notice that the configuration parameters are unique to each interface type. Have a look at the module configuration: modules/interface/main.tf

    
    code -r /home/cisco/CiscoLive/DEVWKS-3320/modules/interface/main.tf 
    

    
terraform {
  required_providers {
    dcnm = {
      source  = "CiscoDevNet/dcnm"
      version = "1.2.7"
    }
  }
}

resource "dcnm_interface" "loopbacks" {
  for_each = {
    for lo in var.loopbacks : "${var.inventory[lo.switch_id]}|loopback${lo.loopback_id}" => lo
  }
  fabric_name   = var.fabric_name
  type          = "loopback"
  name          = "loopback${each.value.loopback_id}"
  policy        = "int_loopback"
  switch_name_1 = var.inventory[each.value.switch_id]
  vrf           = each.value.vrf
  ipv4          = each.value.loopback_ipv4
  loopback_tag  = each.value.route_tag
  deploy        = true
}

resource "dcnm_interface" "vpcs" {
  for_each = {
    for vpc in var.vpcs : "${var.inventory[vpc.switch1_id]}|${var.inventory[vpc.switch2_id]}|vpc${vpc.vpc_id}" => vpc
  }
  fabric_name             = var.fabric_name
  policy                  = "int_vpc_trunk_host"
  type                    = "vpc"
  name                    = "vPC${each.value.vpc_id}"
  switch_name_1           = var.inventory[each.value.switch1_id]
  switch_name_2           = var.inventory[each.value.switch2_id]
  vpc_peer1_id            = each.value.vpc_id
  vpc_peer2_id            = each.value.vpc_id
  mode                    = each.value.mode
  bpdu_guard_flag         = each.value.bpdu_guard_flag
  mtu                     = each.value.mtu
  vpc_peer1_allowed_vlans = "none"
  vpc_peer2_allowed_vlans = "none"
  vpc_peer1_interface     = each.value.peer1_members
  vpc_peer2_interface     = each.value.peer2_members
  deploy                  = true
}
    

Step 2 - Interface module variables

variables.tf defines the module's input variables, as well as each variable's type. Open and review the file modules/interface/variables.tf

    
    code -r /home/cisco/CiscoLive/DEVWKS-3320/modules/interface/variables.tf 
    

    
variable "fabric_name" {
  type = string
}

variable "inventory" {
  type = map(any)
}

variable "loopbacks" {
  type = list(object({
    switch_id     = string
    loopback_id   = number
    loopback_ipv4 = string
    vrf           = string
    route_tag     = number
  }))
}

variable "vpcs" {
  type = list(object({
    vpc_id          = number
    switch1_id      = string
    switch2_id      = string
    mode            = string
    bpdu_guard_flag = string
    mtu             = string
    peer1_members   = list(string)
    peer2_members   = list(string)
  }))
}
    
  • Introduction
  • NDFC and Terraform
  • Envrionment and Topology
  • Task01 Interface Module
  • Task02 Overlay Module
  • Task03 CI/CD Pipeline
  • Bonus: Policy Module
  • Thanks