Skip to content

docs: clarify cron attribute format for coder_script resource #409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

blink-so[bot]
Copy link

@blink-so blink-so bot commented Jun 4, 2025

This PR addresses issue #353 by clarifying the cron format documentation for the coder_script resource.

Changes Made

  • Updated cron description: Clarified that the cron attribute uses a 6-field format (seconds minutes hours day-of-month month day-of-week) instead of the standard Unix 5-field format
  • Fixed misleading example: Changed "0 22 * * *" to "0 0 22 * * *" to show proper 6-field format
  • Added helpful examples: Included multiple cron examples with inline comments explaining the schedule
  • Added additional example: Created a new example showing every 5 minutes schedule

Problem Solved

The original issue was that users expected the standard Unix cron format (minutes hours day month day-of-week) but the provider actually uses a 6-field format that includes seconds as the first field. This caused confusion where a user's "*/5 * * * *" (intended for every 5 minutes) was actually running every 5 seconds.

Testing

The documentation changes have been tested by verifying the cron parser configuration in provider/script.go which shows:

var ScriptCRONParser = cron.NewParser(cron.Second | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.DowOptional | cron.Descriptor)

This confirms the 6-field format is correct.

Fixes #353

Copy link

github-actions bot commented Jun 4, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@matifali matifali requested review from jatcod3r and kylecarbs June 4, 2025 11:05
blink-so bot added 5 commits June 4, 2025 15:06
- Update cron description to specify 6-field format (seconds minutes hours day month day-of-week)
- Fix misleading example that used 5-field Unix format
- Add additional cron examples with proper 6-field format
- Include inline comments explaining the schedule

Fixes #353
- Detect when users provide Unix 5-field cron format
- Provide helpful warning with suggested 6-field conversion
- Maintain backwards compatibility - expressions still work
- Add comprehensive tests for validation function

This helps users avoid confusion where '*/5 * * * *' (intended for
every 5 minutes) actually runs every 5 seconds due to the missing
seconds field.
- Added the missing every_5_minutes cron script example to examples/resources/coder_script/resource.tf
- This example demonstrates the 6-field cron format with a health check that runs every 5 minutes
- Ensures examples directory matches the documentation examples
- Updated the cron field description in provider/script.go to include detailed 6-field format explanation
- Fixed formatting issues in documentation (removed extra spaces before comments)
- Regenerated documentation to ensure consistency between schema and docs
- This ensures the documentation generation preserves the detailed cron description instead of reverting to generic text
@blink-so blink-so bot force-pushed the fix-cron-documentation branch from e998cb2 to e810230 Compare June 4, 2025 15:06
@matifali matifali requested a review from Copilot June 4, 2025 15:07
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR clarifies the cron attribute format used by the coder_script resource, addressing issue #353 by updating documentation and examples to reflect the usage of a 6-field cron format.

  • Updated cron description in resource schema and docs
  • Fixed misleading example by converting a 5-field expression to a correct 6-field expression
  • Added tests to validate cron expressions and introduced a new example for an every 5 minutes schedule

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
provider/script_test.go Added tests for various cron expression scenarios
provider/script.go Introduced ValidateCronExpression and updated the resource's validation logic
examples/resources/coder_script/resource.tf Updated resource examples to use the correct 6-field cron format
docs/resources/script.md Updated documentation for the cron attribute to clarify the 6-field format

@matifali matifali requested a review from johnstcn June 4, 2025 15:17
Copy link

@jatcod3r jatcod3r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description looks good to me! I tested out the 6-field format too and it works per what example describes.

I'm not sure about the new function though. I don't know how to test this myself, but it looks like the runner was able to verify it: https://github.com/coder/terraform-provider-coder/actions/runs/15445849660

Would be good to get someone to test out the resource change, but overall this looks great to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

docs: better description for the cron attribute of coder_script
2 participants