> ## Documentation Index
> Fetch the complete documentation index at: https://checkly-422f444a-paula-tree-202-entitlements-group-troubles.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Private Locations CLI Integration

> Integrate Private Locations with Checkly CLI and monitoring-as-code workflows. Define Private Locations in your TypeScript and JavaScript projects.

# Integration with Checkly CLI

Define Private Locations in your monitoring-as-code workflow using the Checkly CLI. This enables version-controlled, repeatable deployments of your monitoring infrastructure.

## Basic Configuration

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    import { ApiCheck, BrowserCheck } from 'checkly/constructs'

    // API check using private location
    new ApiCheck('internal-api-check', {
      name: 'Internal API Health',
      request: {
        method: 'GET',
        url: 'http://internal-api.company.local/health'
      },
      privateLocations: ['company-datacenter-east'],
      maxResponseTime: 5000
    })

    // Browser check using private location  
    new BrowserCheck('internal-app-check', {
      name: 'Internal App Login Flow',
      code: {
        entrypoint: './internal-app.spec.ts'
      },
      privateLocations: ['company-datacenter-east']
    })
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    const { ApiCheck, BrowserCheck } = require('checkly/constructs')

    // API check for internal service
    new ApiCheck('database-health-check', {
      name: 'Database Connection Health',
      request: {
        method: 'GET',
        url: 'http://db-proxy.internal:8080/health'
      },
      privateLocations: ['internal-network'],
      assertions: [
        { source: 'STATUS_CODE', comparison: 'EQUALS', target: 200 }
      ]
    })
    ```
  </Tab>
</Tabs>

## Advanced Configuration

### Multiple Private Locations

Configure checks to run from multiple Private Locations for redundancy:

```typescript theme={null}
new ApiCheck('critical-service-check', {
  name: 'Critical Service Health',
  request: {
    method: 'GET',
    url: 'http://critical-service.internal/health'
  },
  privateLocations: ['datacenter-primary', 'datacenter-secondary'],
  maxResponseTime: 3000,
  retryCount: 2
})
```

### Environment-Specific Configuration

Use environment variables to configure Private Locations dynamically:

```typescript theme={null}
// checkly.config.ts
import { defineConfig } from 'checkly/constructs'

export default defineConfig({
  projectName: 'Internal Monitoring',
  logicalId: 'internal-monitoring',
  checks: {
    locations: ['us-east-1', 'eu-west-1'],
    privateLocations: process.env.PRIVATE_LOCATIONS?.split(',') || [],
    tags: ['internal', process.env.ENVIRONMENT || 'development']
  }
})
```

### Conditional Private Location Usage

Use conditional logic to determine Private Location usage:

```typescript theme={null}
const usePrivateLocations = process.env.USE_PRIVATE_LOCATIONS === 'true'
const privateLocationNames = usePrivateLocations ? ['internal-network'] : []

new ApiCheck('service-health-check', {
  name: 'Service Health Check',
  request: {
    method: 'GET',
    url: process.env.SERVICE_URL || 'http://localhost:8080/health'
  },
  privateLocations: privateLocationNames,
  tags: usePrivateLocations ? ['private-location'] : ['public-location']
})
```

## Deployment Workflows

### CI/CD Integration

Integrate Private Location checks into your CI/CD pipeline:

```yaml theme={null}
# .github/workflows/deploy-checks.yml
name: Deploy Monitoring Checks

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  deploy-checks:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '18'
          
      - name: Install dependencies
        run: npm install
        
      - name: Deploy to Checkly
        env:
          CHECKLY_API_KEY: ${{ secrets.CHECKLY_API_KEY }}
          PRIVATE_LOCATIONS: ${{ secrets.PRIVATE_LOCATIONS }}
          ENVIRONMENT: production
        run: npx checkly deploy
```

### Environment-Specific Deployments

Deploy different configurations for different environments:

```bash theme={null}
#!/bin/bash
# deploy-monitoring.sh

ENVIRONMENT=$1
PRIVATE_LOCATIONS=""

