An automation tool to restart stopped (deallocated) spot VMs across multiple cloud providers (AWS, Azure, GCP). Currently, it supports only GCP and Azure spot VMs.
-
Go to the Google Cloud Console
https://console.cloud.google.com/ -
Select your project
Use the project selector at the top of the page to choose your GCP project. -
Navigate to Service Accounts
In the left sidebar, go to IAM & Admin > Service Accounts. -
Create a new service account
- Click Create Service Account.
- Enter a name and description.
- Click Create and Continue.
-
Grant the required role
- In the "Grant this service account access to project" step, add the role:
Compute Instance Admin (v1) (roles/compute.instanceAdmin.v1) - Click Continue and then Done.
- In the "Grant this service account access to project" step, add the role:
-
Create and download a key
- Click on the service account you just created.
- Go to the Keys tab.
- Click Add Key > Create new key.
- Select JSON and click Create.
- A
.jsonfile will be downloaded to your computer.
-
Use the credentials
- Place the downloaded JSON file in the
credentialsdirectory (e.g.,credentials/credentials.json). - Reference it in the
vms.jsonconfiguration for each GCP VM:"credentials_file": "credentials.json"
- Place the downloaded JSON file in the
Note:
A service account is created within a specific GCP project and its permissions apply only to resources in that project.
If you want to manage VMs across multiple GCP projects, you can either:
- Create a service account in each project, or
- Grant an existing service account access to additional projects by assigning it the necessary roles in those projects.
-
Go to the Azure Portal
https://portal.azure.com/ -
Register a new application
- Navigate to Azure Active Directory > App registrations.
- Click New registration.
- Enter a name and register the application.
-
Create a client secret
- In app registration, go to Certificates & secrets.
- Click New client secret, add a description, and set an expiry.
- Copy the generated value - client secret value, not client secret ID (you won't see it again).
-
Get tenant and client IDs
- In app registration, copy the Application (client) ID and Directory (tenant) ID.
-
Assign a role to the application
- Go to Subscription or Resource Group where your VMs are.
- Click Access control (IAM) > Add > Add role assignment.
- Assign the role Virtual Machine Contributor to the application (search for the app by name).
-
Get your subscription ID
- Go to Subscriptions in the portal and copy the Subscription ID.
-
Create a credentials JSON file
Create a file (e.g.,azure_credentials.json) in thecredentialsdirectory with the following content:{ "AZURE_CLIENT_ID": "<your-client-id>", "AZURE_CLIENT_SECRET": "<your-client-secret>", "AZURE_TENANT_ID": "<your-tenant-id>", "AZURE_SUBSCRIPTION_ID": "<your-subscription-id>" } -
Reference the credentials in your
vms.json"credentials_file": "azure_credentials.json"
{
"gcp": [
{
"project_id": "your-gcp-project",
"zone": "us-central1-a",
"instance_name": "my-gcp-vm",
"credentials_file": "credentials.json",
"description": "This is a GCP spot VM for testing"
}
],
"azure": [
{
"resource_group": "myResourceGroup",
"instance_name": "myAzureVM",
"credentials_file": "azure_credentials.json",
"description": "Azure spot VM for testing"
}
]
}- Create
vms.json - Place the credential files in
credentialsdirectory. - Run the script:
sudo apt install python3-venv python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txt python3 main.py
Keep the GCP and Azure credentials file secure. Anyone with this file can access the cloud accounts according to the permissions granted.
MIT License