# Quick Start Guide - Terraform Provider

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](https://developer.hashicorp.com/terraform/downloads) version 1.0 or higher installed
- An active [Azion account](https://www.azion.com/)
- A [Personal Token](/en/documentation/products/accounts/personal-tokens/) with appropriate permissions

---

## Step 1: Install Terraform

You must have Terraform Core installed in your environment. [See how to install](https://developer.hashicorp.com/terraform/downloads).

Verify the installation:

```bash
terraform version
```

---

## Step 2: Configure the Provider

Create a new directory for your Terraform project:

```bash
mkdir azion-terraform
cd azion-terraform
```

Create the `main.tf` file:

```hcl
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)

```bash
export AZION_API_TOKEN="your-personal-token"
```

### Option 2: Variables File

Create `variables.tf`:

```hcl
variable "api_token" {
  type        = string
  description = "Azion Personal Token"
  sensitive   = true
}
```

Create `terraform.tfvars` (add to `.gitignore`):

```hcl
api_token = "your-personal-token"
```

Update `main.tf`:

```hcl
provider "azion" {
  api_token = var.api_token
}
```

---

## Step 4: Create Your First Infrastructure

Create `resources.tf`:

```hcl
# 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

```bash
terraform init
```

### Verify the Plan

```bash
terraform plan
```

### Apply Changes

```bash
terraform apply
```

Type `yes` when prompted to confirm.

---

## Step 6: Verify Resources

```bash
# 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:

```hcl
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

- [Workloads](/en/documentation/products/terraform-provider/resources/workloads/) - Learn about workloads
- [Applications](/en/documentation/products/terraform-provider/resources/applications/) - Configure applications
- [Security](/en/documentation/products/terraform-provider/resources/security/) - Configure firewall and WAF
- [Best Practices](/en/documentation/products/terraform-provider/best-practices/) - Best practices for usage

---

## 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](/en/documentation/products/terraform-provider/terraform-migration-v3-to-v4/).