Study guide

9.3 Infrastructure as Code: Terraform and Ansible Automation for PAN-OS

Palo Alto Networks Certified Next-Generation Firewall Engineer Exam

Track your progress as you read

Finished sections get a check mark.

1 Chapter 1: Device Deployment & Architecture

1.1 Platform Selection & Sizing: Hardware, VM-Series, and Cloud NGFW Form Factors 1.2 Base PAN-OS 11.x System Settings, Management Interfaces, and Service Routes 1.3 Interface Types, Zone Topologies, and Virtual Wire Configurations 1.4 Site-to-Site VPN Tunnels: IPSec, GRE, and Quantum-Resistant Cryptography

2 Chapter 2: Routing, VRFs, and Virtual Routers

2.1 Virtual Routers and VRF Architecture in PAN-OS 11.x 2.2 Static Routing, BGP, and OSPF Configuration & Failover 2.3 Policy-Based Forwarding (PBF) and Path Monitoring

3 Chapter 3: NAT and High Availability Designs

3.1 Source, Destination, and Twice-NAT Policy Configurations 3.2 High Availability Active/Passive Architecture and State Synchronization 3.3 High Availability Active/Active Architecture and HA Clustering

4 Chapter 4: Panorama Management & Policy Hierarchy

4.1 Panorama Architecture: Collector Groups, Log Collectors, and Device Registration 4.2 Templates and Template Stacks Configuration 4.3 Device Groups, Shared Rulestacks, and Policy Hierarchy

5 Chapter 5: Strata Cloud Manager and AIOps

5.1 Strata Cloud Manager (SCM) Architecture and Cloud-Delivered Management 5.2 SCM Rulestacks, Folder Hierarchies, and Unified Policy Management 5.3 AIOps for NGFW: Telemetry, Proactive Best-Practice Audits, and Operational Insights

6 Chapter 6: Security Profiles and Content Inspection

6.1 Antivirus, Anti-Spyware, and DNS Security Profiles 6.2 Vulnerability Protection, Custom Signatures, and Threat Exceptions 6.3 URL Filtering, Advanced WildFire Analysis, and Inline Deep Learning

7 Chapter 7: Decryption Inspection & Policy

7.1 SSL Forward Proxy Architecture and Internal Certificate Authority Trust 7.2 SSL Inbound Inspection for Internal Web Servers 7.3 Decryption Exclusions, HSM Integration, and Troubleshooting Decryption Failures

8 Chapter 8: User Identity and GlobalProtect Remote Access

8.1 User-ID Architecture, Agentless/Agent Deployment, and Cloud Identity Engine (CIE) 8.2 GlobalProtect Portals, Gateways, and Authentication Methods (SAML, MFA) 8.3 Host Information Profile (HIP) Checks and Endpoint Security Enforcement

9 Chapter 9: Cloud NGFW, Automation, and API Integration

9.1 Cloud NGFW for AWS and Azure Architectures (GWLB and VWAN) 9.2 XML and REST API Automation with Palo Alto Networks Firewalls 9.3 Infrastructure as Code: Terraform and Ansible Automation for PAN-OS 9.4 CN-Series, AI Runtime Security, and Edge Deployment Options

10 Chapter 10: Virtual Systems, Logging, and Operational Monitoring

10.1 Virtual Systems (VSYS), Logical Routers, and Inter-VSYS Routing 10.2 Logging Architecture: Strata Logging Service, Log Forwarding, and Collectors 10.3 Application Command Center (ACC), Dashboards, and Custom Reporting 10.4 Explicit and Transparent Web Proxy on PAN-OS

9.3 Infrastructure as Code: Terraform and Ansible Automation for PAN-OS

Key Takeaways Explain This Topic AI

The official paloaltonetworks/panos Terraform provider allows security engineers to define PAN-OS security zones, objects, and policies declaratively in HashiCorp HCL.

The Ansible paloaltonetworks.panos collection provides task-based automation modules for configuration state management, network object creation, and automated policy commits.

GitOps pipelines use Git repositories as the single source of truth for firewall policy, automatically validating, testing, and deploying changes via CI/CD workflows.

Automated policy validation in CI/CD pipelines runs static analysis to catch shadow rules, overly permissive wildcard entries, and syntax errors prior to pushing configuration to production firewalls.

Last updated: July 2026

  • 9.3 Infrastructure as Code: Terraform and Ansible Automation for PAN-OS
  • Infrastructure as Code (IaC) for PAN-OS

Managing firewall configurations manually via the web GUI or CLI creates operational bottlenecks, configuration drift, and potential security gaps across enterprise hybrid cloud environments. Infrastructure as Code (IaC) applies software engineering best practices to network security, treating security policies, network interfaces, virtual routers, security zones, and address objects as version-controlled, auditable code artifacts.

Terraform Automation with the paloaltonetworks/panos Provider

HashiCorp Terraform is a leading declarative IaC tool that enables security engineers to provision and manage Palo Alto Networks firewalls and Panorama using HashiCorp Configuration Language (HCL) .

Provider Setup and Authentication

The official Terraform provider is maintained by Palo Alto Networks ( paloaltonetworks/panos ). Provider configuration requires firewall hostname/IP details and API credentials: terraform {

  • required_providers {
  • panos = {
  • source = "paloaltonetworks/panos"
  • version = "~> 1.11.0"
  • }
  • }
  • }
  • provider "panos" {
  • hostname = var.panos_hostname
  • api_key = var.panos_api_key
  • }
  • Declarative Resource Provisioning