case $ENVIRONMENT in
  "production")
    PRIVATE_LOCATIONS="prod-datacenter-east,prod-datacenter-west"
    ;;
  "staging")
    PRIVATE_LOCATIONS="staging-datacenter"
    ;;
  "development")
    PRIVATE_LOCATIONS="dev-network"
    ;;
  *)
    echo "Unknown environment: $ENVIRONMENT"
    exit 1
    ;;
esac

export PRIVATE_LOCATIONS
export ENVIRONMENT

npx checkly deploy
```

## Project Structure

Organize your monitoring-as-code project for Private Locations:

```
monitoring-project/
├── checkly.config.ts
├── package.json
├── checks/
│   ├── api/
│   │   ├── internal-services.ts
│   │   └── database-health.ts
│   ├── browser/
│   │   ├── internal-apps.ts
│   │   └── admin-dashboards.ts
│   └── shared/
│       ├── assertions.ts
│       └── helpers.ts
├── environments/
│   ├── production.ts
│   ├── staging.ts
│   └── development.ts
└── scripts/
    ├── deploy.sh
    └── validate.sh
```

### Configuration Files

**checkly.config.ts:**

```typescript theme={null}
import { defineConfig } from 'checkly/constructs'
import { productionConfig } from './environments/production'
import { stagingConfig } from './environments/staging'

const config = process.env.ENVIRONMENT === 'production' 
  ? productionConfig 
  : stagingConfig

export default defineConfig(config)
```

**environments/production.ts:**

```typescript theme={null}
import { ChecklyConfig } from 'checkly/constructs'

export const productionConfig: ChecklyConfig = {
  projectName: 'Production Internal Monitoring',
  logicalId: 'prod-internal-monitoring',
  checks: {
    privateLocations: ['prod-datacenter-east', 'prod-datacenter-west'],
    tags: ['production', 'internal'],
    runtimeId: '2023.09'
  },
  cli: {
    runParallel: true,
    runLocation: 'us-east-1'
  }
}
```

## Best Practices

<AccordionGroup>
  <Accordion title="Version Control">
    * Store Private Location configurations in version control
    * Use environment-specific configuration files
    * Document Private Location dependencies
    * Include deployment scripts in your repository
  </Accordion>

  <Accordion title="Security">
    * Use environment variables for sensitive configuration
    * Never commit API keys or secrets
    * Implement least-privilege access for deployment
    * Use separate Private Locations for different environments
  </Accordion>

  <Accordion title="Testing">
    * Test Private Location configurations locally
    * Validate check configurations before deployment
    * Use staging environments for testing
    * Implement rollback procedures
  </Accordion>

  <Accordion title="Monitoring">
    * Monitor your monitoring deployment
    * Track Private Location agent health
    * Alert on deployment failures
    * Regular review of check configurations
  </Accordion>
</AccordionGroup>

## Troubleshooting

### Common Issues

**Private Location Not Found:**

```bash theme={null}
Error: Private location 'internal-network' not found
```

**Solution:** Ensure the Private Location exists in your Checkly account and the name matches exactly.

**Agent Not Connected:**

```bash theme={null}
Warning: No agents connected to private location 'internal-network'
```

**Solution:** Verify that agents are running and connected to the Private Location.

**Deployment Failures:**

```bash theme={null}
Error: Failed to deploy checks to private location
```

**Solution:** Check agent connectivity, API key validity, and network access.

### Debugging Commands

```bash theme={null}
# Validate configuration
npx checkly validate

# Test check execution
npx checkly test --location internal-network

# Check agent status
npx checkly whoami

# Deploy with verbose logging
npx checkly deploy --verbose
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Agent Configuration" href="/detect/private-locations/agent-configuration">
    Learn advanced agent configuration options
  </Card>

  <Card title="Use Cases" href="/detect/private-locations/use-cases">
    Explore real-world deployment patterns
  </Card>

  <Card title="Kubernetes Deployment" href="/detect/private-locations/kubernetes-deployment">
    Deploy at scale with Kubernetes
  </Card>

  <Card title="Scaling Guide" href="/detect/private-locations/scaling-redundancy">
    Plan for growth and redundancy
  </Card>
</CardGroup>

<Tip>
  Start with a simple configuration and gradually add complexity as you become familiar with Private Location integration patterns.
</Tip>
