Skip to content

Conversation

@pedroespindula
Copy link

Description

This PR fixes an issue that prevented the creation of web type schedules in Grafana OnCall using Terraform. Although the provider was intended to support all schedule types, a validation conflict caused the creation of web schedules to fail.

The provider was incorrectly returning the error Error: time_zone can not be set with type: web.

image

This contradicted the Grafana OnCall API, which requires the time_zone field for this schedule type and would fail with the error Error: POST <oncall_api_url>/api/v1/schedules/: 400 {time_zone: [This field is required.]}.

image

This fix resolves the conflicting validation logic, allowing time_zone to be correctly passed to the API for web schedules.

Key Changes

  • time_zone logic: The validation for the time_zone field has been adjusted to allow its use with web type schedules, resolving the API conflict.
  • Forced recreation for web schedules: Implemented the CustomizeDiff function, which forces the resource to be recreated (ForceNew) whenever any of its attributes are changed and the type is web. This ensures that the Terraform state remains consistent, as changes in the Grafana UI are not reflected back into the state.
  • web schedule example: Added a new grafana_oncall_schedule resource example with type = "web" to demonstrate its correct usage, including the lifecycle { ignore_changes = all } block.

How to Test

  1. Create a new grafana_oncall_schedule resource with type = "web".
  2. Run terraform apply and verify that the schedule was created correctly in Grafana OnCall, whereas it would have failed before.
  3. Change an attribute in the .tf file (e.g., the name).
  4. Run terraform apply again and confirm that the old schedule was destroyed and a new one was created.
  5. To test the synchronization, add the lifecycle { ignore_changes = all } block to the resource, modify the schedule in the Grafana UI, and then run terraform plan. No changes should be detected.

Additional Details

  • API request that was made to On Call to create the Web Schedule manually:
curl --location '$GRAFANA_ONCALL_URL/api/v1/schedules/' \
--header 'Content-Type: application/json' \
--header 'Authorization: $GRAFANA_ONCALL_ACCESS_TOKEN' \
--data '{
    "name": "[TEST] Example Schedule",
    "type": "web",
    "time_zone": "UTC"
}'
  • Apply working with the modified version:
resource "grafana_oncall_schedule" "test" {
  name      = "[TEST] Example Schedule"
  type      = "web"
  time_zone = "UTC"
}
image
  • Replace working with the modified version:
image
  • If no attributes changed, nothing happens:
image
  • If ignore changes used, nothing happens:
resource "grafana_oncall_schedule" "test" {
  name      = "[TEST] Example Schedule - Changed"
  type      = "web"
  time_zone = "UTC"

  lifecycle {
    ignore_changes = all
  }
}
image image

@pedroespindula pedroespindula requested review from a team as code owners October 15, 2025 20:55
@pedroespindula pedroespindula requested review from gerardocorea and twu and removed request for a team October 15, 2025 20:55
@CLAassistant
Copy link

CLAassistant commented Oct 15, 2025

CLA assistant check
All committers have signed the CLA.

@pedroespindula pedroespindula force-pushed the fix/oncall-web-schedule-creation branch from 29af19f to 4d8d4c2 Compare October 15, 2025 20:55
@Duologic Duologic requested review from a team and removed request for a team October 27, 2025 13:38
@jwelch92
Copy link
Contributor

jwelch92 commented Nov 3, 2025

@pedroespindula Apologies for missing this PR! #2401 added support for creating web schedules with a time_zone field.

Does the linked PR fix the issue you're seeing, or is there another issue that is addressed by this PR? Thanks!

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.

3 participants