Instruqt Labs (beta)
  • Instruqt
  • Getting started
    • Setting up Version Control
    • Install Instruqt CLI
    • Creating your first lab
    • Configuration basics
    • Exploring the lab configuration
    • Adding your first chapter
    • Configuring sandboxes
    • Adding quizzes
    • Adding tasks and gating content
    • Finishing up
  • Documentation
    • Writing Lab Content
      • Project Structure
      • Markdown and Components
    • Integrations
      • Version Control
    • Lab reference
      • Content
        • Lab
        • Page
        • Activities
          • Task
          • Quiz
            • Multiple Choice
            • Single Choice
            • Text Answer
            • Numeric Answer
        • Layout
        • Tabs
          • Terminal
          • Service
          • Editor
          • External Website
          • Note
      • Sandbox
        • Containers
          • Container
          • Sidecar Container
        • Kubernetes
          • Cluster
          • Config
          • Helm
        • Nomad
          • Cluster
          • Job
        • Networking
          • Network
          • Ingress
        • Cloud Accounts
          • AWS
          • Azure
          • Google Cloud
        • Terraform
        • Template
        • Exec
        • Copy
        • Certificates
          • Root
          • Leaf
        • Random
          • Number
          • ID
          • UUID
          • Password
          • Creature
      • Functions
    • Tools
      • Instruqt CLI
    • Glossary
Powered by GitBook
On this page
  • Task
  • Condition
  • Script
  • Config
  • ParallelExec
  • Examples
Edit on GitHub
Export as PDF
  1. Documentation
  2. Lab reference
  3. Content
  4. Activities

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

Attribute
Description

SuccessMessage success_message type: string

The message to display when the task is successfully completed.

Configuration for the task. This configuration will be used for all scripts within the task.

The conditions that have to be met in order for the task to successfully be validated.

Computed Attributes

These attributes are computed when the config is parsed and applied, and are therefore only known at parsetime or runtime.

Attribute
Description

Meta ID meta.id string

The full ID of the resource e.g. `resource.type.name`. This is computed from the full resource path:

Meta Type meta.type string

The type of the resource. This taken from the type label of the resource definition.

Meta Name meta.name string

The name of the resource. This taken from the name label of the resource definition.


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

Attribute
Description

Name id required type: string

The id of the condition.

Description description required type: string

The description of the condition. This will be visible on the task in the frontend.

Configuration for the condition. This configuration will be used for all scripts within the condition. This overrides the configuration for the task.

The checks that need to be executed successfully in order for the condition to pass. Check scripts are triggered when a task is validated.

The solve scripts that are executed when skipping the condition.

The setup scripts that are executed when unlocking the condition.

The cleanup scripts that are executed when the condition is completed or skipped.

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

Attribute
Description

Script script required type: string

The file location of the script to execute.

The configuration for the script. This overrides the configuration for the task or condition.

FailureMessage failure_message type: string

The message to show if the check has failed.

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

Attribute
Description

The target resource to execute the script on.

User user type: string default: root

The user to execute the script as.

Group group type: string default: root

The group to execute the script as.

WorkingDirectory working_directory type: string default: /

The working directory to execute the script in.

Environment environment type: map[string]string

The environment variables to set for the script.

Timeout timeout type: int default: 30

The timeout in seconds for the script to execute.

SuccessExitCodes success_exit_codes type: []int default: []int{0}

The exit codes that are considered successful.

FailureExitCodes failure_exit_codes type: []int default: []int{}

The exit codes that are considered expected failures. Any other failure codes will be considered errors.

ParallelExec configures wether conditions or scripts are executed in parallel.

Computed Attributes

These attributes are computed when the config is parsed and applied, and are therefore only known at parsetime or runtime.


ParallelExec

Configures wether 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

Attribute
Description

Condition condition type: bool

Condition configures wether conditions are executed in parallel.

Check check type: bool

Check configures wether check scripts are executed in parallel.

Solve solve type: bool

Solve configures wether solve scripts are executed in parallel.

Setup setup type: bool

Setup configures wether setup scripts are executed in parallel.

Cleanup cleanup type: bool

Cleanup configures wether cleanup scripts are executed in parallel.

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'"
    }
  }
}
PreviousActivitiesNextQuiz

Last updated 1 month ago

Config config type: block

Conditions condition type: []block

Config config type: block

Checks check type: []block

Solves solve type: []block

Setups setup type: []block

Cleanups cleanup type: []block

Config config type: block

Target target type: Reference to

ParallelExec parallel_exec type: block

success_message = "Great job!"
config {
  target = resource.container.ubuntu
  user   = "root"
}
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"
  }
}
// given the following resource
resource "container" "ubuntu" {
  ...
}

// the resulting id will be
resource.container.ubuntu
// given the following resource
resource "container" "ubuntu" {
  ...
}

// the resulting type will be
container
// given the following resource
resource "container" "ubuntu" {
  ...
}

// the resulting name will be
ubuntu
condition "id" {
  ...
}
description = "Create a new file located at /tmp/hello"
config {
  target = resource.container.ubuntu
  user   = "root"
}
check {
  script = "scripts/first_task/file_exists.sh"
}
solve {
  script = "scripts/first_task/solve.sh"
}
setup {
  script = "scripts/first_task/setup_directory.sh"
}
cleanup {
  script = "scripts/first_task/cleanup_directory.sh"
}
  script = "scripts/tasks/my_script.sh"
config {
  target = resource.container.ubuntu
  user   = "root"
}
failure_message = "The number of pods was incorrect, did you create the deployment?"
target = resource.container.ubuntu
user = "root"
group = "root"
working_directory = "/tmp"
environment = {
  VAULT_ADDR = "http://localhost:8200"
}
timeout = 30
success_exit_codes = [0]
failure_exit_codes = [1, 3]
parallel_exec {
  condition = true
  check = true
}
condition = true
check = true
solve = true
setup = true
cleanup = true
Container
Config
Condition
Config
Script
Script
Script
Script
Config
ParallelExec