Skip to content

ryutaro-asada/terraform-provider-cronmath

Repository files navigation

Terraform Provider CronMath

Release Registry Go Report Card Tests License: MPL-2.0

The CronMath provider allows you to perform time arithmetic operations on cron expressions within your Terraform configurations. It uses the cronmath library for cron expression manipulation.

Features

  • ➕ Add minutes or hours to cron expressions
  • ➖ Subtract minutes or hours from cron expressions
  • 🔄 Handle day boundary transitions automatically
  • 🌍 Perfect for timezone adjustments
  • ⏰ Create staggered schedules easily

Requirements

Installation

From Terraform Registry

terraform {
  required_providers {
    cronmath = {
      source  = "ryutaro-asada/cronmath"
      version = "~> 1.0"
    }
  }
}

provider "cronmath" {
  # No configuration required
}

Manual Installation

  1. Download the latest release from the releases page
  2. Extract the archive
  3. Move the binary to ~/.terraform.d/plugins/registry.terraform.io/ryutaro-asada/cronmath/1.0.0/[OS]_[ARCH]/

Usage

Data Source: cronmath_calculate

Calculate a new cron expression by applying time operations:

data "cronmath_calculate" "morning_job" {
  input = "30 9 * * *"  # 9:30 AM
  
  operations {
    type  = "sub"
    value = 30
    unit  = "minutes"
  }
}

output "adjusted_schedule" {
  value = data.cronmath_calculate.morning_job.result  # "0 9 * * *"
}

Examples

Timezone Adjustment

# Convert UTC to EST (UTC-5)
data "cronmath_calculate" "est_schedule" {
  input = "0 15 * * *"  # 3:00 PM UTC
  
  operations {
    type  = "sub"
    value = 5
    unit  = "hours"
  }
}

# Convert UTC to JST (UTC+9)
data "cronmath_calculate" "jst_schedule" {
  input = "0 10 * * *"  # 10:00 AM UTC
  
  operations {
    type  = "add"
    value = 9
    unit  = "hours"
  }
}

Building the Provider

# Clone the repository
git clone https://github.com/ryutaro-asada/terraform-provider-cronmath.git
cd terraform-provider-cronmath

# Download dependencies
go mod download

# Build the provider
make build

# Install locally for testing
make install

Running Tests

# Run unit tests
make test

# Run acceptance tests
make testacc

# Run specific test
go test -v -run TestCronMathDataSource ./internal/provider/

License

This project is licensed under the Mozilla Public License 2.0 - see the LICENSE file for details.

Support

For bugs and feature requests, please open an issue.

Related Projects

Acknowledgments

About

Terraform Provider for Cron expression

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors