Experimental REST API to query Azure resources, written in Go
This is a simple REST API that calls Azure Management (ARM) endpoints to retrieve information about Azure resources.
- List all resource groups in an Azure subscription
- Uses Azure SDK for Go v2
- Supports multiple authentication methods via
DefaultAzureCredential
- Go 1.21 or later
- Azure subscription
- Azure CLI installed and authenticated, OR service principal credentials
- Install dependencies:
go mod download-
Set up authentication:
-
Option 1 (Recommended for local development): Sign in with Azure CLI:
az login
-
Option 2: Set up service principal environment variables (see
.env.example)
-
-
Set your Azure subscription ID:
export AZURE_SUBSCRIPTION_ID="your-subscription-id-here"You can find your subscription ID by running:
az account show --query id -o tsvgo run main.goThe server will start on port 8080 by default.
Returns API information and available endpoints.
curl http://localhost:8080/Returns all resource groups in the configured subscription.
curl http://localhost:8080/resource-groupsExample response:
{
"subscription_id": "12345678-1234-1234-1234-123456789abc",
"count": 2,
"resource_groups": [
{
"id": "/subscriptions/12345678-1234-1234-1234-123456789abc/resourceGroups/my-rg",
"location": "eastus",
"name": "my-rg",
"tags": {
"environment": "dev"
}
}
]
}Health check endpoint.
curl http://localhost:8080/healthAZURE_SUBSCRIPTION_ID(required): Your Azure subscription IDPORT(optional): Server port, defaults to 8080AZURE_TENANT_ID,AZURE_CLIENT_ID,AZURE_CLIENT_SECRET(optional): For service principal authentication
go build -o go-azure-api
./go-azure-apiThe application uses DefaultAzureCredential which attempts authentication in the following order:
- Environment variables (service principal)
- Workload identity (for Azure Kubernetes Service)
- Managed identity (for Azure VMs, App Service, etc.)
- Azure CLI credentials
- Azure PowerShell credentials
For local development, using Azure CLI (az login) is the easiest method.