Skip to content

Commit

Permalink
[Existing Resources] Add Team and Schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
diraol committed Jul 23, 2024
1 parent 0901010 commit dcd536b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
24 changes: 21 additions & 3 deletions modules/config/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## Config

Terraform module that configures a multitude of [Opsgenie resources](https://registry.terraform.io/providers/opsgenie/opsgenie/latest/docs).
Terraform module that configures a multitude of [Opsgenie resources](https://registry.terraform.io/providers/opsgenie/opsgenie/latest/docs).
Many resources have cross-resource dependencies, which may be simpler to handle within a single module in certain cases, such as using YAML configurations.

This module is designed to accept an input configuration map.
One nice way of handling this is by passing resource definitions from a YAML configuration file.
This module is designed to accept an input configuration map.
One nice way of handling this is by passing resource definitions from a YAML configuration file.

See below for details & examples.

Expand Down Expand Up @@ -148,6 +148,22 @@ users:
```


### `existing_schedules.yaml`

```yaml
existing_schedules:
- acme.default
```


### `existing_teams.yaml`

```yaml
existing_teams:
- acme
```


### `existing_users.yaml`

```yaml
Expand Down Expand Up @@ -228,6 +244,8 @@ module "opsgenie" {
| `alert_policies` | `name` and `id` of each alert policy |
| `api_integrations` | `name` and `id` of each API integration |
| `escalations` | `name` and `id` of each escalation |
| `existing_schedules` | `name` and `id` of each existing schedule |
| `existing_teams` | `name` and `id` of each existing team |
| `existing_users` | `username` and `id` of each existing user |
| `notification_policies` | `name` and `id` of each notification policy |
| `schedules` | `name` and `id` of each schedules |
Expand Down
30 changes: 30 additions & 0 deletions modules/config/existing_resources.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// local.existing users is a list of key pairs, in which all keys are "username".
// Let's remove duplicated items from the list based on the value of each item.
// Existing schedules and teams are just a plain list of their respective
// resource names.
locals {
distinct_existing_users = distinct([for user in local.existing_users : user.username])
unique_existing_users = [for u in local.distinct_existing_users : { "username" = u }]

unique_existing_schedules = distinct(local.existing_schedules)

unique_existing_teams = distinct(local.existing_teams)
}

data "opsgenie_user" "this" {
for_each = module.this.enabled ? { for user in local.unique_existing_users : user.username => user } : tomap()

username = each.value.username
}

data "opsgenie_schedule" "this" {

Check warning on line 20 in modules/config/existing_resources.tf

View workflow job for this annotation

GitHub Actions / terraform-module / CI / Lint (./modules/config)

[tflint] reported by reviewdog 🐶 data "opsgenie_schedule" "this" is declared but not used Raw Output: existing_resources.tf:20:1: warning: data "opsgenie_schedule" "this" is declared but not used ()

Check warning on line 20 in modules/config/existing_resources.tf

View workflow job for this annotation

GitHub Actions / terraform-module / CI / Lint (./modules/config)

[tflint] reported by reviewdog 🐶 data "opsgenie_schedule" "this" is declared but not used Raw Output: existing_resources.tf:20:1: warning: data "opsgenie_schedule" "this" is declared but not used ()
for_each = module.this.enabled ? toset(local.unique_existing_schedules) : toset()

name = each.key
}

data "opsgenie_team" "this" {

Check warning on line 26 in modules/config/existing_resources.tf

View workflow job for this annotation

GitHub Actions / terraform-module / CI / Lint (./modules/config)

[tflint] reported by reviewdog 🐶 data "opsgenie_team" "this" is declared but not used Raw Output: existing_resources.tf:26:1: warning: data "opsgenie_team" "this" is declared but not used ()

Check warning on line 26 in modules/config/existing_resources.tf

View workflow job for this annotation

GitHub Actions / terraform-module / CI / Lint (./modules/config)

[tflint] reported by reviewdog 🐶 data "opsgenie_team" "this" is declared but not used Raw Output: existing_resources.tf:26:1: warning: data "opsgenie_team" "this" is declared but not used ()
for_each = module.this.enabled ? toset(local.unique_existing_teams) : toset()

name = each.key
}
5 changes: 0 additions & 5 deletions modules/config/existing_users.tf

This file was deleted.

2 changes: 2 additions & 0 deletions modules/config/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ locals {
integration_actions = lookup(var.opsgenie_resources, "integration_actions", [])
notification_policies = lookup(var.opsgenie_resources, "notification_policies", [])
schedules = lookup(var.opsgenie_resources, "schedules", [])
existing_schedules = lookup(var.opsgenie_resources, "existing_schedules", [])
schedule_rotations = lookup(var.opsgenie_resources, "schedule_rotations", [])
team_routing_rules = lookup(var.opsgenie_resources, "team_routing_rules", [])
teams = lookup(var.opsgenie_resources, "teams", [])
existing_teams = lookup(var.opsgenie_resources, "existing_teams", [])
users = lookup(var.opsgenie_resources, "users", [])
existing_users = lookup(var.opsgenie_resources, "existing_users", [])
services = lookup(var.opsgenie_resources, "services", [])
Expand Down

0 comments on commit dcd536b

Please sign in to comment.