This guide provides detailed instructions for migrating from Azion Terraform Provider v1.x (API v3) to v2.0 (API v4). Follow the steps below to ensure a smooth transition.
Migration Overview
Terraform Provider v2.0 represents a major release that migrates to Azion API v4. This version introduces new resources and removes deprecated ones to align with the new API architecture.
Key Changes
| Aspect | v1.x (API v3) | v2.0 (API v4) |
|---|---|---|
| API Version | Azion API v3 | Azion API v4 |
| Domain Management | azion_domain resource | azion_workload and azion_workload_deployment resources |
| Origin Management | azion_edge_application_origin resource | azion_connector resource |
| Functions | azion_edge_function resource | azion_function resource |
| Custom Pages | Not available | azion_custom_page resource |
Version Compatibility
| Terraform Provider Version | API Version | Status |
|---|---|---|
| 1.41.0 and earlier | API v3 | Deprecated |
| 2.0.0 and later | API v4 | Current |
Before You Begin
Before starting the migration process, ensure you have completed the following preparations.
Prerequisites
- Terraform: Version 1.0 or later installed
- Azion Account: Valid account with API v4 access
- Personal Token: A valid personal token with appropriate permissions
- Backup: A complete backup of your current Terraform state and configurations
Backup Your Configuration
Create a backup of your current Terraform configuration and state files before making any changes:
# Create a backup directorymkdir -p ~/terraform-backup
# Copy your configuration filescp -r ./your-terraform-project ~/terraform-backup/
# Backup the state file (if using local state)cp terraform.tfstate ~/terraform-backup/cp terraform.tfstate.backup ~/terraform-backup/ 2>/dev/null || true
# If using remote state, download a local copyterraform state pull > ~/terraform-backup/terraform.tfstateVersion Pinning
If you need to remain on v1.x temporarily, pin the provider version:
terraform { required_providers { azion = { source = "aziontech/azion" version = "1.41.0" } }}Version 1.41.0 and earlier no longer receive updates or bug fixes. Plan your migration to v2.0 as soon as possible.
Breaking Changes
This section details the breaking changes between v1.x and v2.0.
Removed Resources
The following resources and data sources have been removed in v2.0:
| Resource | Status | Replacement |
|---|---|---|
azion_domain | Removed | Use azion_workload and azion_workload_deployment |
azion_domains (data source) | Removed | Use azion_workloads data source |
azion_edge_application_origin | Removed | Use azion_connector |
azion_edge_applications_origins (data source) | Removed | Use azion_connectors data source |
Renamed Resources
| v1.x Resource | v2.0 Resource | Notes |
|---|---|---|
azion_edge_function | azion_function | Resource renamed to align with new product naming |
New Resources in v2.0
| Resource | Description |
|---|---|
azion_workload | Manage Azion workloads (replaces domain management) |
azion_workload_deployment | Manage workload deployments |
azion_connector | Manage Azion connectors (replaces origin management) |
azion_custom_page | Manage custom pages |
Unchanged Resources
The following resources remain available with their original names:
| Resource | Description |
|---|---|
azion_edge_application_main_setting | Application main settings |
azion_edge_application_cache_setting | Cache settings |
azion_edge_application_rule_engine | Rules engine |
azion_edge_application_edge_functions_instance | Function instances for applications |
azion_edge_firewall_main_setting | Firewall main settings |
azion_edge_firewall_edge_functions_instance | Function instances for firewall |
azion_intelligent_dns_zone | DNS zones |
azion_intelligent_dns_record | DNS records |
azion_intelligent_dns_dnssec | DNSSEC settings |
azion_network_list | Network lists |
azion_waf_rule_set | WAF rule sets |
azion_digital_certificate | Digital certificates |
azion_environment_variable | Environment variables |
Resource Mapping
This section provides detailed mapping between v1.x and v2.0 resources.
Domain to Workload Mapping
Domain management in v1.x has been replaced by a two-resource model in v2.0:
| v1.x (Domain) | v2.0 (Workload) |
|---|---|
azion_domain | azion_workload + azion_workload_deployment |
azion_domains (data source) | azion_workloads |
Key Differences:
- v1.x: Single
azion_domainresource managed the entire domain lifecycle - v2.0: Separation of concerns with
azion_workload(definition) andazion_workload_deployment(deployment)
Origin to Connector Mapping
Origin management has been replaced by connectors:
| v1.x (Origin) | v2.0 (Connector) |
|---|---|
azion_edge_application_origin | azion_connector |
azion_edge_applications_origins (data source) | azion_connectors |
Key Differences:
- v1.x: Origins were defined within Edge Application contexts
- v2.0: Connectors are standalone resources that provide more flexible integration options
Edge Function to Function Mapping
| v1.x | v2.0 |
|---|---|
azion_edge_function | azion_function |
azion_edge_functions (data source) | azion_functions data source |
Migration Examples
This section provides side-by-side configuration examples for migrating your Terraform resources.
Domain to Workload Migration
v1.x Configuration
terraform { required_providers { azion = { source = "aziontech/azion" version = "1.41.0" } }}
provider "azion" { api_token = var.api_token}
# Domain resource (v1.x)resource "azion_domain" "example" { name = "my-domain" cname_access_only = false digital_certificate = 1234 edge_application = 5678 is_active = true
# Domain name binding domain_name = "example.com"}v2.0 Configuration
terraform { required_providers { azion = { source = "aziontech/azion" version = "2.0.0" } }}
provider "azion" { api_token = var.api_token}
# Workload resource (v2.0)resource "azion_workload" "example" { name = "my-workload"
# Workload configuration options # Refer to the Terraform Registry documentation for full options}
# Workload deployment (v2.0)resource "azion_workload_deployment" "example" { workload_id = azion_workload.example.id
# Deployment configuration # Refer to the Terraform Registry documentation for full options}Origin to Connector Migration
v1.x Configuration
# Edge Application Origin (v1.x)resource "azion_edge_application_origin" "example" { edge_application_id = azion_edge_application_main_setting.example.id
name = "my-origin" origin_type = "single_origin" origin_address = "origin.example.com" origin_protocol = "https" origin_path = "/api" host_header = "origin.example.com"
# Connection settings connection_timeout = 30 read_timeout = 60}v2.0 Configuration
# Connector (v2.0)resource "azion_connector" "example" { name = "my-connector"
# Connector configuration # Refer to the Terraform Registry documentation for full options
# Example configuration origin = { address = "origin.example.com" protocol = "https" path = "/api" }
# Connection settings connection_timeout = 30 read_timeout = 60}Edge Function Migration
v1.x Configuration
# Edge Function (v1.x)resource "azion_edge_function" "example" { name = "my-function" active = true code = file("${path.module}/function.js")
# Function arguments json_args = jsonencode({ key = "value" })}v2.0 Configuration
# Function (v2.0)resource "azion_function" "example" { name = "my-function" active = true code = file("${path.module}/function.js")
# Function arguments json_args = jsonencode({ key = "value" })}Complete Example: Application with Workload
v1.x Configuration
terraform { required_providers { azion = { source = "aziontech/azion" version = "1.41.0" } }}
provider "azion" { api_token = var.api_token}
# Edge Applicationresource "azion_edge_application_main_setting" "app" { name = "my-application"}
# Originresource "azion_edge_application_origin" "origin" { edge_application_id = azion_edge_application_main_setting.app.id name = "my-origin" origin_type = "single_origin" origin_address = "origin.example.com"}
# Domainresource "azion_domain" "domain" { name = "my-domain" edge_application = azion_edge_application_main_setting.app.id domain_name = "example.com"}
# Edge Functionresource "azion_edge_function" "func" { name = "my-function" active = true code = file("${path.module}/function.js")}v2.0 Configuration
terraform { required_providers { azion = { source = "aziontech/azion" version = "2.0.0" } }}
provider "azion" { api_token = var.api_token}
# Edge Application (unchanged)resource "azion_edge_application_main_setting" "app" { name = "my-application"}
# Connector (replaces origin)resource "azion_connector" "connector" { name = "my-connector" # Connector configuration}
# Workload (replaces domain)resource "azion_workload" "workload" { name = "my-workload"}
# Workload deploymentresource "azion_workload_deployment" "deployment" { workload_id = azion_workload.workload.id # Deployment configuration}
# Function (renamed)resource "azion_function" "func" { name = "my-function" active = true code = file("${path.module}/function.js")}State Migration Steps
Follow these steps to migrate your Terraform state from v1.x to v2.0.
Step 1: Update Provider Version
Update your Terraform configuration to use Provider v2.0:
terraform { required_providers { azion = { source = "aziontech/azion" version = "2.0.0" } }}Step 2: Initialize the New Provider
Run Terraform init to download the new provider:
terraform init -upgradeStep 3: Remove Deprecated Resources from State
Remove the deprecated resources from your Terraform state:
# Remove domain resourcesterraform state rm azion_domain.example
# Remove origin resourcesterraform state rm azion_edge_application_origin.example
# Remove edge function resources (will be recreated as azion_function)terraform state rm azion_edge_function.exampleStep 4: Update Configuration Files
Update your .tf files with the new resource configurations following the examples in the Migration Examples section.
Step 5: Import New Resources
Import your existing resources into the new resource types:
# Import workloadsterraform import azion_workload.example <workload_id>
# Import connectorsterraform import azion_connector.example <connector_id>
# Import functionsterraform import azion_function.example <function_id>Step 6: Verify the Plan
Run a plan to verify the expected changes:
terraform planReview the output carefully to ensure:
- No resources will be unexpectedly destroyed
- New resources will be created correctly
- Resource attributes are mapped correctly
Step 7: Apply the Changes
Apply the changes:
terraform applyTroubleshooting
This section addresses common issues encountered during migration.
Common Errors and Solutions
Error: Provider Version Conflict
Error: Failed to query available provider packagesCould not retrieve the list of available versions for provider aziontech/azionSolution: Ensure you’re specifying the correct source and version. Run:
terraform init -upgradeError: Resource Type Not Found
Error: Invalid resource typeon main.tf line 10:10: resource "azion_domain" "example" {The provider aziontech/azion does not support resource type "azion_domain".Solution: This resource has been removed in v2.0. Replace with azion_workload and azion_workload_deployment resources.
Error: State Migration Failed
Error: Error refreshing state: azion_edge_application_origin.example:resource not foundSolution: The resource was already removed or doesn’t exist. Remove it from state:
terraform state rm azion_edge_application_origin.exampleError: Import Not Found
Error: Cannot import non-existent remote objectSolution: Ensure the resource ID you’re importing exists in API v4. Some resources from API v3 may have different IDs in API v4. Check the Azion Console to find the correct resource IDs.
Additional Resources
- Terraform Provider v2.0 Documentation
- Terraform Provider v1.x Documentation (Legacy)
- Azion API v4 Documentation
- Terraform Registry - Azion Provider
Getting Help
If you encounter issues during migration:
- Review the Troubleshooting section
- Check the Terraform Registry documentation
- Contact Azion Support through the Support Portal
- Visit the Azion Community for additional resources