Troubleshoot the Terraform Provider
Fix Azion Terraform Provider errors about the personal token, provider versions, removed resource types, the state, and imports.
Each section of this page starts from an error that Terraform prints while it works with the Azion Terraform Provider, then gives its cause and its fix. Errors about the personal token and the provider version come first. Errors from a migration to provider v2.0 follow: removed resource types, the state, and imports.
Terraform fails with personal token is required
A Terraform command stops before the provider calls Azion API, with this error:
The provider found no personal token. It reads the token from the AZION_API_TOKEN environment variable or from its api_token argument.
- Set the environment variable: export
AZION_API_TOKENin the terminal that runs Terraform, and leave theprovider "azion"block empty. - Pass the token in the api_token argument: declare a sensitive
api_tokenvariable, set it interraform.tfvars, and passvar.api_tokento the provider. For the files, refer to Provide your personal token. - Create a personal token: the token needs the permissions that your resources require. For more information, refer to Personal tokens.
To set the variable, replace [TOKEN VALUE] with your personal token and run this command in the terminal that runs Terraform:
The provider reads the token, and the command no longer stops at the provider configuration.
Terraform fails with no compatible versions
Terraform finds no version of the Azion provider that it can use and stops with this error:
The Azion Terraform Provider needs Terraform 1.0 or later. The version of Terraform Core on your machine is the first thing to check.
- Check the Terraform version:
terraform versionprints the version of Terraform Core. - Install a later version of Terraform: when the version is earlier than 1.0, install a later one. For the install, refer to Install Terraform.
To print the version of Terraform Core:
terraform version reports version 1.0 or later, which the provider needs.
Terraform fails with Failed to query available provider packages
Terraform cannot list the versions of the Azion provider and stops with this error:
Terraform looks the provider up by the source and the version in the required_providers block. The source of the Azion Terraform Provider is aziontech/azion.
- Check the source and the version: set
sourcetoaziontech/azionandversionto the provider version that you use, such as2.0.0. - Upgrade the installed provider:
terraform init -upgradedownloads the version that the block sets. For the full upgrade to v2.0, refer to Upgrade the provider to v2.0.
This required_providers block sets the source and pins provider version 2.0.0:
To download the provider version that the block sets, run this command in the project directory:
Terraform installs the provider version that the block sets, such as 2.0.0, in the project.
Terraform fails with resource not found
A Terraform command fails on a resource of the configuration with this error:
The configuration refers to a resource that Azion API v4 does not have. Provider v2.0 works only with API v4, and API v4 removed or renamed some API v3 resources.
- Check the resource on your account: look for the resource in Azion Console. The Azion API reference lists the resources that API v4 serves.
- Rename the v1.x resources: a resource type of provider v1.x can have another name in v2.0, or no counterpart. For each v1.x name and its replacement, refer to Resource changes in v2.0.
- Stay on provider v1.x for an API v3 account: an account on API v3 uses provider v1.x. For more information, refer to Azion Terraform Provider v1.x (API v3).
The configuration names only resources that exist in API v4, and the error no longer appears.
Terraform reports Invalid resource type for azion_domain
A configuration written for provider v1.x fails under provider v2.0 with this error:
Provider v2.0 removed the azion_domain resource. A workload and its deployment take its role.
- Replace the domain with a workload: rewrite the block as an
azion_workloadresource and anazion_workload_deploymentresource. For the v1.x block and the blocks that replace it, refer to Replace a domain with a workload. - Look up the resource types of the provider: the Terraform Registry documents every resource type and argument that the provider accepts.
The configuration uses only resource types that provider v2.0 accepts.
Terraform fails with Error refreshing state
During a migration to provider v2.0, Terraform stops on the v1.x origin resource with this error:
The state still lists a resource that the provider no longer finds. Provider v2.0 replaces the v1.x origin resource with azion_connector.
- Remove the resource from the state:
terraform state rmtakes the resource out of the state and leaves the object on your account. For the commands that remove the v1.x domain, origin, and function resources, refer to Remove the v1.x resources from the state. - Manage the origin as a connector: declare an
azion_connectorresource for the origin. For the v1.x block and the block that replaces it, refer to Replace an origin with a connector.
The state no longer lists the v1.x origin resource, and Terraform refreshes the state without the error.
terraform import fails with Cannot import non-existent remote object
terraform import stops with this error:
No object with the ID that you passed exists in Azion API v4. An API v3 resource can have a different ID in API v4.
- Look up the API v4 ID: find the ID of the resource in Azion Console.
- Import with the API v4 ID: run
terraform import <type>.<name> <id>with the ID from Azion Console. For the import of a workload, a connector, and a function, refer to Import the resources under their v2.0 types.
The state lists the imported resource under its v2.0 type.