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

feat: add until parameter to grafana_oncall_on_call_shift resource #1830

Merged
merged 9 commits into from
Oct 3, 2024

Conversation

maltelehmann
Copy link
Contributor

@maltelehmann maltelehmann commented Oct 3, 2024

Manual tests:

Creating shift with until

terraform {
  required_providers {
    grafana = {
      source = "grafana/grafana"
    }
  }
}

provider "grafana" {
  url                 = "http://localhost:3000"
  oncall_url          = "http://localhost:8080"
  oncall_access_token = "<revoked>"
}

data "grafana_oncall_user" "admin" {
  username = "admin"
}

resource "grafana_oncall_on_call_shift" "example_shift" {
  name       = "Example Shift"
  type       = "recurrent_event"
  start      = "2024-09-07T14:00:00"
  until      = "2024-10-07T14:00:00"
  duration   = 60 * 60 * 4
  frequency  = "weekly"
  interval   = 2
  by_day     = ["MO", "TU", "WE", "TH", "FR"]
  week_start = "MO"
  users      = [data.grafana_oncall_user.admin.id]
  time_zone  = "UTC"
}

resource "grafana_oncall_schedule" "example_schedule" {
  name      = "Example Schadule"
  type      = "calendar"
  time_zone = "UTC"
  shifts    = [grafana_oncall_on_call_shift.example_shift.id]
}
 terraform apply -auto-approve
data.grafana_oncall_user.admin: Reading...
data.grafana_oncall_user.admin: Read complete after 0s [id=U32XDMQA668KJ]

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   = 14400
      + frequency  = "weekly"
      + id         = (known after apply)
      + interval   = 2
      + name       = "Example Shift"
      + start      = "2024-09-07T14:00:00"
      + time_zone  = "UTC"
      + type       = "recurrent_event"
      + until      = "2024-10-07T14:00:00"
      + users      = [
          + "U32XDMQA668KJ",
        ]
      + week_start = "MO"
    }

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

Plan: 2 to add, 0 to change, 0 to destroy.
grafana_oncall_on_call_shift.example_shift: Creating...
grafana_oncall_on_call_shift.example_shift: Creation complete after 0s [id=OHG7MJ9RASQ8Z]
grafana_oncall_schedule.example_schedule: Creating...
grafana_oncall_schedule.example_schedule: Creation complete after 0s [id=SDVXPQFWIA8C6]

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

recurrent shift ends on until date (biweekly recurring shift):

image

Update until of existing shift

