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

time_restriction support to team_routing_rule #27

Merged
merged 18 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
### Contributors

<!-- markdownlint-disable -->
| [![Marcin Brański][3h4x_avatar]][3h4x_homepage]<br/>[Marcin Brański][3h4x_homepage] | [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]<br/>[Andriy Knysh][aknysh_homepage] | [![Igor Rodionov][goruha_avatar]][goruha_homepage]<br/>[Igor Rodionov][goruha_homepage] | [![Yonatan Koren][korenyoni_avatar]][korenyoni_homepage]<br/>[Yonatan Koren][korenyoni_homepage] |
|---|---|---|---|---|
| [![Marcin Brański][3h4x_avatar]][3h4x_homepage]<br/>[Marcin Brański][3h4x_homepage] | [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]<br/>[Andriy Knysh][aknysh_homepage] | [![Igor Rodionov][goruha_avatar]][goruha_homepage]<br/>[Igor Rodionov][goruha_homepage] | [![Yonatan Koren][korenyoni_avatar]][korenyoni_homepage]<br/>[Yonatan Koren][korenyoni_homepage] | [![Benjamin Smith][benbentwo_avatar]][benbentwo_homepage]<br/>[Benjamin Smith][benbentwo_homepage] |
|---|---|---|---|---|---|
<!-- markdownlint-restore -->

[3h4x_homepage]: https://github.com/3h4x
Expand All @@ -436,6 +436,8 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
[goruha_avatar]: https://img.cloudposse.com/150x150/https://github.com/goruha.png
[korenyoni_homepage]: https://github.com/korenyoni
[korenyoni_avatar]: https://img.cloudposse.com/150x150/https://github.com/korenyoni.png
[benbentwo_homepage]: https://github.com/benbentwo
[benbentwo_avatar]: https://img.cloudposse.com/150x150/https://github.com/benbentwo.png

[![README Footer][readme_footer_img]][readme_footer_link]
[![Beacon][beacon]][website]
Expand Down
2 changes: 2 additions & 0 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,5 @@ contributors:
github: "goruha"
- name: "Yonatan Koren"
github: "korenyoni"
- name: "Benjamin Smith"
github: "benbentwo"
10 changes: 10 additions & 0 deletions examples/team_routing_rule/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,15 @@ module "team_routing_rule" {
id = module.escalation.escalation_id
}
]

time_restriction = {
type = "time-of-day"
restriction = {
end_hour = 17
end_min = 0
start_hour = 9
start_min = 0
}
}
}
}
33 changes: 32 additions & 1 deletion modules/team_routing_rule/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module "team_routing_rule" {
id = module.escalation.escalation_id
}]
}

}
```

Expand All @@ -43,3 +42,35 @@ module "team_routing_rule" {
|:----------------------------|:--------------------------------------------|
| `team_routing_rule_name` | The name of the Opsgenie Team Routing Rule.|
| `team_routing_rule_id` | The ID of the Opsgenie Team Routing Rule. |

## Important Note

Due to the Opsgenie terraform provider issue, there is a difference in the configuration of the `time_restriction` blocks based on `type`.

[Github Issue #282](https://github.com/opsgenie/terraform-provider-opsgenie/issues/282)

```hcl
time_restriction {
type = "time-of-day"
restriction {
end_hour = 17
end_min = 0
start_hour = 9
start_min = 0
}
}
```
vs
```hcl
time_restriction {
type = "weekday-and-time-of-day"
restriction {
end_day = "friday"
end_hour = 17
end_min = 0
start_day = "monday"
start_hour = 9
start_min = 0
}
}
```
42 changes: 37 additions & 5 deletions modules/team_routing_rule/main.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,48 @@
resource "opsgenie_team_routing_rule" "this" {
count = module.this.enabled ? 1 : 0

name = var.team_routing_rule.name
team_id = var.team_routing_rule.team_id
order = try(var.team_routing_rule.order, 0)
name = var.team_routing_rule.name
team_id = var.team_routing_rule.team_id
order = try(var.team_routing_rule.order, 5)

timezone = try(var.team_routing_rule.timezone, "America/Los_Angeles")
dynamic "time_restriction" {
for_each = [for time_restriction in try([var.team_routing_rule.time_restriction], []) : time_restriction if time_restriction != null]

content {
# NOTE: The Opsgenie terraform provider appears to be inconsistent with how it uses time_restriction:
# `restrictions` for type `weekday-and-time-of-day`
# `restriction` for type `time-of-day`
type = var.team_routing_rule.time_restriction.type
dynamic "restrictions" {
for_each = var.team_routing_rule.time_restriction.type == "weekday-and-time-of-day" ? try(var.team_routing_rule.time_restriction.restrictions, []) : []
content {
start_hour = restrictions.value.start_hour
start_min = restrictions.value.start_min
start_day = restrictions.value.start_day
end_hour = restrictions.value.end_hour
end_min = restrictions.value.end_min
end_day = restrictions.value.end_day
}
}

dynamic "restriction" {
for_each = var.team_routing_rule.time_restriction.type == "time-of-day" ? try(var.team_routing_rule.time_restriction.restrictions, []) : []
aknysh marked this conversation as resolved.
Show resolved Hide resolved
content {
start_hour = restriction.value.start_hour
start_min = restriction.value.start_min
end_hour = restriction.value.end_hour
end_min = restriction.value.end_min
}
}
}
}

criteria {
type = try(var.team_routing_rule.criteria.type, "match-all")
type = try(var.team_routing_rule.criteria.type != null ? var.team_routing_rule.criteria.type : "match-all", "match-all")

dynamic "conditions" {
for_each = try(var.team_routing_rule.criteria.conditions, [])
for_each = try(var.team_routing_rule.criteria.conditions != null ? var.team_routing_rule.criteria.conditions : [], [])

content {
expected_value = try(conditions.value.expected_value, null)
Expand Down
2 changes: 1 addition & 1 deletion modules/team_routing_rule/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
opsgenie = {
source = "opsgenie/opsgenie"
version = ">= 0.4"
version = ">= 0.6.7"
}
}
}