Terraform
Overview
  • Introduction
  • Dev Setup
  • NX-API Overview
  • NX-API Python
  • Ansible NXOS
  • pyATS
  • NetDevOps
  • Terraform
  • Bonus: Postman
  • Bonus: YANG

Terraform

Terraform is an open-source infrastructure as code software tool created by HashiCorp. It allows users to define and provision data center infrastructure using a high-level configuration language known as HashiCorp Configuration Language (HCL) or optionally JSON. It is used to manage cloud services, such as AWS, Azure, Google Cloud, and many others, as well as on-premises infrastructure. Terraform enables users to create, change, and improve infrastructure safely and predictably. It manages external resources (such as public cloud infrastructure, private cloud infrastructure, network appliances, software as a service, and platform as a service) with a declarative configuration language. Terraform is designed to automate the provisioning of infrastructure, making it easier to manage complex environments and ensuring that infrastructure is consistent and reproducible. Terraform Overview

Key Features

  • Infrastructure as Code (IaC): Define infrastructure using code, enabling version control and collaboration.
  • Provider Ecosystem: Supports a wide range of providers, allowing management of various cloud and on-premises resources.
  • State Management: Maintains a state file to track resource changes and ensure consistency.
  • Execution Plans: Generates execution plans to preview changes before applying them.
  • Modular Design: Supports reusable modules for organizing and sharing configurations.
  • Dependency Management: Automatically handles dependencies between resources.

Terraform State

One key benefits of using Terraform is its ability to manage the state of your infrastructure. Terraform maintains a state file that represents the current state of your infrastructure. This state file is used to track the resources that Terraform manages, including their attributes and relationships. The state file is crucial for Terraform's operation, as it allows Terraform to determine what changes need to be made to your infrastructure when you run commands like `terraform apply` or `terraform plan`. This is critical for large scale deployments. This allows Terraform to understand what has changed in the infrastructure definition and what actions need to be taken to bring the actual infrastructure in line with the desired state defined in your Terraform configuration files.

This plays a key role in Infrastructure as Code (IaC) practices, as it allows teams to collaborate on infrastructure changes, track modifications over time, and ensure that the infrastructure is always in a known and consistent state. The state file can be stored locally or remotely, depending on your needs. Remote state storage is often used in team environments to ensure that all team members have access to the same state file and can collaborate effectively. For private enterprises the storage of the state file is often accomplished inside a private GIT server or pipeline execution file (e.g. Jenkins) where the state file is carefully managed, backed up and secured.

For this reason Terraform isn't used in "procedural" automation. It is not used to run a series of commands sequentially to achieve a goal, but rather to define the desired state of the infrastructure and let Terraform handle the details of how to achieve that state.

Cisco and Terraform

Cisco has embraced Terraform as a key tool for managing its infrastructure and services. By integrating Terraform with Cisco's cloud and networking solutions, users can automate the deployment and management of Cisco resources in a consistent and repeatable manner.

To facility the use of Terraform with Cisco products, Cisco provides a range of Terraform providers and modules that enable users to interact with Cisco's cloud services, networking devices, and other infrastructure components. These providers allow users to define and manage Cisco resources using Terraform's declarative configuration language, making it easier to automate the provisioning and management of Cisco infrastructure.

All the Cisco Terraform providers and modules are available on the Terraform Registry You can find the complete list of available providers and modules on the Terraform Module registry

These providers and modules cover a wide range of Cisco products and services, including:
  • Cisco ACI
  • Cisco DNA Center
  • Cisco Meraki
  • Cisco Cloud Services
  • Cisco Webex
  • And many more...

Terraform NXOS Provider

The Terraform NXOS provider is a plugin that allows users to manage Cisco Nexus devices using Terraform. It provides a declarative way to define and manage the configuration of Cisco Nexus switches, enabling users to automate the provisioning and management of their network infrastructure.

The NXOS provider supports a wide range of Cisco Nexus features, including VLANs, interfaces, routing protocols, access control lists (ACLs), and more. The NXOS provider talks to the Nexus devices using the NX-API, which is a RESTful API. In similar fashion to ACI, Cisco has developed a data model known as DME. This model is used to represent the configuration and state of the Nexus devices, allowing users to interact with the devices in a consistent and predictable manner.

The DME model is similar to the ACI model, but it is specifically designed for Cisco Nexus devices. It provides a structured way to represent the configuration and state of the devices when compared to the traditional CLI-based configuration.

The easiest way to understand the DME model is to use the NX-API Sandbox, which is a web-based tool that allows users to explore the DME model and interact with the Nexus devices using the NX-API. The NX-API Sandbox provides a graphical interface to browse the DME model, view the available resources, and interact with the devices using the NX-API. The following image shows the NX-API Sandbox interface:

Terraform Overview

Provider Documentation

The provider documentation is available and provides detailed information on how to use the NXOS provider, including including all available resources, data sources and examples. NXOS Provider Documentation