I have created this repository to get started with Terraform and since I don't have much experience with either cloud (AWS, GCP, Azzue etc.) or ACI, I decided to explore the terraform with Cisco IOSXE. Having a network engineer background, I have good understanding how to deal with IOSXE devices. I found two awesome providers mentioned with their links below.
https://registry.terraform.io/providers/CiscoDevNet/iosxe/latest
https://registry.terraform.io/providers/netascode/iosxe/latest
As there are two different providers, I have seperated them out in two folders, so if you like run the Terraform provider of your choice, go to respective folder and run the terraform commands.
Please also notice that, this is very basic and just to understand how Terraform works and what you can with Terraform to configure IOSXE devices. Everyone is welcome to clone or fork and take this as starting point towards Terraform.
Check out the following link to download and install the Terraform on different operating systems.
https://www.terraform.io/downloads
# Check Terraform Version $ terraform version # Verify the installation and terraform commands help $ terraform -help # Install the autocomplete package. $ terraform -install-autocomplete # Initial and reinstall providers $ terraform init $ terraform init -upgrade $ terraform providers # Format and validate Terraform config .tf files before plan and apply $ terraform validate $ terraform fmt $ terraform fmt --diff # Plan (dry run), apply (commit) and destroy (delete/remove) $ terraform plan $ terraform apply $ terraform apply -auto-approve $ terraform destroy $ terraform destroy -auto-approve # Refresh the terraform state file, if there was a manual change on the device $ terraform refresh # Terraform state commands $ terraform state list $ terraform state list iosxe_rest.get_native_config # Display output on the terminal $ terraform show $ terraform output $ terraform output -json $ terraform output debug_native_config # Terraform workspace commands $ terraform workspace list $ terraform workspace show $ terraform workspace new dev $ terraform workspace select default # Plan and Apply on the specific resource $ terraform plan -target main.rtf $ terraform plan -target get_configs.tf (plan with specific .tf file) $ terraform plan -target iosxe_rest.get_interfaces (plan with specific resource) $ terraform plan -target iosxe_rest $ terraform apply -target main.rtf $ terraform apply -target get_configs.tf (apply with specific .tf file) $ terraform apply -target iosxe_rest.get_interfaces (apply with specific resource) $ terraform apply -target=module.bgp_config (apply with specific module) # Import the existing user from the device (note: resource "iosxe_static_route.static_route" must exists otherwise won't import ) $ terraform import iosxe_static_route.static_route "Cisco-IOS-XE-native:native/ip/route/ip-route-interface-forwarding-list=10.20.0.0,255.255.255.0" # Replace the providers from 'netascode/iosxe' to 'CiscoDevNet/iosxe' $ terraform state replace-provider netascode/iosxe CiscoDevNet/iosxe # Generate a Terraform Resource Graph $ terraform graph | dot -Tpng > terra-iosxe-graph.png $ terraform graph | dot -Tsvg > terra-iosxe-graph.svg # Terraform commands running with CLI variables $ terraform plan -var="hostname=csr1000v-2" $ terraform apply -var="hostname=csr1000v-2" $ terraform apply -var='vrfs=["VRF_A","VRF_B"]' # Terraform commands running with variables files $ terraform plan -var-file="dev.tfvars" $ terraform apply -var-file="dev.tfvars" $ terraform apply -var-file="terraform.tfvars.json" # Terraform commands running with environment variables $ TF_VAR_hostname='csr1000v-1' terraform plan $ TF_VAR_hostname='csr1000v-1' terraform apply -auto-approve # Generate JSON format of terraform.tfvars of inputs $ terraform-docs tfvars json . # Terraform command provides an interactive console terraform console
The Terraform language uses the following types for its values:
Reference: https://www.terraform.io/language/expressions/types
Terraform loads variables in the following order, with later sources taking precedence over earlier ones:
Reference: https://www.terraform.io/language/values/variables
Reference: https://www.terraform.io/language/expressions/for
Reference: https://www.terraform.io/language/meta-arguments/for_each
Reference: https://www.terraform.io/language/meta-arguments/count
Checkout my loopback_interfaces.tf
and vrf.tf
inside nac_iosxe folder where I have used these loops.
A module is a container for multiple resources that are used together. Modules can be used to create lightweight abstractions, so that you can describe your infrastructure in terms of its architecture, rather than directly in terms of physical objects.
Reference: https://www.terraform.io/language/modules/develop
Checkout the modules in modules
directory, I have created inside nac_iosxe folder, I have only created two BGP modules for testing as this is only a basic repository, you may create more.
Owner
Contributors
Categories
Products
Application Centric Infrastructure (ACI)IOS XEProgramming Languages
HCLLicense
Code Exchange Community
Get help, share code, and collaborate with other developers in the Code Exchange community.View Community