We will use the dcnm_interface
module to configure loopback and vPC interfaces on fabric-stage. First, let's create the terraform configuration in task01_interfaces/main.tf
:
code -r /home/cisco/CiscoLive/DEVWKS-3320/task01_interfaces/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 "interfaces" {
source = "../modules/interface"
fabric_name = var.fabric_name
inventory = var.inventory
loopbacks = var.loopbacks
vpcs = var.vpcs
}
variables.tf
defines the variables and their types that we referenced in main.tf
. Open the file task01_interfaces/variables.tf
to review these.
code -r /home/cisco/CiscoLive/DEVWKS-3320/task01_interfaces/variables.tf
Copy the below content to the 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 "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)
}))
}
interface.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. Open the file task01_interfaces/interface.tfvars
to review these.
code -r /home/cisco/CiscoLive/DEVWKS-3320/task01_interfaces/interface.tfvars
Copy the below content to the 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 = "stanging-spine1",
}
loopbacks = [
{
loopback_id = 10
switch_id = 101
loopback_ipv4 = "100.100.100.1"
vrf = "devnet"
route_tag = 12345
},
{
loopback_id = 10
switch_id = 102
loopback_ipv4 = "100.100.100.2"
vrf = "devnet"
route_tag = 12345
}
]
vpcs = [
{
vpc_id = 10
switch1_id = "101"
switch2_id = "102"
mode = "active"
bpdu_guard_flag = "true"
mtu = "jumbo"
peer1_members = ["eth1/1"]
peer2_members = ["eth1/1"]
},
{
vpc_id = 20
switch1_id = "101"
switch2_id = "102"
mode = "active"
bpdu_guard_flag = "true"
mtu = "jumbo"
peer1_members = ["eth1/2"]
peer2_members = ["eth1/2"]
}
]
cd /home/cisco/CiscoLive/DEVWKS-3320/task01_interfaces
terraform init
Initializing modules...
- interfaces in ../modules/interface
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=interface.tfvars -out plan
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.interfaces.dcnm_interface.loopbacks["staging-leaf1|loopback10"] will be created
+ resource "dcnm_interface" "loopbacks" {
+ access_vlans = (known after apply)
+ admin_state = true
+ allowed_vlans = (known after apply)
+ bpdu_guard_flag = (known after apply)
+ configuration = (known after apply)
+ deploy = true
.
[ommited]
.
Plan: 4 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.interfaces.dcnm_interface.vpcs["staging-leaf1|staging-leaf2|vpc20"]: Creating...
module.interfaces.dcnm_interface.vpcs["staging-leaf1|staging-leaf2|vpc10"]: Creating...
module.interfaces.dcnm_interface.loopbacks["staging-leaf2|loopback10"]: Creating...
module.interfaces.dcnm_interface.loopbacks["staging-leaf1|loopback10"]: Creating...
module.interfaces.dcnm_interface.vpcs["staging-leaf1|staging-leaf2|vpc20"]: Still creating... [10s elapsed]
module.interfaces.dcnm_interface.vpcs["staging-leaf1|staging-leaf2|vpc10"]: Still creating... [10s elapsed]
module.interfaces.dcnm_interface.loopbacks["staging-leaf2|loopback10"]: Still creating... [10s elapsed]
module.interfaces.dcnm_interface.loopbacks["staging-leaf1|loopback10"]: Still creating... [10s elapsed]
module.interfaces.dcnm_interface.loopbacks["staging-leaf1|loopback10"]: Creation complete after 13s [id=loopback10]
module.interfaces.dcnm_interface.loopbacks["staging-leaf2|loopback10"]: Creation complete after 13s [id=loopback10]
module.interfaces.dcnm_interface.vpcs["staging-leaf1|staging-leaf2|vpc20"]: Still creating... [20s elapsed]
module.interfaces.dcnm_interface.vpcs["staging-leaf1|staging-leaf2|vpc10"]: Still creating... [20s elapsed]
module.interfaces.dcnm_interface.vpcs["staging-leaf1|staging-leaf2|vpc20"]: Still creating... [30s elapsed]
module.interfaces.dcnm_interface.vpcs["staging-leaf1|staging-leaf2|vpc10"]: Still creating... [30s elapsed]
module.interfaces.dcnm_interface.vpcs["staging-leaf1|staging-leaf2|vpc10"]: Creation complete after 35s [id=vPC10]
module.interfaces.dcnm_interface.vpcs["staging-leaf1|staging-leaf2|vpc20"]: Still creating... [40s elapsed]
module.interfaces.dcnm_interface.vpcs["staging-leaf1|staging-leaf2|vpc20"]: Creation complete after 42s [id=vPC20]
Apply complete! Resources: 4 added, 0 changed, 0 destroyed.