This article explains how to deploy resources, such as virtual machines (VMs), across multiple projects in Crusoe Cloud using Terraform. It addresses a common requirement for users managing infrastructure across different crusoe projects.
Prerequisites
- Make sure you have terraform installed.
- Install Crusoe CLI to authenticate.
- Ensure you have a valid SSH key to access the deployed VMs.
- Retrieve your project IDs using the below command.
crusoe projects list
Step-by-Step Instructions
- Run the command below to list available projects and their project IDs. Select the project_ids where you want to deploy your resources.
crusoe projects list
- The command below lists all the available locations, where your resources will be deployed.
crusoe locations list
- The command below lists all the available images.
crusoe compute images list
- The command below lists all the available VM types to choose from.
crusoe compute vms types
-
Create a file named `main.tf` and copy the following configuration and update the values as per your requirements:
terraform {
required_providers {
crusoe = {
source = "crusoecloud/crusoe"
version = "0.5.26"
}
}
}
locals {
ssh_key = file("~/.ssh/id_ed25519.pub") #replace with path to your public SSH key if different
variable "project_id1" {
type = string
default = "YOUR_PROJECT1_ID" #add your project1 id here
}
variable "project_id2" {
type = string
default = "YOUR_PROJECT2_ID" #add your project2 id here
}
#creating VM1 in project_id1
resource "crusoe_compute_instance" "vmprojectid1" {
name = "testproject1vm"
project_id = var.project_id1
type = "c1a.2x"
location = "eu-iceland1-a"
image = "ubuntu22.04:latest"
ssh_key = local.ssh_key
}
#creating VM2 in project_id2
resource "crusoe_compute_instance" "vmprojectid2" {
name = "testproject2vm"
project_id = var.project_id2
type = "c1a.2x"
location = "eu-iceland1-a"
image = "ubuntu22.04:latest"
ssh_key = local.ssh_key
} - At the root of your terraform project, run the series of commands below to deploy the resources to multiple projects.
terraform init
terraform plan
terraform apply -
Terraform will provision the VMs in both projects.
Comments
0 comments
Article is closed for comments.