Template Configuration»
This document provides comprehensive reference for writing template YAML configurations. Templates use a YAML-based configuration format that defines infrastructure, inputs, and deployment behavior.
Template Body Structure»
The template body uses YAML format with the templateSchema. Here's a minimal example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
Important
Templates use the templateSchema which requires the stacks array format (not a single stack object). Each stack must have a unique key field, and VCS configuration uses the reference structure with value and type fields.
Note: The space field is NOT allowed in Template schema stack definitions. Space assignment is handled at the template deployment level, not in the blueprint YAML.
Templating Restrictions
The following fields cannot use template expressions (${{ }}):
- Stack keys (
/stacks/*/key) - Must be static strings - Stack dependencies (
/stacks/*/depends_on/*) - Must be static references - All VCS fields (
/stacks/*/vcs/**) - Includingrepository,provider,namespace,reference.value,reference.type, etc. - Input definitions (
/inputs/**) - Includingid,name,type,options,default, etc.
Templating is allowed in fields like name, description, labels, autodeploy, environment variables, vendor configuration, and most other stack settings.
Input Types»
Templates support various input types to collect information from users:
| Type | Description | Use Case |
|---|---|---|
short_text |
Single-line text input | Names, identifiers, short values |
long_text |
Multi-line text area | Descriptions, configurations, scripts |
secret |
Masked sensitive input | Passwords, API keys, tokens |
number |
Integer input | Counts, port numbers, limits |
float |
Decimal number input | Percentages, ratios, measurements |
boolean |
Checkbox | Feature toggles, flags |
select |
Dropdown with options | Predefined choices like environments |
Input Definition»
Each input is defined with the following properties:
1 2 3 4 5 6 7 8 9 10 11 | |
Input Properties»
- id (required): Unique identifier used to reference the input in template expressions
- name (required): Human-readable display name shown in the deployment form
- description (optional): Help text explaining what the input is for
- type (required): Input type (see table above)
- default (optional): Default value if user doesn't provide one
- validations (optional): Validation rules to enforce
- options (required for select): Array of allowed values for select inputs
Input Validations»
Templates support validation rules to ensure users provide valid data:
String Validation»
1 2 3 4 5 6 | |
Number Validation»
1 2 3 4 5 6 7 8 | |
Boolean Validation»
1 2 | |
Select Validation»
1 2 3 4 5 6 7 | |
Using Template Variables»
Template variables can be referenced throughout your configuration using the ${{ }} syntax:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
Variable Syntax»
- Reference inputs:
${{ inputs.input_id }} - Use context variables:
${{ context.property }} - Use maps:
${{ maps[inputs.env].property }} - Apply CEL expressions:
${{ inputs.name.lowerAscii() }}
Templating Restrictions»
Warning
Not all fields support templating. The following paths cannot use ${{ }} expressions:
Structural Fields (must be static):
- stacks.*.key - Stack identifiers must be deterministic
- stacks.*.depends_on.* - Dependencies must be known at parse time
VCS Configuration (must be static):
- stacks.*.vcs.repository - Repository name
- stacks.*.vcs.provider - Provider type (GITHUB, GITLAB, etc.)
- stacks.*.vcs.namespace - Organization/namespace
- stacks.*.vcs.reference.value - Branch/tag/SHA value
- stacks.*.vcs.reference.type - Reference type (branch/tag/sha)
- stacks.*.vcs.project_root - Project root path
Input Definitions (must be static):
- inputs.*.id - Input identifiers
- inputs.*.name - Input display names
- inputs.*.type - Input types
- inputs.*.options - Select options
- inputs.*.default - Default values
- inputs.*.validations - Validation rules
Why these restrictions? These fields define the template's structure and must be deterministic at parse time. VCS fields determine which repository to use, so they cannot depend on runtime inputs.
What CAN be templated? Most other fields including name, description, labels, autodeploy, autoretry, administrative, environment variables, vendor settings, hooks, schedules, and attachments.
Context Variables»
Templates provide built-in context variables for dynamic values:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
Available Context Properties»
| Property | Type | Description |
|---|---|---|
context.deployment.created_at |
Timestamp | Creation date of deployment |
context.deployment.name |
String | Name of deployment |
context.deployment.slug |
String | Slug of deployment |
context.time |
Timestamp | UTC time of deployment |
context.random_string |
String | Random 6-character string |
context.random_number |
Number | Random number (0-1000000) |
context.random_uuid |
String | Random UUID |
context.user.login |
String | User's login name |
context.user.name |
String | User's full name |
context.user.account |
String | Account subdomain |
Stack Configuration»
Templates can configure all stack settings using the templateSchema:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
Note
Templates use the templateSchema format. Key differences from the Blueprint schema:
- Must use stacks array (not a single stack object)
- Each stack requires a unique key field
- VCS configuration uses reference.value and reference.type instead of direct branch, tag, or sha fields
- See the Template Schema Reference section for complete details
For complete stack configuration options, refer to the Stack Configuration documentation.
Multiple Stacks»
Templates can create multiple stacks in a single deployment:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
Note
When using multiple stacks, each stack must have a unique key field for dependency management.
Stack Dependencies»
You can create dependencies between stacks using the depends_on field or stack_dependency_references:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
Dependency Features»
- depends_on: Ensures stacks are created in order
- stack_dependency_references: Pass outputs from one stack to another as environment variables
- Multiple dependencies can be specified
- Prevents circular dependencies
Template Engine»
Templates use the same template engine as Blueprints, based on Google CEL. The implementation is available on GitHub.
Supported Functions»
CEL supports various built-in functions:
- String operations:
contains,startsWith,endsWith,matches,replace,lowerAscii,upperAscii,split,join - Operators:
*,/,-,+,==,!=,<,<=,>,>=,&&,||,!,?: - Type conversions:
string(),int(),bool()
CEL Expression Examples»
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
YAML Syntax Validity»
Reserved YAML characters (:, ?, >, |) within CEL expressions require quotes:
1 2 3 4 5 | |
Maps»
Maps allow you to preconfigure specific values and enable deterministic value selection:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
Note
Maps cannot reference inputs in their definitions, and inputs cannot reference maps.
Map Use Cases»
- Environment-specific configurations
- Predefined resource sizes (small, medium, large)
- Regional settings
- Tier-based configurations (bronze, silver, gold)
Schedules»
Templates support scheduling for drift detection and scheduled tasks:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
Schedule Types»
Drift Detection:
- Automatically check for configuration drift
- Option to reconcile differences automatically
- Configurable cron schedule
- Can ignore state file changes
Scheduled Tasks:
- Run arbitrary commands on a schedule
- Support for multiple scheduled tasks
- Each task has its own cron schedule
- Timezone configuration per task
Hooks»
Templates support lifecycle hooks for custom actions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
Hook Types»
- init: Run before/after initialization
- plan: Run before/after planning
- apply: Run before/after applying changes
- destroy: Run before/after destroying resources
- run: Run after any run completes
Hook Best Practices»
- Keep hooks simple: Complex logic belongs in the repository
- Use for notifications: Alert teams about deployments
- Validate inputs: Check prerequisites before operations
- Cleanup: Remove temporary files after runs
Best Practices»
Input Design»
Good input design:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
Bad input design:
1 2 3 4 5 6 7 8 | |
Template Structure»
- Organize inputs logically: Group related inputs together
- Use descriptive IDs: Make input IDs clear and meaningful
- Provide defaults: Set sensible defaults for optional inputs
- Add descriptions: Help users understand what each input does
- Validate thoroughly: Use validation rules to prevent errors
Variable Usage»
- Use maps for complex logic: Instead of many conditional expressions
- Keep expressions simple: Complex logic can be hard to debug
- Quote when needed: Remember YAML special character rules
- Use context variables: For unique identifiers and timestamps
Security»
- Mark secrets: Always use
secret: truefor sensitive values - Validate inputs: Prevent injection attacks with pattern validation
- Least privilege: Configure minimal required permissions
- Audit hooks: Review hook commands for security issues
Examples»
Simple Web Application»
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
Multi-Stack Application with Dependencies»
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
Environment-Based Configuration with Maps»
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
Schema»
The up-to-date schema of a Blueprint is available through a GraphQL query for authenticated users:
1 2 3 | |
Tip
Remember that there are multiple ways to interact with Spacelift. You can use the GraphQL API, the CLI, the Terraform Provider, or the web UI.
For simplicity, here is the current schema, but it might change in the future:
Click to expand
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 | |
TemplateSchema Key Differences»
Templates use the templateSchema format, which has important differences from the original Blueprint schema:
Required Changes»
| Aspect | Original Blueprint Schema | Template Schema |
|---|---|---|
| Stack Definition | Single stack object OR stacks array |
Only stacks array (required) |
| Stack Key | Not required | Each stack must have unique key field |
| VCS Reference | Direct fields: branch, tag, sha |
Structured: reference.value and reference.type |
| Space Field | Required space field in stack |
NOT allowed (assigned at deployment) |
| Stack Limit | Max 5 stacks | Max 10 stacks |
VCS Configuration Comparison»
Original Blueprint Schema:
1 2 3 4 | |
Template Schema:
1 2 3 4 5 6 | |
Reference Types»
The reference.type field accepts three values:
branch: Use a branch name (e.g.,main,develop)tag: Use a git tag (e.g.,v1.0.0)sha: Use a specific commit SHA (e.g.,abc123def456)
Tip
When a template version is published, it's automatically pinned to the current commit SHA of the specified branch/tag, ensuring deterministic deployments.
Available Stack Properties»
The templateSchema supports the following stack-level properties:
| Property | Type | Description |
|---|---|---|
key |
string | Required. Unique identifier for the stack (used in dependencies) |
name |
string | Required. Stack display name (can be templated) |
description |
string | Optional description (can be templated) |
labels |
array | Optional labels for categorization (can be templated) |
administrative |
boolean | Mark stack as administrative (can be templated) |
autodeploy |
boolean | Enable automatic deployment on VCS changes (can be templated) |
autoretry |
boolean | Enable automatic retry on failure (can be templated) |
vcs |
object | Required. VCS configuration (cannot be templated) |
vendor |
object | Required. Infrastructure tool configuration (Terraform, Pulumi, etc.) |
environment |
object | Environment variables and mounted files (can be templated) |
attachments |
object | Contexts, policies, and cloud integrations |
hooks |
object | Lifecycle hooks (init, plan, apply, destroy) |
schedules |
object | Drift detection and scheduled tasks (supports drift and tasks only) |
depends_on |
array | Stack dependencies (cannot be templated) |
runner_image |
string | Custom runner image |
worker_pool |
string | Worker pool ID |
secret_masking_enabled |
boolean | Enable secret masking in logs |
Note
Property names in Template schema are case-sensitive and use lowercase without underscores for boolean flags (e.g., autodeploy, not auto_deploy). Some properties from the original Blueprint schema are not available in Template schema.
Related Resources»
- Template Overview - General information about templates
- Templates Workbench - Creating and managing templates
- Template Deployments - Deploying from templates
- Blueprint Configuration - Similar configuration reference
- Stack Configuration - Stack settings reference