https://github.com/gabrielecanepa/azure-vm-actions
☁️ Actions to start and shut down Azure virtual machines
https://github.com/gabrielecanepa/azure-vm-actions
azure azure-virtual-machine devops github-actions
Last synced: over 1 year ago
JSON representation
☁️ Actions to start and shut down Azure virtual machines
- Host: GitHub
- URL: https://github.com/gabrielecanepa/azure-vm-actions
- Owner: gabrielecanepa
- Created: 2024-07-25T09:14:10.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-19T15:31:32.000Z (almost 2 years ago)
- Last Synced: 2025-01-30T09:41:59.850Z (over 1 year ago)
- Topics: azure, azure-virtual-machine, devops, github-actions
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Azure Virtual Machine Actions
[](https://github.com/gabrielecanepa/azure-vm-actions/actions/workflows/start-vm.yml)
[](https://github.com/gabrielecanepa/azure-vm-actions/actions/workflows/stop-vm.yml)
This repository contains a collection of GitHub Actions for working with Azure virtual machines.
## Configuration
### Service principal
To create a service principal and configure its access to Azure resources, open a local or cloud shell and run the following command specifying an arbitrary service principal name (e.g. `auto-shutdown`), the virtual machine subscription ID and resource group name:
```sh
SERVICE_PRINCIPAL_NAME="auto-shutdown"
SUBSCRIPTION_ID="SUBSCRIPTION_ID"
RESOURCE_GROUP_NAME=""
az ad sp create-for-rbac \
--name $SERVICE_PRINCIPAL_NAME \
--scopes /subscriptions/$SUBSCRIPTION_ID/resourceGroups/$RESOURCE_GROUP_NAME \
--role contributor --sdk-auth
```
The response will be a JSON object with the following structure:
```json
{
"clientId": "",
"clientSecret": "",
"subscriptionId": "",
"tenantId": "",
"activeDirectoryEndpointUrl": "https://login.microsoftonline.com",
"resourceManagerEndpointUrl": "https://management.azure.com/",
"activeDirectoryGraphResourceId": "https://graph.windows.net/",
"sqlManagementEndpointUrl": "https://management.core.windows.net:8443/",
"galleryEndpointUrl": "https://gallery.azure.com/",
"managementEndpointUrl": "https://management.core.windows.net/"
}
```
### GitHub Actions
Add the following secrets to your GitHub repository:
- `AZURE_CREDENTIALS`: the JSON object from the previous step
- `VM_NAME`: name of the virtual machine
- `VM_RESOURCE_GROUP`: name of the virtual machine resource group
## Usage
Once configured, you can run the following workflows using GitHub Actions.
| Name | Description | Schedule | Trigger |
| ----------------------------------------- | ------------------------------------------------- | --------------------------- | ------------------------------- |
| [Start VM](.github/workflows/stop-vm.yml) | Start a virtual machine | None | `workflow_dispatch` |
| [Stop VM](.github/workflows/stop-vm.yml) | Stop (power off and deallocate) a virtual machine | Every day at midnight (UTC) | `schedule`, `workflow_dispatch` |