This guide shows you how to get started with the Azion Terraform Provider to manage your infrastructure as code.
Prerequisites
Before you begin, make sure you have:
- Terraform version 1.0 or higher installed
- An active Azion account
- A Personal Token with appropriate permissions
Step 1: Install Terraform
You must have Terraform Core installed in your environment. See how to install.
Verify the installation:
terraform versionStep 2: Configure the Provider
Create a new directory for your Terraform project:
mkdir azion-terraformcd azion-terraformCreate the main.tf file:
terraform { required_providers { azion = { source = "aziontech/azion" version = "2.0.0" } }}
provider "azion" { # Recommended: use AZION_API_TOKEN environment variable # api_token = var.api_token}Step 3: Configure Authentication
Option 1: Environment Variable (Recommended)
export AZION_API_TOKEN="your-personal-token"Option 2: Variables File
Create variables.tf:
variable "api_token" { type = string description = "Azion Personal Token" sensitive = true}Create terraform.tfvars (add to .gitignore):
api_token = "your-personal-token"Update main.tf:
provider "azion" { api_token = var.api_token}Step 4: Create Your First Infrastructure
Create resources.tf:
# Create a workloadresource "azion_workload" "my_workload" { name = "my-first-workload"}
# Create a connectorresource "azion_connector" "my_connector" { name = "my-connector"}
# Create an applicationresource "azion_application_main_settings" "my_app" { name = "my-application"}
# Create a DNS zoneresource "azion_intelligent_dns_zone" "my_zone" { name = "example.com" active = true}Step 5: Initialize and Apply
Initialize Terraform
terraform initVerify the Plan
terraform planApply Changes
terraform applyType yes when prompted to confirm.
Step 6: Verify Resources
# List all resourcesterraform state list
# View details of a specific resourceterraform state show azion_workload.my_workloadQuick Start Example
Here’s a complete example to get you started with Azion Terraform Provider v2.0:
terraform { required_providers { azion = { source = "aziontech/azion" version = "2.0.0" } }}
provider "azion" { api_token = var.api_token}
# Create a workloadresource "azion_workload" "example" { name = "my-workload" # Additional configuration...}
# Create a connectorresource "azion_connector" "example" { name = "my-connector" # Additional configuration...}
# Create an applicationresource "azion_application_main_settings" "example" { name = "my-application" # Additional configuration...}Project Structure
A recommended structure for larger projects:
azion-terraform/├── main.tf # Provider and general configurations├── variables.tf # Input variables├── outputs.tf # Outputs├── terraform.tfvars # Variable values (don't version control)├── modules/│ ├── workload/│ ├── application/│ └── security/└── environments/ ├── dev/ ├── staging/ └── prod/Next Steps
- Workloads - Learn about workloads
- Applications - Configure applications
- Security - Configure firewall and WAF
- Best Practices - Best practices for usage
Troubleshooting
Authentication Error
Error: error configuring Terraform Azion Provider: personal token is requiredSolution: Verify that the token is correctly configured via environment variable or configuration file.
Incompatible Version
Error: provider registry.terraform.io/aziontech/azion: no compatible versionsSolution: Verify that you’re using Terraform 1.0 or higher.
Resources Not Found
Error: resource not foundSolution: Verify that the resource exists in API v4. Some v3 resources were removed or renamed. See the Migration Guide.