Terraform Provider for Cisco IOS XE
The terraform-provider-iosxe is a plugin for Terraform that one can use to manage the configuration and state on Cisco Catalyst IOS XE devices including switches, routers, and wireless LAN controllers.
The provider was build and tested with Cisco Catalyst IOS XE and all subsequent releases are supported
- Cisco IOS XE 17.7
Getting Started
Review the Intro to IOS XE slides for reference
- Enable RESTCONF on the device
device# conf t
device(conf)# restconf
- Install Terraform on the host that will apply the changes to the device
- Create a Terraform file on the host like the following example that adds VLAN 1 to the device:
vlan.tf
terraform {
required_providers {
iosxe = {
version = "0.1.1"
source = "CiscoDevNet/iosxe"
}
}
}
provider "iosxe" {
request_timeout = 30
insecure = true
}
resource "iosxe_rest" "vlan_example" {
method = "POST"
path = "/data/Cisco-IOS-XE-native:native/vlan"
payload = jsonencode(
{
"Cisco-IOS-XE-vlan:vlan-list": {
"id": "1",
"name": "VLAN1"
}
}
)
}
- Initialize Terraform on the host
$ terrafrom init
- Apply the Terraform file
$ terrafrom apply -auto-approve
Cisco IOS XE Example Resources
Creating Additional Terraform Resources
Any feature or Remote Procedure Call (RPC) supported by RESTCONF & YANG is supported by this Terraform provider. If a particular feature example is not yet in this GitHub repository, you can create the necessary Terraform file using these steps
-
Configure the feature as per the CLI config guide, if needed.
-
You can find the JSON for features currently configured device using
show run | format restconf-json
- An alternate approach to find the RESTCONF JSON can be done using YANG Suite, a tool to visualize and understand YANG models
-
The resulting JSON found from executing RESTCONF can be used to create the .tf file. For example, replace each of the values in angle brackets (<>) in the example Terraform file below with the corresponding Xpath and JSON:
example.tf
resource "iosxe_rest" "feature_put" { method = "PUT" path = <RESTCONF_XPATH> payload = jsonencode( { <JSON_RESPONSE> } ) }