Skip to content

Exports Syncing

Export node values to environment variables and sync them to your .env file.

Use case: Keeping your .env file in sync with your HCL configuration, especially during development.

Add export blocks inside nodes to define which values should be exported:

partition "database" {
environment "production" {
provider "main" {
host = "db.prod.internal"
port = 5432
username = "app_user"
password = sensitive("secret123")
database = "myapp"
export {
DB_HOST = self.host
DB_PORT = self.port
DB_USERNAME = self.username
DB_PASSWORD = self.password
DB_DATABASE = self.database
}
}
}
}
Terminal window
# Export specific node
php artisan huckle:export database.production.main
# Export all nodes
php artisan huckle:export --all
use Cline\Huckle\Facades\Huckle;
// Export specific node
$node = Huckle::get('database.production.main');
$node->exportToEnv();
// Export by context
Huckle::exportContextToEnv([
'partition' => 'database',
'environment' => 'production',
]);

The huckle:sync command writes exported values directly to your .env file:

Terminal window
# Sync to default .env
php artisan huckle:sync
# Sync to specific file
php artisan huckle:sync --file=.env.production
# Preview changes without writing
php artisan huckle:sync --dry-run
  1. Reads the current .env file
  2. Finds all exported values from your nodes
  3. Updates existing keys or adds new ones
  4. Preserves comments and formatting
  5. Writes the updated file
nodes.hcl
partition "services" {
environment "local" {
provider "stripe" {
api_key = sensitive("pk_test_xxx")
api_secret = sensitive("sk_test_xxx")
export {
STRIPE_KEY = self.api_key
STRIPE_SECRET = self.api_secret
}
}
}
}
Terminal window
# Your .env before:
# APP_NAME=MyApp
# APP_ENV=local
php artisan huckle:sync
# Your .env after:
# APP_NAME=MyApp
# APP_ENV=local
# STRIPE_KEY=pk_test_xxx
# STRIPE_SECRET=sk_test_xxx

Export only nodes matching specific criteria:

use Cline\Huckle\Facades\Huckle;
// Export all nodes for a partition
Huckle::exportContextToEnv([
'partition' => 'services',
]);
// Export all nodes for an environment
Huckle::exportContextToEnv([
'environment' => 'production',
]);
// Combine filters
Huckle::exportContextToEnv([
'partition' => 'database',
'environment' => 'production',
'provider' => 'main',
]);
Terminal window
# Show what would be exported (table format)
php artisan huckle:lint --table
# Filter by context
php artisan huckle:lint --table --environment=production
php artisan huckle:lint --table --partition=database