This guide will walk you through the steps required to set up and use Terraform with CloudCIX.
Note
For the “region_id”, please contact the region provider.
For this example, we’ll use the test_region region which has an ID of 123456.
Region Name |
Region ID |
|---|---|
test_region |
123456 |
Note
You can find available regions in your CloudCIX dashboard.
Go to https://saas.cloudcix.com.
Log in with your CloudCIX credentials.
Open Membership.
Go to My Membership → Member Details.
Locate your API Key.
Follow the instructions on the official Terraform website to install Terraform on your system:
Clone the CloudCIX Terraform template repository from GitHub:
https://github.com/CloudCIX/Terraform-Template
git clone https://github.com/CloudCIX/Terraform-Template.git
cd cloudcix-terraform
Copy the template environment file and configure your CloudCIX API credentials:
cp cloudcix.env.template cloudcix.env
Edit cloudcix.env with your CloudCIX credentials:
CLOUDCIX_API_USERNAME=your_username
CLOUDCIX_API_PASSWORD=your_password
CLOUDCIX_API_KEY=your_api_key
CLOUDCIX_API_URL=https://api.cloudcix.com
terraform init
This will download the CloudCIX provider (version ~> 0.11.0) from the Terraform Registry.
Edit terraform.tfvars to customize your infrastructure:
settings_file = "cloudcix.env"
region_id = <Your_Region_ID> # Replace with your region ID from above steps
project_name = "my-project"
# Network Configuration
cidr = "10.0.0.0/24"
network_name = "My Network"
nameservers = "1.1.1.1,8.8.8.8"
# Instance Configuration
instance_name = "my-instance"
instance_type = "virtual-machine"
hypervisor_type = "lxd"
# Cloud-init user data
userdata = "#cloud-config\nusers:\n - name: administrator\n groups: sudo\n shell: /bin/bash\n lock_passwd: false\n passwd: $2a$12$...\n"
# Instance Specifications
instance_specs = {
cpu = {
sku = "vCPU_001"
quantity = 2
}
ram = {
sku = "RAM_001"
quantity = 4
}
storage = {
sku = "SSD_001"
quantity = 32
}
image = {
sku = "SURF001"
quantity = 1
}
}
# Firewall Rules
firewall_rules = [
"in tcp 22 22 0.0.0.0/0 10.0.0.0/24",
"in tcp 80 80 0.0.0.0/0 10.0.0.0/24",
"in tcp 443 443 0.0.0.0/0 10.0.0.0/24",
]
This configuration creates the following CloudCIX resources:
cloudcix_project)¶Creates a CloudCIX project in the specified region.
cloudcix_network_router)¶Creates a virtual router with:
NAT enabled
Custom IPv4 network (CIDR)
Network isolation
cloudcix_compute_instance)¶Creates a virtual machine with:
Custom CPU, RAM, and storage specifications
Network interface with NAT
Public and private IP addresses
Cloud-init userdata support
cloudcix_network_firewall)¶Creates firewall rules to control inbound/outbound traffic.
To deploy the infrastructure defined in your Terraform configuration, run the following commands:
# Preview changes
terraform plan
# Apply configuration
terraform apply
# Auto-approve (skip confirmation)
terraform apply -auto-approve
To destroy the created resources, run:
terraform destroy
terraform output
Example output:
instance_id = "12345"
private_ip = "10.0.0.10"
private_subnet = "10.0.0.0/24"
project_id = "67890"
public_ip = "203.0.113.42"