Terraform resources declare the desired end state of firewall objects and security rules. Terraform compares this declared state against its terraform.tfstate tracking file and the live firewall state to generate execution plans ( terraform plan ): resource "panos_address_object" "web_server" {

  • name = "Web-Server-01"
  • value = "10.0.2.100"
  • description = "Production Web Server"
  • comment = "Managed via Terraform"
  • }
  • resource "panos_security_rule" "allow_web" {
  • name = "Allow-Inbound-Web"
  • source_zones = ["untrust"]
  • source_addresses = ["any"]
  • destination_zones = ["trust"]
  • destination_addresses = [panos_address_object.web_server.name]
  • applications = ["web-browsing", "ssl"]
  • services = ["application-default"]
  • action = "allow"
  • }
  • Candidate vs. Committed State in Terraform

By default, creating or modifying resources with terraform apply pushes changes to the PAN-OS Candidate Configuration . The panos provider can be configured with commit options (e.g., commit = true on provider or resource level, or using explicit panos_commit resources) to automatically execute firewall commits upon state application. Furthermore, remote state backends (such as AWS S3 with DynamoDB locking) ensure team collaboration without state collision or race conditions.

Ansible Automation with paloaltonetworks.panos

While Terraform excels at declarative infrastructure lifecycle management, Ansible provides procedural, task-driven configuration management, compliance auditing, and workflow orchestration.

The paloaltonetworks.panos Collection

Palo Alto Networks provides a dedicated Ansible collection available on Ansible Galaxy ( paloaltonetworks.panos ). It includes specialized modules for PAN-OS operations:

panos_address_object : Manage address objects and groups.

panos_security_rule : Create, update, or remove security policy rules.

panos_commit : Execute candidate configuration commits with optional description and filter options.

panos_type_cmd : Run raw XML API commands for custom status reporting or maintenance operations.

  • Example Ansible Playbook ---
  • name: Automate PAN-OS Security Rule Deployment
  • hosts: firewalls
  • connection: local
  • gather_facts: false

tasks:

- name: Create Database Server Address Object

paloaltonetworks.panos.panos_address_object:

  • provider: "{{ panos_provider }}"
  • name: "DB-Server-Primary"
  • value: "192.168.10.50"
  • description: "Primary DB Host"

- name: Ensure Database Access Rule Exists

paloaltonetworks.panos.panos_security_rule:

  • provider: "{{ panos_provider }}"
  • rule_name: "Allow-App-to-DB"
  • source_zone: ["trust"]
  • destination_zone: ["db-zone"]
  • source_ip: ["any"]
  • destination_ip: ["DB-Server-Primary"]
  • application: ["mysql"]
  • action: "allow"
  • commit: true
  • GitOps Deployment Pipelines for Firewall Policy

GitOps leverages Git repositories as the single source of truth for firewall security policy declarations. Any modification to security policies must follow a pull request (PR) code review and CI/CD automated validation workflow before impacting production firewalls.

GitOps Pipeline Architecture

Developer / Security Engineer Work: Engineer creates a new branch, adds/modifies rule definitions in YAML or HCL format, and opens a Pull Request (PR).

CI/CD Static Linting & Syntax Check: The CI pipeline (e.g., GitHub Actions, GitLab CI) triggers automatically to check HCL/YAML syntax, validate JSON schemas, and run static security rules.

Automated Dry-Run ( plan / --check ): CI executes terraform plan or ansible-playbook --check against a sandbox firewall to generate a diff report attached directly to the PR comments.

Peer Review & Security Approval Gate: Senior security architects review the proposed rule change, verifying business justification and compliance requirements.

Merge & Automated Deployment: Merging the PR to main triggers the CD pipeline, executing terraform apply or Ansible playbooks against Panorama / production firewalls, followed by an automated commit.

Post-Deployment Verification: Automated API health checks verify session tables, routing tables, and threat log flow to validate policy efficacy.

CI/CD Automated Policy Validation & Shift-Left Security

Integrating automated policy validation into CI/CD pipelines enforces governance before changes enter candidate configurations:

Shadow Rule Detection: Automated linters analyze rule order to ensure new rules are not rendered useless by pre-existing broad catch-all rules.

Any/Any Inspection: Pipeline scripts reject PRs containing overly permissive rules (e.g., source any , destination any , application any , action allow ).

Required Metadata: Verification scripts enforce mandatory rule fields such as owner tags, ticket reference numbers, and log forwarder profile bindings ( log_setting ).

Tool Comparison Matrix

  • Capability / Feature Terraform ( panos Provider) Ansible ( paloaltonetworks.panos )
  • Automation Paradigm Declarative (Desired End State) Procedural / Task-Based Execution
  • State File Tracking Yes ( terraform.tfstate ) No (Queries live API directly)

Primary Use Case Infrastructure provisioning & state enforcement Configuration management, orchestration & compliance checks

  • Change Preview terraform plan (Detailed diff) ansible-playbook --check (Dry-run mode)
  • Drift Remediation Automatic (Reverts unauthorized manual GUI changes) Module-dependent task idempotency

GitOps Integration Native integration with CI/CD runners Native execution via Ansible Automation Platform / AWX

Loading diagram... GitOps CI/CD Firewall Policy Deployment Pipeline