Task
Task
The task
resource is the new form of the lifecycle scripts, that can now be embedded anywhere on a page within the instructions.
Each task resource can have multiple condition
blocks that need to be met before the task is completed, which in turn
can have multiple of each type of lifecycle block and each of the blocks are executed in sequence in the order they appear in code.
resource "task" "name" {
...
}
Attributes
SuccessMessage success_message
type: string
The message to display when the task is successfully completed.
success_message = "Great job!"
Config config
type: block
Config
Configuration for the task. This configuration will be used for all scripts within the task.
config {
target = resource.container.ubuntu
user = "root"
}
Conditions condition
type: []block
Condition
The conditions that have to be met in order for the task to successfully be validated.
condition "create_file" {
description = "Create a new file located at /tmp/hello"
config {
target = resource.container.ubuntu
}
check {
script = "scripts/first_task/my_check.sh"
}
}
Computed Attributes
These attributes are computed when the config is parsed and applied, and are therefore only known at parsetime or runtime.
Meta ID meta.id
string
The full ID of the resource e.g. `resource.type.name`. This is computed from the full resource path:
// given the following resource
resource "container" "ubuntu" {
...
}
// the resulting id will be
resource.container.ubuntu
Meta Type meta.type
string
The type of the resource. This taken from the type label of the resource definition.
// given the following resource
resource "container" "ubuntu" {
...
}
// the resulting type will be
container
Meta Name meta.name
string
The name of the resource. This taken from the name label of the resource definition.
// given the following resource
resource "container" "ubuntu" {
...
}
// the resulting name will be
ubuntu
Condition
A condition
is a partial validation for a task. Conditions can be used to split up bigger task into smaller pieces, allowing for more granular feedback to users.
resource "task" "task" {
condition "name" {
...
}
}
Attributes
Name id
required
type: string
The id of the condition.
condition "id" {
...
}
Description description
required
type: string
The description of the condition. This will be visible on the task in the frontend.
description = "Create a new file located at /tmp/hello"
Config config
type: block
Config
Configuration for the condition. This configuration will be used for all scripts within the condition. This overrides the configuration for the task.
config {
target = resource.container.ubuntu
user = "root"
}
Checks check
type: []block
Script
The checks that need to be executed successfully in order for the condition to pass. Check scripts are triggered when a task is validated.
check {
script = "scripts/first_task/file_exists.sh"
}
Solves solve
type: []block
Script
The solve scripts that are executed when skipping the condition.
solve {
script = "scripts/first_task/solve.sh"
}
Setups setup
type: []block
Script
The setup scripts that are executed when unlocking the condition.
setup {
script = "scripts/first_task/setup_directory.sh"
}
Cleanups cleanup
type: []block
Script
The cleanup scripts that are executed when the condition is completed or skipped.
cleanup {
script = "scripts/first_task/cleanup_directory.sh"
}
Computed Attributes
These attributes are computed when the config is parsed and applied, and are therefore only known at parsetime or runtime.
Script
A script that gets executed in the lifecycle of a lab. The script can be used to check the state of the lab, solve a challenge, setup the lab, or cleanup the lab, etc.
resource "task" "task" {
condition "condition" {
check {
...
}
solve {
...
}
setup {
...
}
cleanup {
...
}
}
}
Attributes
Script script
required
type: string
The file location of the script to execute.
script = "scripts/tasks/my_script.sh"
Config config
type: block
Config
The configuration for the script. This overrides the configuration for the task or condition.
config {
target = resource.container.ubuntu
user = "root"
}
FailureMessage failure_message
type: string
The message to show if the check has failed.
failure_message = "The number of pods was incorrect, did you create the deployment?"
Computed Attributes
These attributes are computed when the config is parsed and applied, and are therefore only known at parsetime or runtime.
Config
The configuration for scripts.
resource "task" "task" {
# Default configuration for all conditions and their scripts.
config {
...
}
}
resource "task" "task" {
condition "condition" {
# Default configuration for all scripts in this condition.
config {
...
}
}
}
resource "task" "task" {
condition "condition" {
# Setup, check, solve, or cleanup.
check {
# Configuration the specific script.
config {
...
}
}
}
}
Attributes
Target target
type: Reference to Container
The target resource to execute the script on.
target = resource.container.ubuntu
User user
type: string
default: root
The user to execute the script as.
user = "root"
Group group
type: string
default: root
The group to execute the script as.
group = "root"
WorkingDirectory working_directory
type: string
default: /
The working directory to execute the script in.
working_directory = "/tmp"
Environment environment
type: map[string]string
The environment variables to set for the script.
environment = {
VAULT_ADDR = "http://localhost:8200"
}
Timeout timeout
type: int
default: 30
The timeout in seconds for the script to execute.
timeout = 30
SuccessExitCodes success_exit_codes
type: []int
default: []int{0}
The exit codes that are considered successful.
success_exit_codes = [0]
FailureExitCodes failure_exit_codes
type: []int
default: []int{}
The exit codes that are considered expected failures. Any other failure codes will be considered errors.
failure_exit_codes = [1, 3]
ParallelExec parallel_exec
type: block
ParallelExec
ParallelExec configures whether conditions or scripts are executed in parallel.
parallel_exec {
condition = true
check = true
}
Computed Attributes
These attributes are computed when the config is parsed and applied, and are therefore only known at parsetime or runtime.
ParallelExec
Configures whether conditions or scripts are executed in parallel.
resource "task" "task" {
config {
# Default configuration for all conditions and their scripts.
parallel_exec {
...
}
}
}
resource "task" "task" {
condition "condition" {
config {
# Default configuration for all scripts in this condition.
parallel_exec {
...
}
}
}
}
Attributes
Condition condition
type: bool
Condition configures whether conditions are executed in parallel.
condition = true
Check check
type: bool
Check configures whether check scripts are executed in parallel.
check = true
Solve solve
type: bool
Solve configures whether solve scripts are executed in parallel.
solve = true
Setup setup
type: bool
Setup configures whether setup scripts are executed in parallel.
setup = true
Cleanup cleanup
type: bool
Cleanup configures whether cleanup scripts are executed in parallel.
cleanup = true
Computed Attributes
These attributes are computed when the config is parsed and applied, and are therefore only known at parsetime or runtime.
Examples
Full Example
resource "task" "first_task" {
config {
target = resource.container.ubuntu
parallel_exec {
condition = true
}
}
condition "file_exists" {
description = "The file exists"
config {
target = resource.container.ubuntu
}
check {
script = "scripts/first_task/file_exists.sh"
failure_message = "The file could not be found at /tmp/hello"
}
solve {
script = "scripts/first_task/solve.sh"
}
}
condition "contents_match" {
description = "The contents of the file contains the word 'world'"
check {
script = "scripts/first_task/contents_match.sh"
failure_message = "The file does not contain the word 'world'"
}
}
}
Last updated