Skip to main content

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:

  1. Press Ctrl+Shift+P (or Cmd+Shift+P on macOS)
  2. Type "Preferences: Open Settings (JSON)"
  3. 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}"
}
]
}
tip

If you're using a development server with a self-signed certificate, you can disable certificate verification by adding "tls_insecure": true to the server configuration. This should only be used in development environments.

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

  1. Open the Infrahub Servers tree view in the Activity Bar
  2. You should see all three servers listed
  3. Expand each server to verify it can retrieve branches
  4. Check the status bar - it shows the first server's connection status

Step 5: Switch between servers for queries

When executing GraphQL queries:

  1. Right-click on a query in the Infrahub YAML tree view
  2. Select "Execute GraphQL Query"
  3. You'll be prompted to select a server from your configured list
  4. Choose the appropriate environment
  5. 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}"
}
]
}

Working with self-signed certificates

For development or testing environments using self-signed SSL certificates, you can disable certificate verification:

{
"infrahub-vscode.servers": [
{
"name": "Development (Self-Signed)",
"address": "https://dev.infrahub.local",
"api_token": "${env:INFRAHUB_DEV_TOKEN}",
"tls_insecure": true
}
]
}
warning

The tls_insecure option disables TLS certificate verification, which makes connections vulnerable to man-in-the-middle attacks. Never use this option for production servers. Only use it in controlled development environments with self-signed certificates.

Validation

To verify your configuration is working correctly:

  1. Check Status Bar: The first server's status appears in the status bar
  2. Tree View: All servers should appear in the Infrahub Servers tree view
  3. Branch Listing: Expanding each server should show its branches
  4. 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 or Cmd+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

Certificate verification errors

If you encounter certificate errors with development servers:

  • For self-signed certificates, add "tls_insecure": true to the server configuration
  • For production servers with certificate issues, fix the certificate rather than disabling verification
  • Check that your system's CA certificate store is up to date