How to Configure Multiple Infrahub Servers
If you need to work with multiple Infrahub environments (development, staging, production), this guide shows you how to configure and manage multiple server connections in the VSCode extension.
Prerequisites
- Infrahub VSCode extension installed
- Access to multiple Infrahub servers
- API tokens for each server (if authentication is required)
Step 1: Open extension settings
Open your VSCode settings configuration:
- Press
Ctrl+Shift+P
(orCmd+Shift+P
on macOS) - Type "Preferences: Open Settings (JSON)"
- Press Enter
Step 2: Add multiple server configurations
Add your server configurations to the settings file:
{
"infrahub-vscode.servers": [
{
"name": "Development",
"address": "http://localhost:8000",
"api_token": "${env:INFRAHUB_DEV_TOKEN}"
},
{
"name": "Staging",
"address": "https://staging.infrahub.example.com",
"api_token": "${env:INFRAHUB_STAGING_TOKEN}"
},
{
"name": "Production",
"address": "https://infrahub.example.com",
"api_token": "${env:INFRAHUB_PROD_TOKEN}"
}
]
}
Step 3: Set up environment variables
For security, use environment variables for API tokens:
On macOS and Linux
Add to your shell configuration file (~/.bashrc
, ~/.zshrc
, etc.):
export INFRAHUB_DEV_TOKEN="your-dev-token"
export INFRAHUB_STAGING_TOKEN="your-staging-token"
export INFRAHUB_PROD_TOKEN="your-prod-token"
Then reload your shell or restart VSCode.
On windows
Using PowerShell:
[System.Environment]::SetEnvironmentVariable('INFRAHUB_DEV_TOKEN', 'your-dev-token', 'User')
[System.Environment]::SetEnvironmentVariable('INFRAHUB_STAGING_TOKEN', 'your-staging-token', 'User')
[System.Environment]::SetEnvironmentVariable('INFRAHUB_PROD_TOKEN', 'your-prod-token', 'User')
Restart VSCode after setting environment variables.
Step 4: Verify all connections
- Open the Infrahub Servers tree view in the Activity Bar
- You should see all three servers listed
- Expand each server to verify it can retrieve branches
- Check the status bar - it shows the first server's connection status
Step 5: Switch between servers for queries
When executing GraphQL queries:
- Right-click on a query in the Infrahub YAML tree view
- Select "Execute GraphQL Query"
- You'll be prompted to select a server from your configured list
- Choose the appropriate environment
- Select the branch to query against
Advanced configuration
Using different schemas per environment
Configure different schema directories for each environment:
{
"infrahub-vscode.servers": [
{
"name": "Development",
"address": "http://localhost:8000",
"api_token": "${env:INFRAHUB_DEV_TOKEN}"
},
{
"name": "Production",
"address": "https://infrahub.example.com",
"api_token": "${env:INFRAHUB_PROD_TOKEN}"
}
]
}
Server groups with naming conventions
Use clear naming conventions to organize servers:
{
"infrahub-vscode.servers": [
{
"name": "[LOCAL] Development",
"address": "http://localhost:8000"
},
{
"name": "[AWS] US-East-1 Staging",
"address": "https://staging-us-east-1.infrahub.example.com",
"api_token": "${env:INFRAHUB_AWS_STAGING_TOKEN}"
},
{
"name": "[AWS] US-East-1 Production",
"address": "https://us-east-1.infrahub.example.com",
"api_token": "${env:INFRAHUB_AWS_PROD_TOKEN}"
},
{
"name": "[Azure] Europe-West Production",
"address": "https://eu-west.infrahub.example.com",
"api_token": "${env:INFRAHUB_AZURE_PROD_TOKEN}"
}
]
}
Validation
To verify your configuration is working correctly:
- Check Status Bar: The first server's status appears in the status bar
- Tree View: All servers should appear in the Infrahub Servers tree view
- Branch Listing: Expanding each server should show its branches
- Query Execution: Test a query against each server
Troubleshooting
Server not appearing in tree view
- Save your settings.json file
- Reload VSCode window (
Ctrl+R
orCmd+R
) - Check for JSON syntax errors in settings
Authentication failures
-
Verify environment variables are set correctly:
echo $INFRAHUB_DEV_TOKEN # macOS/Linux
echo %INFRAHUB_DEV_TOKEN% # Windows CMD -
Ensure tokens have necessary permissions
-
Check token expiration dates
Connection timeouts
- Verify server URLs are accessible from your network
- Check for proxy/firewall restrictions
- Ensure VPN connection if required