We will use the dcnm provider's overlay
module to configure VRFs and Networks on fabric-stage. First, let's create the terraform configuration. Open the file task02_overlay/main.tf
:
code -r /home/cisco/CiscoLive/DEVWKS-3320/task02_overlay/main.tf
Copy the below content to the file and press Ctrl+s
to save it.
terraform {
required_providers {
dcnm = {
source = "CiscoDevNet/dcnm"
version = "1.2.7"
}
}
}
provider "dcnm" {
username = var.ndfc.username
password = var.ndfc.password
url = var.ndfc.url
platform = var.ndfc.platform
}
module "overlay" {
source = "../modules/overlay"
fabric_name = var.fabric_name
inventory = var.inventory
vrfs = var.vrfs
networks = var.networks
}
variables.tf
defines the variables and their types that we referenced in main.tf
. Open the file task02_overlay/variables.tf
.
code -r /home/cisco/CiscoLive/DEVWKS-3320/task02_overlay/variables.tf
Copy the content below to this file and press Ctrl+s
to save it.
variable "ndfc" {
type = object({
username = string
password = string
url = string
platform = string
})
}
variable "fabric_name" {
type = string
}
variable "inventory" {
type = map(any)
}
variable "vrfs" {
type = list(object({
name = string
vlan_id = number
segment_id = number
description = string
attachments = list(object({
switch_id = string
}))
}))
}
variable "networks" {
type = list(object({
name = string
vlan_id = number
network_id = number
vrf_name = string
ipv4_gateway = string
description = string
attachments = list(object({
switch_id = string
switch_ports = list(string)
}))
}))
}
overlay.tfvars
is the terraform plan's input. It is here that we assign concrete values to the variables we previously defined in Step 2. These need to match variables.tf
in both name and structure. In this task, we'll first create VRF vrf_devnet
and attach it to staging-leaf1 and staging-leaf2. We'll then create a network network_devnet1
and attach it to the vPC port-channel interfaces we created earlier in Task01.
Open the file task02_overlay/overlay.tfvars
:
code -r /home/cisco/CiscoLive/DEVWKS-3320/task02_overlay/overlay.tfvars
Copy the content below to this file and press Ctrl+s
to save it.
ndfc = {
username = "admin",
password = "cisco.123",
url = "https://10.15.0.14",
platform = "nd"
}
fabric_name = "fabric-stage"
inventory = {
101 = "staging-leaf1",
102 = "staging-leaf2",
201 = "staging-spine1",
}
vrfs = [
{
name = "vrf_devnet"
segment_id = 150001
vlan_id = 2000
description = "VRF for DEVWKS-3320"
attachments = [
{
switch_id = 101
},
{
switch_id = 102
},
]
}
]
networks = [
{
name = "network_devnet1"
network_id = 130001
vlan_id = 2301
description = "Network1 for DEVWKS-3320"
vrf_name = "vrf_devnet"
ipv4_gateway = "10.10.10.1/24"
attachments = [
{
switch_id = 101
switch_ports = [
"Port-channel10",
"Port-channel20",
]
},
{
switch_id = 102
switch_ports = [
"Port-channel10",
"Port-channel20",
]
}
]
}
]
cd /home/cisco/CiscoLive/DEVWKS-3320/task02_overlay
terraform init
Initializing modules...
- overlay in ../modules/overlay
Initializing the backend...
Initializing provider plugins...
- Finding ciscodevnet/dcnm versions matching "1.2.7"...
- Installing ciscodevnet/dcnm v1.2.7...
- Installed ciscodevnet/dcnm v1.2.7 (signed by a HashiCorp partner, key ID 433649E2C56309DE)
Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://www.terraform.io/docs/cli/plugins/signing.html
Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
terraform plan -var-file=overlay.tfvars -out plan
module.overlay.data.dcnm_inventory.inventory["201"]: Reading...
module.overlay.data.dcnm_inventory.inventory["101"]: Reading...
module.overlay.data.dcnm_inventory.inventory["102"]: Reading...
module.overlay.data.dcnm_inventory.inventory["101"]: Read complete after 1s [id=10.15.2.12]
module.overlay.data.dcnm_inventory.inventory["201"]: Read complete after 1s [id=10.15.2.11]
module.overlay.data.dcnm_inventory.inventory["102"]: Read complete after 1s [id=10.15.2.13]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# module.overlay.dcnm_network.networks["network_devnet1"] will be created
+ resource "dcnm_network" "networks" {
+ arp_supp_flag = (known after apply)
+ deploy = true
+ deploy_timeout = 300
+ description = "Network1 for DEVWKS-3320"
.
[ommited]
.
Plan: 2 to add, 0 to change, 0 to destroy.
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Saved the plan to: plan
To perform exactly these actions, run the following command to apply:
terraform apply "plan"
terraform apply plan
module.overlay.dcnm_vrf.vrfs["vrf_devnet"]: Creating...
module.overlay.dcnm_vrf.vrfs["vrf_devnet"]: Still creating... [10s elapsed]
module.overlay.dcnm_vrf.vrfs["vrf_devnet"]: Creation complete after 14s [id=vrf_devnet]
module.overlay.dcnm_network.networks["network_devnet1"]: Creating...
module.overlay.dcnm_network.networks["network_devnet1"]: Still creating... [10s elapsed]
module.overlay.dcnm_network.networks["network_devnet1"]: Still creating... [20s elapsed]
module.overlay.dcnm_network.networks["network_devnet1"]: Still creating... [30s elapsed]
module.overlay.dcnm_network.networks["network_devnet1"]: Creation complete after 31s [id=network_devnet1]
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.