TTL & Automatic Cleanup

Time-to-Live (TTL) ensures environments are automatically cleaned up after a specified duration, preventing resource waste and unexpected costs.

Overview

Every environment can have a TTL that specifies how long it should exist. When the TTL expires:

  1. Warning notifications are sent (24h, 1h, 10min before)
  2. A final checkpoint is created (if enabled)
  3. The environment is terminated
  4. All resources are released

TTL Configuration

Setting TTL at Creation

# Create with 8-hour TTL
teactl env create --blueprint workshop --name march-training --ttl 8h

# Create with 3-day TTL
teactl env create --blueprint demo --name client-demo --ttl 3d

# Create without TTL (runs indefinitely)
teactl env create --blueprint dev --name my-sandbox --no-ttl

TTL in Blueprints

Define default TTL in your blueprint:

apiVersion: teabar.dev/v1
kind: Blueprint
metadata:
  name: workshop-environment
spec:
  ttl:
    default: 8h          # Default TTL for environments
    max: 24h             # Maximum allowed TTL
    extendable: true     # Allow users to extend TTL
    max_extensions: 3    # Maximum number of extensions

TTL Hierarchy

TTL values are resolved in this order (first non-null wins):

  1. Environment-specific - Set at creation or via extend
  2. Blueprint default - Defined in the blueprint
  3. Project default - Project-level setting
  4. Organization default - Organization-level setting
  5. System default - Platform default (usually 24h for SaaS)
# View effective TTL configuration
teactl env get march-training --show-ttl-source

TTL Countdown Behavior

Running Environments

TTL counts down while the environment is in RUNNING state.

Sleeping Environments

By default, TTL pauses when an environment is sleeping:

# In blueprint or project config
ttl:
  count_while_sleeping: false  # Default: pause TTL during sleep

To continue countdown during sleep:

ttl:
  count_while_sleeping: true

State Transitions

StateTTL Behavior
PROVISIONINGNot counting (environment not ready)
RUNNINGCounting down
SLEEPINGPaused (configurable)
TERMINATINGNot applicable

Extending TTL

Add Time

# Add 4 more hours
teactl env extend march-training --add 4h

# Add 1 day
teactl env extend march-training --add 1d

Set Absolute Expiration

# Extend until specific time
teactl env extend march-training --until "2024-01-20 18:00"

# Extend until end of day
teactl env extend march-training --until "today 23:59"

Remove TTL

# Remove TTL (environment runs indefinitely)
teactl env extend march-training --no-ttl

Extension Limits

Blueprints can limit extensions:

ttl:
  extendable: true
  max_extensions: 3        # Max 3 extensions allowed
  max_extension_time: 24h  # Max time per extension
  max_total: 7d            # Maximum total lifetime

Check remaining extensions:

teactl env get march-training

# Output includes:
# TTL: 2h remaining (extended 2/3 times)

Expiration Warnings

Default Warning Schedule

Time Before ExpiryNotification
24 hoursEmail + Slack (if configured)
1 hourEmail + Slack + CLI notification
10 minutesAll channels + terminal banner

Configuring Warnings

# Project or organization config
notifications:
  ttl_warnings:
    - time: 24h
      channels: [email]
    - time: 1h
      channels: [email, slack]
    - time: 10m
      channels: [email, slack, webhook]

Viewing Expiring Environments

# List environments expiring soon
teactl env list --expiring

# List environments expiring within 2 hours
teactl env list --expiring --within 2h

Sample output:

NAME             STATUS    TTL REMAINING   EXPIRES AT
march-training   Running   1h 30m          2024-01-15 16:30 UTC
demo-env         Running   45m             2024-01-15 15:45 UTC
test-workshop    Sleeping  4h              2024-01-15 19:00 UTC

Grace Period

After TTL expires, there’s a grace period before deletion:

ttl:
  grace_period: 30m  # 30 minutes grace period

During grace period:

  • Environment is marked as EXPIRED
  • Warning banner shown to all users
  • Final checkpoint created
  • Environment can still be extended
# Extend expired environment (during grace period)
teactl env extend march-training --add 2h

Final Checkpoint

Before termination, Teabar can create a final checkpoint:

ttl:
  final_checkpoint: true
  checkpoint_retention: 30d  # Keep final checkpoint for 30 days

Access final checkpoints:

# List checkpoints including final ones
teactl checkpoint list --include-final

# Restore from final checkpoint
teactl env create --from-checkpoint march-training-final

Cleanup Process

When TTL expires and grace period ends:

  1. Pre-termination hook runs (if configured)
  2. Final checkpoint created (if enabled)
  3. Environment terminated - all resources deleted
  4. Notification sent - confirmation of cleanup
  5. Billing stopped - no further charges

Pre-termination Hook

Run custom scripts before cleanup:

ttl:
  pre_termination:
    - name: Export data
      command: /scripts/export-data.sh
      timeout: 5m

Cost Implications

TTL directly impacts costs:

# View cost projection based on TTL
teactl env get march-training --show-cost-projection

# Output:
# Current cost: $12.50
# TTL remaining: 4h
# Projected total: $18.50

Cost Optimization Tips

  1. Set appropriate TTLs - Don’t use longer than needed
  2. Use sleep mode - Pause TTL and reduce compute costs
  3. Extend incrementally - Add small amounts vs. removing TTL
  4. Review expiring envs - Clean up before they expire

CLI Reference

CommandDescription
teactl env create --ttl <duration>Create with TTL
teactl env create --no-ttlCreate without TTL
teactl env extend --add <duration>Add time to TTL
teactl env extend --until <datetime>Set absolute expiration
teactl env extend --no-ttlRemove TTL
teactl env list --expiringList expiring environments
teactl env get --show-ttl-sourceShow TTL configuration source

See Also

ende