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:


Step 1: Install Terraform

You must have Terraform Core installed in your environment. See how to install.

Verify the installation:

Terminal window
terraform version

Step 2: Configure the Provider

Create a new directory for your Terraform project:

Terminal window
mkdir azion-terraform
cd azion-terraform

Create 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

Terminal window
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 workload
resource "azion_workload" "my_workload" {
name = "my-first-workload"
}
# Create a connector
resource "azion_connector" "my_connector" {
name = "my-connector"
}
# Create an application
resource "azion_application_main_settings" "my_app" {
name = "my-application"
}
# Create a DNS zone
resource "azion_intelligent_dns_zone" "my_zone" {
name = "example.com"
active = true
}

Step 5: Initialize and Apply

Initialize Terraform

Terminal window
terraform init

Verify the Plan

Terminal window
terraform plan

Apply Changes

Terminal window
terraform apply

Type yes when prompted to confirm.


Step 6: Verify Resources

Terminal window
# List all resources
terraform state list
# View details of a specific resource
terraform state show azion_workload.my_workload

Quick 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 workload
resource "azion_workload" "example" {
name = "my-workload"
# Additional configuration...
}
# Create a connector
resource "azion_connector" "example" {
name = "my-connector"
# Additional configuration...
}
# Create an application
resource "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


Troubleshooting

Authentication Error

Error: error configuring Terraform Azion Provider: personal token is required

Solution: Verify that the token is correctly configured via environment variable or configuration file.

Incompatible Version

Error: provider registry.terraform.io/aziontech/azion: no compatible versions

Solution: Verify that you’re using Terraform 1.0 or higher.

Resources Not Found

Error: resource not found

Solution: Verify that the resource exists in API v4. Some v3 resources were removed or renamed. See the Migration Guide.