Multi-Version Support in Terraform Provider for Cisco IOS-XR & 25.1X support - #323
Open
hayibrah wants to merge 8 commits into
Open
Multi-Version Support in Terraform Provider for Cisco IOS-XR & 25.1X support #323hayibrah wants to merge 8 commits into
hayibrah wants to merge 8 commits into
Conversation
hayibrah
marked this pull request as draft
March 16, 2026 16:32
hayibrah
force-pushed
the
feature/muli-iosxr-version-support
branch
3 times, most recently
from
March 17, 2026 02:24
ce48e57 to
91f61b2
Compare
hayibrah
force-pushed
the
feature/muli-iosxr-version-support
branch
2 times, most recently
from
March 17, 2026 14:29
f4f984c to
8cf4ff3
Compare
hayibrah
force-pushed
the
feature/muli-iosxr-version-support
branch
from
March 17, 2026 14:47
8cf4ff3 to
63c980f
Compare
hayibrah
marked this pull request as ready for review
March 17, 2026 15:12
IOS-XR 25.1 version support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
The provider now supports multiple IOS-XR versions (e.g., 24.4, 25.2) with intelligent version-aware validation that:
Key Changes
1. Automatic IOS-XR Version Detection (Optional iosxr_version)
The provider now automatically detects IOS-XR version from devices via gNMI when
iosxr_versionis not specified:Features:
/Cisco-IOS-XR-cli-cfg:clito extract version from CLI config headersync.Map) - no redundant queries within a runiosxr_versionif detection fails2. Unified Validation (3 → 1 Function)
Replaces three separate validation calls. Only generated when resource has version differences.
3. Direct Registration (Removed init() Functions)
Resources and datasources are now registered directly in provider.go instead of using init() functions.
4. YANG-Based Range Constraints
Integer ranges automatically extracted from YANG models per version:
endpoint_default_probe_tx_intervalrange: 30000-15000000endpoint_default_probe_tx_intervalrange: 3300-15000000Configuration Examples
Provider Setup
Example 1: Version-Specific Ranges
Example 2: Removed Field
Example 3: Added Field
Example 4: Legacy Resource
How It Works
Validation Flow
iosxr_versionfrom configuration (optional - auto-detected if not set)Validation Only When Needed
Validation code is only generated if a resource has:
AddedInVersionorRemovedInVersionVersionRangesacross versionsLegacyin any versionZero overhead for resources without version differences.
Architecture
Code Organization
Definition File Structure
Base Version (24.4/crypto.yaml)
Higher Version (25.2/crypto.yaml)
Generated Model Structure
Generated Resource Structure
Real-World Use Cases
Use Case 1: Performance Measurement with Different Ranges
The
endpoint_default_probe_tx_intervalfield has different valid ranges in different IOS-XR versions:YANG Model for Version 24.4:
YANG Model for Version 25.2:
Terraform Configuration:
Use Case 2: Crypto with Version-Specific Fields
Version 24.4 Configuration:
Version 25.2 Configuration:
Use Case 3: Multiple Devices with Different Versions
How to Add Version-Specific Fields
Step 1: Add Field to Higher Version Definition
Create or edit
gen/definitions/25.2/resource_name.yaml:Step 2: Mark Field as Legacy (Removed)
Step 3: Mark Entire Resource as Legacy
Step 4: Regenerate
cd /Users/hayibrah/GolandProjects/terraform-provider-iosxr go generateThe generator will:
Benefits
Automatic Version Detection
iosxr_versionis optional. If omitted, the provider auto-detects the version from each device via gNMI by querying/Cisco-IOS-XR-cli-cfg:cliand parsing the CLI config header (!! IOS XR Configuration 24.4). Results are cached in-memory (sync.Map) per device for the duration of the Terraform run.Accepted format:
"24.4","25.2"—ParseVersion()inhelpersis the single source of truth for validation and conversion to internal format.Auto-Detection
Explicit Version
Detection Failure
If auto-detection fails, the provider raises an error with guidance to set
iosxr_versionexplicitly. Supported versions:24.4,25.2.✅ Zero Configuration - auto-detected per device
✅ Cached - one gNMI query per device per run, thread-safe
✅ Fresh - re-detected on every
terraform plan/terraform apply