Azion Terraform Provider quickstart
Configure the Azion Terraform Provider with a personal token and create your first workload, connector, application, and DNS zone as code.
This guide instructs you through your first infrastructure as code with the Azion Terraform Provider.
- Create a Terraform project that requires the provider.
- Give the provider your personal token.
- Declare four resources and create them with
terraform apply. - Check the resources in the Terraform state.
The configuration declares four independent resources, and no resource refers to another:
azion_workloadcreates a workload.azion_connectorcreates a connector.azion_application_main_settingcreates an application.azion_intelligent_dns_zonecreates an active zone in Edge DNS.
For more information about the provider, refer to Azion Terraform Provider.
Prerequisites
- Terraform 1.0 or later.
- An Azion account. To create one, refer to Create an account.
- A personal token with the permissions that your resources require. For more information, refer to Personal tokens.
Install Terraform
The Azion Terraform Provider needs Terraform Core on your machine. If Terraform is not installed, install it from the Terraform downloads page.
Check the installed version:
The command prints the version of Terraform Core. The provider needs version 1.0 or later.
Create the project and declare the provider
Create a directory for the project and go to it:
In the azion-terraform directory, create a main.tf file with the following content. The required_providers block sets the provider source to aziontech/azion and pins version 2.0.0:
The project declares the Azion Terraform Provider at a fixed version.
Provide your personal token
The provider reads your personal token from the AZION_API_TOKEN environment variable, which is the recommended method. In the terminal that runs Terraform, set the variable. Replace [TOKEN VALUE] with your personal token:
The provider "azion" block in main.tf stays empty, and no file in the project holds the token.
To keep the token in a Terraform variable instead, the provider takes it in the api_token argument. Create a variables.tf file that declares api_token as a sensitive variable:
Create a terraform.tfvars file that sets the variable. This file holds the token, so add terraform.tfvars to your .gitignore file:
In main.tf, replace the provider "azion" block with a block that passes the variable to the provider:
The provider has your personal token, from the environment or from the api_token variable.
Declare the resources
In the azion-terraform directory, create a resources.tf file. It declares a workload, a connector, an application, and a DNS zone:
Replace example.com with the domain of your zone. The project declares four resources that do not exist on your account yet.
Create the resources
From the azion-terraform directory, initialize the Terraform project:
Review the plan of the changes before you apply them:
Apply the configuration:
At the confirmation prompt, enter yes. Terraform creates the four resources on your Azion account.
If a command returns an error, refer to Troubleshoot the Terraform Provider.
Check the resources
List the resources in the Terraform state, then show the details of the workload:
The state holds the four resources, and terraform state show displays the attributes that Terraform stores for the workload.
Complete example
The following configuration for provider version 2.0.0 puts the provider and three resources in one file. It declares the provider itself, so use it in an empty directory, not next to another file that declares the provider. It reads the token from the api_token variable, so it needs a variables.tf file that declares api_token and a terraform.tfvars file that sets it. Each resource block marks where its other arguments go: