Skip to content
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

When creating an oncall-shift via the public API, rolling_users is not validated #5041

Closed
joeyorlando opened this issue Sep 18, 2024 · 0 comments · Fixed by #5050
Closed
Labels
bug Something isn't working part:Terraform/Crossplane

Comments

@joeyorlando
Copy link
Contributor

What went wrong?

What happened:

Below is a reproducible example via Terraform:

terraform {
  required_version = ">= 1.5.1"
  required_providers {
    grafana = {
      source  = "grafana/grafana"
      version = ">= 2.0.0"
    }
  }
}


provider "grafana" {
  alias               = "oncall"
  oncall_access_token = "<redacted>"
  oncall_url          = "http://localhost:8080/"
}

data "grafana_oncall_user" "joey" {
  provider = grafana.oncall
  username = "joey"
}

data "grafana_oncall_user" "bob" {
  provider = grafana.oncall
  username = "bob"
}

resource "grafana_oncall_on_call_shift" "example_shift" {
  provider = grafana.oncall
  name       = "Example Shift"
  type       = "rolling_users"
  start      = "2024-09-19T14:00:00"
  duration   = 60 * 60 * 12
  frequency  = "weekly"
  interval   = 1
  by_day     = ["MO", "TU", "WE", "TH", "FR"]
  week_start = "MO"
  rolling_users = [
    ["foo"],
    ["bar"],
    # [data.grafana_oncall_user.bob.id],
    # [data.grafana_oncall_user.joey.id],
  ]
  time_zone = "UTC"
}

resource "grafana_oncall_schedule" "example_schedule" {
  provider = grafana.oncall
  name      = "Example Calendar Schadule"
  type      = "calendar"
  time_zone = "America/New_York"
  shifts = [
    grafana_oncall_on_call_shift.example_shift.id,
  ]
}

Then:

❯ terraform apply
data.grafana_oncall_user.bob: Reading...
data.grafana_oncall_user.joey: Reading...
data.grafana_oncall_user.joey: Read complete after 0s [id=U95J3KBUFXM8J]
data.grafana_oncall_user.bob: Read complete after 0s [id=USSSBK861DG8H]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # grafana_oncall_on_call_shift.example_shift will be created
  + resource "grafana_oncall_on_call_shift" "example_shift" {
      + by_day        = [
          + "FR",
          + "MO",
          + "TH",
          + "TU",
          + "WE",
        ]
      + duration      = 43200
      + frequency     = "weekly"
      + id            = (known after apply)
      + interval      = 1
      + name          = "Example Shift"
      + rolling_users = [
          + [
              + "foo",
            ],
          + [
              + "bar",
            ],
        ]
      + start         = "2024-09-19T14:00:00"
      + time_zone     = "UTC"
      + type          = "rolling_users"
      + week_start    = "MO"
    }

  # grafana_oncall_schedule.example_schedule will be created
  + resource "grafana_oncall_schedule" "example_schedule" {
      + id        = (known after apply)
      + name      = "Example Calendar Schadule"
      + shifts    = (known after apply)
      + time_zone = "America/New_York"
      + type      = "calendar"
    }

Plan: 2 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

grafana_oncall_on_call_shift.example_shift: Creating...
grafana_oncall_on_call_shift.example_shift: Creation complete after 0s [id=ORYHWWAVT9D6Y]
grafana_oncall_schedule.example_schedule: Creating...
grafana_oncall_schedule.example_schedule: Creation complete after 0s [id=SXAGQRJCI1AH4]

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

The oncall shift is created and persisted as such:

{
    "id": 3,
    "public_primary_key": "ORYHWWAVT9D6Y",
    "name": "Example Shift",
    "time_zone": "UTC",
    "source": 3,
    "rolling_users": "[{}, {}]",
    "start_rotation_from_user_index": 0,
    "uuid": "17adca68f6ee43ec9a7a56008f7896f4",
    "type": 2,
    "start": "2024-09-19 14:00:00",
    "duration": 43200000000,
    "frequency": 1,
    "priority_level": 0,
    "interval": 1,
    "week_start": 0,
    "by_day": "[\"MO\", \"WE\", \"FR\", \"TU\", \"TH\"]",
    "by_month": null,
    "by_monthday": null,
    "organization_id": 1,
    "team_id": null,
    "until": null,
    "schedule_id": null,
    "rotation_start": "2024-09-19 14:00:00",
    "updated_shift_id": null
  }

What did you expect to happen:
I would expect the OnCall API and/or Terraform to complain about the values being passed not being valid Grafana OnCall user IDs

How do we reproduce it?

See above steps for detailed repro steps

Grafana OnCall Version

v1.9.25

Product Area

Terraform/Crossplane

Grafana OnCall Platform?

None

User's Browser?

No response

Anything else to add?

No response

@joeyorlando joeyorlando added the bug Something isn't working label Sep 18, 2024
github-merge-queue bot pushed a commit that referenced this issue Sep 20, 2024
# What this PR does
Adds validation for rolling users param in the shift api

## Which issue(s) this PR closes
Closes [5041](#5041)

<!--
*Note*: If you want the issue to be auto-closed once the PR is merged,
change "Related to" to "Closes" in the line above.
If you have more than one GitHub issue that this PR closes, be sure to
preface
each issue link with a [closing
keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue).
This ensures that the issue(s) are auto-closed once the PR has been
merged.
-->

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working part:Terraform/Crossplane
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant