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.
Defining Exports
Section titled “Defining Exports”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 } } }}Exporting to Environment
Section titled “Exporting to Environment”# Export specific nodephp artisan huckle:export database.production.main
# Export all nodesphp artisan huckle:export --alluse Cline\Huckle\Facades\Huckle;
// Export specific node$node = Huckle::get('database.production.main');$node->exportToEnv();
// Export by contextHuckle::exportContextToEnv([ 'partition' => 'database', 'environment' => 'production',]);Syncing to .env File
Section titled “Syncing to .env File”The huckle:sync command writes exported values directly to your .env file:
# Sync to default .envphp artisan huckle:sync
# Sync to specific filephp artisan huckle:sync --file=.env.production
# Preview changes without writingphp artisan huckle:sync --dry-runHow Syncing Works
Section titled “How Syncing Works”- Reads the current
.envfile - Finds all exported values from your nodes
- Updates existing keys or adds new ones
- Preserves comments and formatting
- Writes the updated file
Example Workflow
Section titled “Example Workflow”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 } } }}# 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_xxxContext-Based Export
Section titled “Context-Based Export”Export only nodes matching specific criteria:
use Cline\Huckle\Facades\Huckle;
// Export all nodes for a partitionHuckle::exportContextToEnv([ 'partition' => 'services',]);
// Export all nodes for an environmentHuckle::exportContextToEnv([ 'environment' => 'production',]);
// Combine filtersHuckle::exportContextToEnv([ 'partition' => 'database', 'environment' => 'production', 'provider' => 'main',]);Viewing Exports
Section titled “Viewing Exports”# Show what would be exported (table format)php artisan huckle:lint --table
# Filter by contextphp artisan huckle:lint --table --environment=productionphp artisan huckle:lint --table --partition=database