Study guide
16.3 Infrastructure as Code (IaC) Principles with Terraform in Enterprise Networks
Cisco ENCOR 350-401 CCNP Enterprise Core
Track your progress as you read
Finished sections get a check mark.
1 Introduction & Exam Overview
0.1 Cisco 350-401 ENCOR Exam Logistics, Blueprint Structure, and Certification Paths 0.2 Preparation Strategy, Lab Environment Setup, and Practical Test Pacing
2 Enterprise Campus Architecture and High Availability
1.1 Enterprise Network Design: Two-Tier, Three-Tier, Fabric, and Cloud Architectures 1.2 High Availability Architecture: Device Redundancy, FHRPs, and Stateful Switchover (SSO) 1.3 Quality of Service (QoS) Architecture, Classification, Queuing, and Configuration Interpretation
3 Cisco Software-Defined Architecture: SD-WAN and SD-Access
2.1 Cisco Catalyst SD-WAN: Control, Management, and Data Planes 2.2 Cisco SD-Access Architecture: Control Plane, Data Plane, and Fabric Node Roles 2.3 SD-Access Campus Interoperability: Integrating Traditional Networks with Fabric
4 Device and Network Virtualization Technologies
3.1 Device Virtualization: Type 1/2 Hypervisors, Virtual Machines, and Virtual Switching 3.2 Data Path Virtualization: VRF-Lite, GRE Tunneling, and IPsec VPN Fundamentals 3.3 Network Virtualization Overlays: LISP and VXLAN Encapsulation Mechanics
5 Layer 2 Infrastructure: Trunking, EtherChannel, and Spanning Tree
4.1 802.1Q Trunking, Native VLAN, and Dynamic Trunking Protocol Troubleshooting 4.2 EtherChannel Bundling: Static, LACP, and PAgP Implementation and Verification 4.3 Spanning Tree Architecture: RSTP, MST, and STP Protection Mechanisms
6 Layer 3 Routing: OSPF Multi-Area and Protocol Comparison
5.1 Enterprise Routing Principles: Distance Vector vs. Link-State, EIGRP, and OSPF 5.2 OSPFv2 and OSPFv3 Multi-Area Architecture: LSAs, Area Types, and Summarization 5.3 Policy-Based Routing (PBR) Architecture, Configuration, and Route-Maps
7 Exterior Routing: BGP Peering and Path Selection
6.1 External BGP (eBGP) Peering, States, Neighbor Adjacencies, and Timers 6.2 BGP Path Attributes and the Step-by-Step Best Path Selection Algorithm
8 IP Services and First-Hop Redundancy
7.1 Time Synchronization: Network Time Protocol (NTP) and Precision Time Protocol (PTP) 7.2 Network Address Translation: Static NAT, Dynamic NAT, and PAT/Overload 7.3 First Hop Redundancy Protocols: HSRP and VRRP Implementation and Failover
9 IP Multicast Architecture and Protocols
8.1 Multicast Addressing, IGMPv2/v3 Host Membership, and the RPF Check 8.2 Protocol Independent Multicast Sparse Mode (PIM-SM) and Rendezvous Point Discovery 8.3 Anycast RP with MSDP, Source-Specific Multicast (SSM), and Bidirectional PIM
10 Network Diagnostics, Monitoring, and Telemetry
9.1 Network Diagnostic Tools: Conditional Debugging, Traceroute, SNMPv3, and Syslog Logging 9.2 Flexible NetFlow (FNF) Architecture: Flow Records, Exporters, and Monitors 9.3 Switched Port Analyzer: Local SPAN, Remote SPAN (RSPAN), and Encapsulated RSPAN (ERSPAN)
11 Performance Monitoring and Model-Driven Assurance
10.1 IP Service Level Agreements (IP SLA) Probes, Responder, and Route Tracking 10.2 Cisco Catalyst Center: Assurance Dashboards, AI Analytics, and Machine Reasoning Workflows 10.3 Model-Driven Telemetry and Programmable Interfaces: NETCONF and RESTCONF Verification
12 Device Access Control and AAA Architecture
11.1 Device Line Protection: Console, Aux, VTY, Local Authentication, and Privilege Levels 11.2 AAA Architecture: Comparing RADIUS vs. TACACS+ and Method List Configuration
13 Infrastructure Security: ACLs, CoPP, and API Security
12.1 IPv4 and IPv6 Access Control Lists (ACLs): Standard, Extended, and Named Rules 12.2 Control Plane Policing (CoPP): Protecting the Route Processor with MQC 12.3 REST API Security: Token Authentication, TLS Transport, and Rate Limiting
14 Enterprise Network Security Design: ISE, TrustSec, and MACsec
13.1 Endpoint Security Architecture: 802.1X, Cisco ISE Posture, and Profiling 13.2 Next-Generation Firewalls (FTD) and Enterprise Threat Defense Design 13.3 Cisco TrustSec (Security Group Tags) and MACsec (802.1AE) Layer 2 Encryption
15 Network Automation Fundamentals: Python, JSON, and YANG
14.1 Python Fundamentals for Network Engineers: Data Types, Control Flow, and Libraries 14.2 JSON Data Encoding: Syntax, Formatting Rules, and Python Serialization 14.3 YANG Data Modeling: Modules, Tree Structures, and Data Representation
16 Controller REST APIs and RESTCONF Implementation
15.1 Cisco Catalyst Center Intent APIs and Authentication Workflows 15.2 Cisco Catalyst SD-WAN Manager (vManage) REST APIs and Device Interaction 15.3 RESTCONF Protocol Operations: HTTP Verbs, Datastores, and Response Codes
17 Event-Driven Automation and Infrastructure Orchestration
16.1 Cisco Embedded Event Manager (EEM) Applet Architecture and Event Detectors 16.2 Configuration Management: Comparing Ansible, Puppet, Chef, and SaltStack 16.3 Infrastructure as Code (IaC) Principles with Terraform in Enterprise Networks
16.3 Infrastructure as Code (IaC) Principles with Terraform in Enterprise Networks
Key Takeaways Explain This Topic AI
Infrastructure as Code (IaC) treats physical and virtual infrastructure definitions as software code, enabling version control, collaborative peer review, automated validation pipelines, and reproducible environment deployments.
Terraform is a declarative IaC tool from HashiCorp (source-available under the Business Source License since 2023; OpenTofu is the open-source fork) that uses HashiCorp Configuration Language (HCL) and provider plugins to manage multi-vendor infrastructure.
The core Terraform operational lifecycle follows a four-stage workflow: initialization (terraform init), execution planning (terraform plan), change application (terraform apply), and resource retirement (terraform destroy).
Terraform state (terraform.tfstate) maps HCL resources to real infrastructure; remote backends add locking (for example, an S3 lock file) to stop concurrent writes, and terraform plan exposes configuration drift.
In enterprise network environments, Terraform providers interface with Cisco IOS-XE devices, Cisco Catalyst Center, Cisco SD-WAN Manager, and Cisco ACI to provision VLANs, routing protocols, VRFs, and fabric policies programmatically.
Last updated: October 2026
Infrastructure as Code (IaC) Principles with Terraform in Enterprise Networks
Historically, network infrastructure state resided solely inside physical switch volatile memory, NVRAM, and startup configuration registers. If a catastrophic hardware failure destroyed a datacenter switch or an administrator inadvertently corrupted a configuration, disaster recovery required searching for stale text backups and manually pasting CLI commands into terminal emulators. Infrastructure as Code (IaC) transforms this model by managing enterprise network infrastructure using the same rigor, tools, and automated pipelines applied to modern software engineering.
Core Principles of Infrastructure as Code (IaC)
IaC is built upon four foundational operational tenets:
Declarative Infrastructure Definitions: Engineers specify the desired end-state of infrastructure constructs (e.g., "VLAN 100 must exist with name USERS and an active SVI") rather than writing procedural scripts detailing individual CLI commands. The orchestration engine automatically calculates the operations required to transition the real-world infrastructure to the declared state.
Version Control as the Single Source of Truth: All infrastructure definitions reside in version control repositories (such as Git). Changes undergo collaborative peer review through pull or merge requests and automated linting before deployment to production environments.
Automated Validation and Testing: Continuous Integration and Continuous Deployment (CI/CD) pipelines automatically validate configurations for syntax errors, address allocation conflicts, and security policy compliance before changes touch physical hardware.
Repeatability and Determinism: Complete enterprise topologies—including access switches, distribution pairs, and core routers—can be cloned, deployed, or torn down identically across development, staging, and production environments without configuration divergence. +-------------------------------------------------------------------------+
- | Terraform Core Architecture |
- +-------------------------------------------------------------------------+
- | USER CONFIGURATION (.tf files in HCL) |
- | - Providers - Variables - Resources - Outputs |
- +-------------------------------------------------------------------------+
- |
- v
- +-------------------------------------------------------------------------+
- | TERRAFORM CORE ENGINE |
- | - Dependency Graph Generator (Directed Acyclic Graph) |
- | - State Reconciliation & Drift Analysis Engine |
- | - Lifecycle Orchestrator (init -> plan -> apply -> destroy) |
- +-------------------------------------------------------------------------+
- | ^
- | State Read/Write | Live State Query
- v |
- +----------------------------+ +-----------------------------------+
- | STATE STORAGE | | TERRAFORM PROVIDERS (Plugins) |
- | - Local: terraform.tfstate| | - iosxe (NETCONF / YANG) |
- | - Remote: S3 + lock file | | - catalystcenter (REST APIs) |
- | - State Locking Mechanism | | - sdwan / aci (REST / APIs) |
- +----------------------------+ +-----------------------------------+
- |
- | Target API Calls
- v
- +-------------------------------------------------------------------------+
- | PHYSICAL & SOFTWARE-DEFINED ENTERPRISE INFRASTRUCTURE |
- | - Catalyst 9000 Switches - Catalyst Center - Catalyst SD-WAN |
- +-------------------------------------------------------------------------+
- Terraform Architecture and the Provider Ecosystem
Terraform utilizes a modular, plugin-based architecture comprising two distinct layers:
1. Terraform Core
Terraform Core is the statically compiled binary that serves as the engine for all operations. It reads HashiCorp Configuration Language (HCL) files, parses input variables, evaluates dependencies between resource blocks to construct a Directed Acyclic Graph (DAG), compares desired state against the state file and live infrastructure, and orchestrates the execution sequence.
2. Terraform Providers
Providers are standalone binary plugins that translate Terraform Core's generic CRUD (Create, Read, Update, Delete) resource operations into platform-specific API calls. Providers communicate with Terraform Core over high-performance gRPC remote procedure calls. In enterprise networking, major providers include:
iosxe Provider ( CiscoDevNet/iosxe ): Communicates directly with Cisco IOS XE switches and routers (such as Catalyst 9000 and Catalyst 8000 platforms) using NETCONF over SSH (TCP 830) and YANG models to configure interfaces, VLANs, VRFs, OSPF, and BGP. The device needs netconf-yang enabled.
catalystcenter Provider: Interacts with Cisco Catalyst Center (formerly DNA Center) REST APIs to manage campus fabric sites, provisioning templates, IP address pools, and device onboarding workflows.
sdwan Provider: Interfaces with Cisco Catalyst SD-WAN Manager (vManage) REST APIs to configure centralized control policies, feature templates, and transport VPNs.
aci Provider: Interacts with Cisco Application Centric Infrastructure (ACI) Application Policy Infrastructure Controllers (APIC) to manage Tenants, Bridge Domains, and Application Network Profiles.
The Terraform Operational Lifecycle
Managing network infrastructure with Terraform follows a structured four-stage workflow:
1. terraform init
The initial command executed in any directory containing Terraform code. It scans .tf configuration files, identifies required provider plugins, downloads and installs provider binaries into a local .terraform directory, and initializes the configured remote backend.
2. terraform plan
A read-only speculative execution phase. Terraform queries target infrastructure via provider plugins, compares live state against the local state file and declared .tf configuration code, and outputs a detailed execution plan showing proposed additions ( + ), modifications in-place ( ~ ), and destructions ( - ). Running plan does not alter running network devices.
3. terraform apply
The execution phase. Terraform presents the generated plan to the engineer for interactive approval (or automated execution in CI/CD pipelines via -auto-approve ). Upon confirmation, Terraform Core walks the dependency graph and instructs provider plugins to issue API calls to configure devices. When complete, Terraform records the new state into the state file.
4. terraform destroy
The decommissioning phase. Terraform references the state file to identify all managed resources, generates a reverse-dependency graph, and issues delete API calls to cleanly remove all provisioned infrastructure.
Terraform Lifecycle Phases Reference
Lifecycle Command Operational Scope Live Network Impact State File Operation Primary Operational Purpose
terraform init Local directory & provider plugins None (No network traffic to targets) Initializes backend connection Downloads provider binaries and sets up working environment
terraform plan Core engine, provider APIs, and state None (Strictly read-only query) Refreshes memory cache of state Generates visual diff comparing declared code against live reality
terraform apply Target switches, routers, controllers Active modifications (Create/Update/Delete) Writes updated state to backend Executes API calls to transition network into declared state
terraform destroy Target switches, routers, controllers Active removal (Deletes all managed resources) Removes resource records from state Safely decommissions complete network topology or lab environment
State Management, State Locking, and Drift Detection
Terraform is a stateful orchestration tool. State management is critical to its operation and governance:
The State File ( terraform.tfstate )
Terraform maintains a JSON-formatted state file that maps declarative HCL resources (e.g., resource "iosxe_vlan" "corp_data" ) to real-world infrastructure identifiers (e.g., VLAN ID 100 on switch 10.1.1.1 ). The state file tracks resource attributes, metadata, and dependencies. Without the state file, Terraform cannot distinguish between infrastructure it manages and pre-existing network configurations.
Remote Backends and State Locking
Storing terraform.tfstate on a local workstation creates severe risks in enterprise teams: state loss, credential exposure in unencrypted JSON, and race conditions where multiple engineers run concurrent applies, corrupting state. Enterprise deployments mandate remote backends (such as an AWS S3 bucket, HashiCorp Consul, or HCP Terraform):
Remote Storage: Keeps the state file in a centralized, encrypted, versioned object store.
State Locking: When an apply operation begins, Terraform acquires an exclusive lock through the backend (for example, an S3 lock file enabled with use_lockfile = true ; older S3 configurations used a DynamoDB table, which Terraform now treats as deprecated). If another engineer or CI/CD job attempts to run an apply simultaneously, Terraform rejects the operation until the active lock releases, preventing state corruption.
Drift Detection
Configuration drift occurs when an administrator modifies a device out-of-band using manual CLI commands (e.g., changing an interface description or deleting a VLAN). When terraform plan runs, Terraform refreshes live state via the provider API and compares it to the state file and .tf code. If drift is detected, Terraform generates a plan to restore the live device back to the declared configuration.
State Management Components Comparison
Component / Mechanism Operational Implementation Technical Risk Mitigated Enterprise Best Practice
Local State ( terraform.tfstate ) Default local JSON file in root directory State isolation, merge conflicts, credential exposure Restrict strictly to isolated local sandbox testing
Remote Backend Cloud object storage (S3, GCS, Terraform Cloud) Lost state files, multi-engineer synchronization failure Mandate centralized remote backend with automated versioning
State Locking Backend lock (S3 lock file, legacy DynamoDB table, Consul lock) Race conditions, concurrent write state corruption Enforce mandatory locking on all production remote state backends
State Encryption Server-side encryption (AES-256 / KMS) Cleartext credential leakage in state attributes Enforce customer-managed encryption keys for state storage
Drift Refresh Execution of terraform plan / refresh Undocumented out-of-band manual CLI changes Schedule automated CI/CD drift detection scans daily
HCL Syntax Architecture and Enterprise Network Walkthrough
HashiCorp Configuration Language (HCL) uses structured configuration blocks:
terraform { ... } : Configures global settings, required provider versions, and backend details.
provider "name" { ... } : Establishes connection endpoints, credentials, and transport options.
variable "name" { ... } : Defines input parameters with types ( string , number , list , map ) and defaults.
resource "type" "name" { ... } : Declares the infrastructure component to create and manage.
data "type" "name" { ... } : Queries existing real-world resources without managing their lifecycle.
output "name" { ... } : Exposes computed attributes (such as assigned IP addresses or operational status).
Practical Enterprise Scenario: Provisioning Campus Core Switch with HCL
The following configuration file ( main.tf ) provisions VLANs, a Switched Virtual Interface (SVI), and a BGP routing peer on a Cisco Catalyst core switch using the iosxe provider: terraform {
- required_version = ">= 1.11.0"
- required_providers {
- iosxe = {
- source = "CiscoDevNet/iosxe"
- }
- }
- backend "s3" {
- bucket = "corp-net-terraform-state"
- key = "campus/core-switch-01.tfstate"
- region = "us-east-1"
- use_lockfile = true
- encrypt = true
- }
- }
- provider "iosxe" {
- host = var.switch_ip
- username = var.switch_user
- password = var.switch_password
- }
- variable "switch_ip" {
- type = string
- description = "Management IP address of the core switch"
- default = "10.100.1.1"
- }
- variable "switch_user" {
- type = string
- description = "Administrative username for NETCONF authentication"
- }
- variable "switch_password" {
- type = string
- description = "Administrative password for NETCONF authentication"
- sensitive = true
- }
- # Provision Enterprise Data VLAN
- resource "iosxe_vlan" "engineering_vlan" {
- vlan_id = 200
- name = "ENGINEERING_DATA"
- }
- # Provision Switched Virtual Interface (SVI) Gateway
- resource "iosxe_interface_vlan" "engineering_svi" {
- name = 200
- description = "Default Gateway for Engineering Subnet"
- ipv4_address = "10.200.1.1"
- ipv4_address_mask = "255.255.255.0"
- shutdown = false
- depends_on = [iosxe_vlan.engineering_vlan]
- }
- # Provision the BGP process and a peer to the distribution layer
- resource "iosxe_bgp" "core" {
- asn = "65001"
- }
- resource "iosxe_bgp_neighbor" "dist_pair_peer" {
- asn = iosxe_bgp.core.asn
- ip = "10.200.1.2"
- remote_as = "65002"
- description = "BGP Peering to Distribution Switch 01"
- }
- output "svi_gateway_ip" {
- value = iosxe_interface_vlan.engineering_svi.ipv4_address
- description = "Provisioned SVI Gateway IP Address"
- }
- Configuration Architectural Highlights
Explicit Dependency ( depends_on ): While Terraform automatically builds dependencies based on referenced variables, the depends_on argument explicitly guarantees that iosxe_vlan.engineering_vlan is created on the switch before the SVI iosxe_interface_vlan.engineering_svi . The BGP neighbor shows the implicit form: referencing iosxe_bgp.core.asn makes Terraform create the BGP process first.
Sensitive Variables: The sensitive = true flag protects administrative credentials from being displayed in console plan outputs or CI/CD logs.
NETCONF Transport: The current iosxe provider talks to the switch with NETCONF over SSH (TCP 830), translating HCL resources into YANG-modeled transactions; enable netconf-yang on the device first. Terraform itself needs no agent on the switch, which makes it an agentless tool in the sense of topic 6.7.