# ...
resource "grafana_oncall_on_call_shift" "example_shift" {
  name       = "Example Shift"
  type       = "recurrent_event"
  start      = "2024-09-07T14:00:00"
  until      = "2024-10-14T14:00:00"
  duration   = 60 * 60 * 4
  frequency  = "weekly"
  interval   = 2
  by_day     = ["MO", "TU", "WE", "TH", "FR"]
  week_start = "MO"
  users      = [data.grafana_oncall_user.admin.id]
  time_zone  = "UTC"
}
# ...
terraform apply -auto-approve
data.grafana_oncall_user.admin: Reading...
data.grafana_oncall_user.admin: Read complete after 1s [id=U32XDMQA668KJ]
grafana_oncall_on_call_shift.example_shift: Refreshing state... [id=OHG7MJ9RASQ8Z]
grafana_oncall_schedule.example_schedule: Refreshing state... [id=SDVXPQFWIA8C6]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # grafana_oncall_on_call_shift.example_shift will be updated in-place
  ~ resource "grafana_oncall_on_call_shift" "example_shift" {
        id                             = "OHG7MJ9RASQ8Z"
        name                           = "Example Shift"
      ~ until                          = "2024-10-07T14:00:00" -> "2024-10-14T14:00:00"
        # (14 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
grafana_oncall_on_call_shift.example_shift: Modifying... [id=OHG7MJ9RASQ8Z]
grafana_oncall_on_call_shift.example_shift: Modifications complete after 0s [id=OHG7MJ9RASQ8Z]

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

Shifts ends later (biweekly recurring shift):

image

Update remove until

# ...
resource "grafana_oncall_on_call_shift" "example_shift" {
  name       = "Example Shift"
  type       = "recurrent_event"
  start      = "2024-09-07T14:00:00"
  duration   = 60 * 60 * 4
  frequency  = "weekly"
  interval   = 2
  by_day     = ["MO", "TU", "WE", "TH", "FR"]
  week_start = "MO"
  users      = [data.grafana_oncall_user.admin.id]
  time_zone  = "UTC"
}
# ...
terraform apply -auto-approve
data.grafana_oncall_user.admin: Reading...
data.grafana_oncall_user.admin: Read complete after 0s [id=U32XDMQA668KJ]
grafana_oncall_on_call_shift.example_shift: Refreshing state... [id=OHG7MJ9RASQ8Z]
grafana_oncall_schedule.example_schedule: Refreshing state... [id=SDVXPQFWIA8C6]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # grafana_oncall_on_call_shift.example_shift will be updated in-place
  ~ resource "grafana_oncall_on_call_shift" "example_shift" {
        id                             = "OHG7MJ9RASQ8Z"
        name                           = "Example Shift"
      - until                          = "2024-10-14T14:00:00" -> null
        # (14 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
grafana_oncall_on_call_shift.example_shift: Modifying... [id=OHG7MJ9RASQ8Z]
grafana_oncall_on_call_shift.example_shift: Modifications complete after 0s [id=OHG7MJ9RASQ8Z]

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

Shift does not end anymore:

image

single_event with until is not applied

# ...
resource "grafana_oncall_on_call_shift" "example_shift" {
  name       = "Example Shift"
  type       = "single_event"
  start      = "2024-09-07T14:00:00"
  until      = "2024-09-10T14:00:00"
  duration   = 60 * 60 * 4
  users      = [data.grafana_oncall_user.admin.id]
  time_zone  = "UTC"
}
# ...
terraform apply -auto-approve
data.grafana_oncall_user.admin: Reading...
data.grafana_oncall_user.admin: Read complete after 0s [id=U32XDMQA668KJ]
grafana_oncall_on_call_shift.example_shift: Refreshing state... [id=OHG7MJ9RASQ8Z]
grafana_oncall_schedule.example_schedule: Refreshing state... [id=SDVXPQFWIA8C6]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # grafana_oncall_on_call_shift.example_shift will be updated in-place
  ~ resource "grafana_oncall_on_call_shift" "example_shift" {
      ~ by_day                         = [
          - "FR",
          - "MO",
          - "TH",
          - "TU",
          - "WE",
        ]
      - frequency                      = "weekly" -> null
        id                             = "OHG7MJ9RASQ8Z"
      - interval                       = 2 -> null
        name                           = "Example Shift"
      ~ type                           = "recurrent_event" -> "single_event"
      + until                          = "2024-09-10T14:00:00"
      - week_start                     = "MO" -> null
        # (9 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
grafana_oncall_on_call_shift.example_shift: Modifying... [id=OHG7MJ9RASQ8Z]
╷
│ Error: `until` can not be set with type: single_event
│ 
│   with grafana_oncall_on_call_shift.example_shift,
│   on main.tf line 19, in resource "grafana_oncall_on_call_shift" "example_shift":
│   19: resource "grafana_oncall_on_call_shift" "example_shift" {
│ 
╵

Copy link

github-actions bot commented Oct 3, 2024

In order to lower resource usage and have a faster runtime, PRs will not run Cloud tests automatically.
To do so, a Grafana Labs employee must trigger the cloud acceptance tests workflow manually.

Copy link
Contributor

@joeyorlando joeyorlando left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the contribution @maltelehmann, just one small question on one of the tests.

Comment on lines 208 to 218
name = "%s"
type = "recurrent_event"
start = "2020-09-04T16:00:00"
start = "2020-10-04T16:00:00"
duration = 3600
level = 1
frequency = "weekly"
week_start = "SU"
interval = 2
by_day = ["MO", "FR"]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume until should be added here?

@joeyorlando joeyorlando changed the title feat: add until parameter to grafana_oncall_on_call_shift resource feat: add until parameter to grafana_oncall_on_call_shift resource Oct 3, 2024
@joeyorlando joeyorlando marked this pull request as ready for review October 3, 2024 13:40
@joeyorlando joeyorlando requested review from a team as code owners October 3, 2024 13:40
@joeyorlando joeyorlando merged commit c20d360 into grafana:main Oct 3, 2024
20 of 26 checks passed
@joeyorlando
Copy link
Contributor

thanks for the contribution @maltelehmann we'll try and cut a v3.9.0 release next week!

@maltelehmann
Copy link
Contributor Author

@joeyorlando thank you very much for your swift responses and your feedback :)

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.

2 participants