CloudCIX Terraform Guide

This guide will walk you through the steps required to set up and use Terraform with CloudCIX.

Step 1: Choose Your Region

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.

Step 2: Obtain Your API Keys

  1. Go to https://saas.cloudcix.com.

  2. Log in with your CloudCIX credentials.

  3. Open Membership.

  4. Go to My MembershipMember Details.

  5. Locate your API Key.

Finding the API Key in CloudCIX portal

Step 3: Install Terraform

Follow the instructions on the official Terraform website to install Terraform on your system:

https://developer.hashicorp.com/terraform/install

Step 4: Clone and configure the CloudCIX Terraform Template

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

1. Set Up API Credentials

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

2. Initialize Terraform

terraform init

This will download the CloudCIX provider (version ~> 0.11.0) from the Terraform Registry.

3. Configure Terraform Variables

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:

1. Project (cloudcix_project)

Creates a CloudCIX project in the specified region.

2. Network Router (cloudcix_network_router)

Creates a virtual router with:

  • NAT enabled

  • Custom IPv4 network (CIDR)

  • Network isolation

3. Compute Instance (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

4. Firewall (cloudcix_network_firewall)

Creates firewall rules to control inbound/outbound traffic.

Deploy & Remove Infrastructure

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

View Outputs

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"