Skip to main content

Sleep Resource

Add time delays to resource provisioning
2 min read

The time.Sleep resource adds delays before or after resource creation/destruction, useful for waiting on external systems.

Example Usage#

Basic Delay#

Wait for Database#

Destruction Delay#

Both Create and Destroy Delays#

Argument Reference#

Optional Arguments#

  • createDuration (string): Duration to wait after creation (e.g., "30s", "5m", "1h").
  • destroyDuration (string): Duration to wait before destruction.
  • triggers (map): Arbitrary map that causes recreation when values change.

Duration Format#

Durations use Go duration format:

  • s - seconds
  • m - minutes
  • h - hours

Examples:

  • "30s" - 30 seconds
  • "5m" - 5 minutes
  • "1h30m" - 1 hour 30 minutes
  • "90s" - 90 seconds (1.5 minutes)

Use Cases#

Database Connection Delay#

Service Stabilization#

DNS Propagation Delay#

Graceful Shutdown#

API Rate Limiting#

Multi-Stage Deployment#

Best Practices#

Use Appropriate Durations#

Document Why Delays Are Needed#

Consider Alternatives#

Before using Sleep, consider if there's a better way:

Troubleshooting#

Delay Not Working#

Problem: Resources still fail despite delay

Solution: Increase duration or check if resource has readiness checks

Deployments Too Slow#

Problem: Delays making deployments unnecessarily slow

Solution: Use minimum necessary delays

Import#

Time sleep resources cannot be imported as they represent delays rather than existing infrastructure.

Notes#

  • Sleep occurs during pulumi up or pulumi destroy
  • Does not consume cloud resources (local operation)
  • Useful for eventual consistency delays
  • Consider using resource-specific readiness checks when available
  • All times are wall-clock time, not CPU time