Using Terraform in Arvancloud’s Cloud Server
Terraform is an open-source tool for creating and managing a cloud infrastructure through a set of codes. This makes it easier to deploy your products. The recently recommended method for deploying files is an IaC design, a group of codes that reduce human error in the process to increase its speed and accuracy. This tool defines your required resources in the Terraform config files, and when an executable plan is ready, you can use it to deploy your products onto the cloud services and test your infrastructures.
You need to install Terraform first and configure a provider file which will be explained here.
Install Terraform
You can install the latest version of Terraform via Command Line and Git on Windows or Unix-Based operating systems.
First, get the configuration details with this command:
git clone github.com/arvancloud/terraform-provider-arvan
Then, install Terraform using this command:
make install
Terraform Configuration in Arvancloud
This file specifies which Provider (Arvancloud) you are using and how to obtain the necessary access information (Arvancloud API key).
To start, create the directory for your infrastructure. You must create the provider file in this directory.
mkdir ~/example-terraform-directory
cd ~/example-terraform-directory
Create a Machine User key (API key) from your user panel. You can read the Access Key guide for the step-by-step process. Then, create a file named main.tf in this directory and use an editor to open it and add the content below:
terraform {
required_providers {
arvan = {
source = "arvancloud.ir/terraform/arvan"
version = "0.5.0" # put the version here
}
}
}
variable "MachineUserKey" {
type = string
default = "<Your Machine User Key>"
sensitive = true
}
provider "arvan" {
api_key = var.MachineUserKey
}
The presence of this code in your configuration allows you to access all service features by using codes. For instance, you can use the code below to create a new instance:
terraform {
required_providers {
arvan = {
source = "arvancloud.ir/terraform/arvan"
version = "0.6.0"
}
}
}
variable "MachineUserKey" {
type = string
default = "<Your MAchine User Key>"
sensitive = true
}
provider "arvan" {
api_key = var.MachineUserKey
}
variable "instance-name" {
type = string
default = "terraform-instance-example"
}
variable "region" {
type = string
default = "ir-thr-c2" # Forogh Datacenter
}
resource "arvan_iaas_instance" "instance-1" {
region = var.region
flavor = "g1-1-1-0"
name = var.instance-name
image {
type = "distributions"
name = "debian/11"
}
disk_size = 25
}
data "arvan_iaas_instance" "get_instance_id" {
depends_on = [
arvan_iaas_instance.instance-1
]
region = var.region
name = var.instance-name
}
output "details-instance-1" {
value = data.arvan_iaas_instance.get_instance_id
}
Read the document on Terraform to get an in-depth idea of the samples and configurations.