Pulumi Any Terraform

Time Provider

Manage time-based resources and operations with Pulumi

The Time provider enables you to manage time-based resources like delays, offsets, and rotations in your infrastructure code. This provider is dynamically bridged from the Terraform Time Provider.

Installation

Install the Time provider package using your preferred package manager:

bun add pulumi-time
pnpm add pulumi-time
yarn add pulumi-time
npm install pulumi-time

Configuration

No configuration required - the Time provider works out of the box.

Quick Start

import * as pulumi from "@pulumi/pulumi";
import * as time from "pulumi-time";

// Create a delay
const delay = new time.Sleep("wait-for-deployment", {
    createDuration: "30s", // Wait 30 seconds
});

// Use the delay in resource dependencies
const resource = new SomeResource("dependent", {
    // Resource properties
}, { dependsOn: [delay] });

Key Features

Delays

Add delays between resource operations:

// Wait 60 seconds before creating next resource
const delay = new time.Sleep("deployment-delay", {
    createDuration: "60s",
});

// Wait 30 seconds before destroying
const deleteDelay = new time.Sleep("cleanup-delay", {
    destroyDuration: "30s",
});

Time Offsets

Calculate time offsets:

const offset = new time.Offset("future-time", {
    offsetDays: 30,
    offsetHours: 12,
    offsetMinutes: 30,
});

export const expirationTime = offset.rfc3339;

Time Rotation

Rotate resources on a schedule:

const rotation = new time.Rotating("monthly-rotation", {
    rotationDays: 30,
});

// Use rotation trigger
const secret = new SomeSecret("rotated-secret", {
    value: pulumi.interpolate`secret-${rotation.id}`,
});

Static Times

Create static time values:

const staticTime = new time.Static("timestamp", {});

export const createdAt = staticTime.rfc3339;

Common Use Cases

Staged Deployment

import * as pulumi from "@pulumi/pulumi";
import * as time from "pulumi-time";

// Deploy database
const database = new Database("db", { /* ... */ });

// Wait for database to stabilize
const dbDelay = new time.Sleep("db-stabilize", {
    createDuration: "60s",
}, { dependsOn: [database] });

// Deploy application after delay
const app = new Application("app", {
    databaseUrl: database.connectionString,
}, { dependsOn: [dbDelay] });

Certificate Rotation

const rotation = new time.Rotating("cert-rotation", {
    rotationDays: 90, // Rotate every 90 days
});

const certificate = new Certificate("cert", {
    // Certificate properties
    rotationTrigger: rotation.id,
});

Scheduled Resource Updates

const monthlyRotation = new time.Rotating("monthly", {
    rotationDays: 30,
});

const apiKey = new ApiKey("key", {
    name: pulumi.interpolate`key-${monthlyRotation.id}`,
});

Duration Format

Durations use Go's time format:

  • s = seconds
  • m = minutes
  • h = hours
  • Examples: 30s, 5m, 2h, 1h30m

Best Practices

1. Use Delays for External Dependencies

// Wait for external service
const externalDelay = new time.Sleep("external-ready", {
    createDuration: "120s",
});

2. Implement Graceful Shutdowns

const shutdownDelay = new time.Sleep("graceful-shutdown", {
    destroyDuration: "30s",
});

3. Rotate Credentials Regularly

const credentialRotation = new time.Rotating("creds", {
    rotationDays: 90,
});