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

Aspectv1.x (API v3)v2.0 (API v4)
API VersionAzion API v3Azion API v4
Domain Managementazion_domain resourceazion_workload and azion_workload_deployment resources
Origin Managementazion_edge_application_origin resourceazion_connector resource
Functionsazion_edge_function resourceazion_function resource
Custom PagesNot availableazion_custom_page resource

Version Compatibility

Terraform Provider VersionAPI VersionStatus
1.41.0 and earlierAPI v3Deprecated
2.0.0 and laterAPI v4Current

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:

Terminal window
# Create a backup directory
mkdir -p ~/terraform-backup
# Copy your configuration files
cp -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 copy
terraform state pull > ~/terraform-backup/terraform.tfstate

Version 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:

ResourceStatusReplacement
azion_domainRemovedUse azion_workload and azion_workload_deployment
azion_domains (data source)RemovedUse azion_workloads data source
azion_edge_application_originRemovedUse azion_connector
azion_edge_applications_origins (data source)RemovedUse azion_connectors data source

Renamed Resources

v1.x Resourcev2.0 ResourceNotes
azion_edge_functionazion_functionResource renamed to align with new product naming

New Resources in v2.0

ResourceDescription
azion_workloadManage Azion workloads (replaces domain management)
azion_workload_deploymentManage workload deployments
azion_connectorManage Azion connectors (replaces origin management)
azion_custom_pageManage custom pages

Unchanged Resources

The following resources remain available with their original names:

ResourceDescription
azion_edge_application_main_settingApplication main settings
azion_edge_application_cache_settingCache settings
azion_edge_application_rule_engineRules engine
azion_edge_application_edge_functions_instanceFunction instances for applications
azion_edge_firewall_main_settingFirewall main settings
azion_edge_firewall_edge_functions_instanceFunction instances for firewall
azion_intelligent_dns_zoneDNS zones
azion_intelligent_dns_recordDNS records
azion_intelligent_dns_dnssecDNSSEC settings
azion_network_listNetwork lists
azion_waf_rule_setWAF rule sets
azion_digital_certificateDigital certificates
azion_environment_variableEnvironment 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_domainazion_workload + azion_workload_deployment
azion_domains (data source)azion_workloads

Key Differences:

  • v1.x: Single azion_domain resource managed the entire domain lifecycle
  • v2.0: Separation of concerns with azion_workload (definition) and azion_workload_deployment (deployment)

Origin to Connector Mapping

Origin management has been replaced by connectors:

v1.x (Origin)v2.0 (Connector)
azion_edge_application_originazion_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.xv2.0
azion_edge_functionazion_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 Application
resource "azion_edge_application_main_setting" "app" {
name = "my-application"
}
# Origin
resource "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"
}
# Domain
resource "azion_domain" "domain" {
name = "my-domain"
edge_application = azion_edge_application_main_setting.app.id
domain_name = "example.com"
}
# Edge Function
resource "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 deployment
resource "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:

Terminal window
terraform init -upgrade

Step 3: Remove Deprecated Resources from State

Remove the deprecated resources from your Terraform state:

Terminal window
# Remove domain resources
terraform state rm azion_domain.example
# Remove origin resources
terraform state rm azion_edge_application_origin.example
# Remove edge function resources (will be recreated as azion_function)
terraform state rm azion_edge_function.example

Step 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:

Terminal window
# Import workloads
terraform import azion_workload.example <workload_id>
# Import connectors
terraform import azion_connector.example <connector_id>
# Import functions
terraform import azion_function.example <function_id>

Step 6: Verify the Plan

Run a plan to verify the expected changes:

Terminal window
terraform plan

Review 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:

Terminal window
terraform apply

Troubleshooting

This section addresses common issues encountered during migration.

Common Errors and Solutions

Error: Provider Version Conflict

Error: Failed to query available provider packages
Could not retrieve the list of available versions for provider aziontech/azion

Solution: Ensure you’re specifying the correct source and version. Run:

Terminal window
terraform init -upgrade

Error: Resource Type Not Found

Error: Invalid resource type
on 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 found

Solution: The resource was already removed or doesn’t exist. Remove it from state:

Terminal window
terraform state rm azion_edge_application_origin.example

Error: Import Not Found

Error: Cannot import non-existent remote object

Solution: 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

Getting Help

If you encounter issues during migration:

  1. Review the Troubleshooting section
  2. Check the Terraform Registry documentation
  3. Contact Azion Support through the Support Portal
  4. Visit the Azion Community for additional resources