Skip to content

Commit

Permalink
Feat/adding opsgenie (#10)
Browse files Browse the repository at this point in the history
* feat: adding opsgenie
---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
venkatamutyala and github-actions[bot] authored Mar 20, 2023
1 parent ddea46f commit b49aa19
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This terraform module creates a "parent" zone and multiple subdomain zones under
|------|--------|---------|
| <a name="module_common_s3"></a> [common\_s3](#module\_common\_s3) | ./modules/multy-s3-bucket/0.1.0 | n/a |
| <a name="module_loki_s3"></a> [loki\_s3](#module\_loki\_s3) | ./modules/multy-s3-bucket/0.1.0 | n/a |
| <a name="module_opsgenie_teams"></a> [opsgenie\_teams](#module\_opsgenie\_teams) | ./modules/opsgenie/0.1.0 | n/a |

## Resources

Expand Down Expand Up @@ -64,6 +65,7 @@ This terraform module creates a "parent" zone and multiple subdomain zones under
| <a name="input_company_account_id"></a> [company\_account\_id](#input\_company\_account\_id) | The company AWS account id | `string` | n/a | yes |
| <a name="input_company_key"></a> [company\_key](#input\_company\_key) | The company key | `string` | n/a | yes |
| <a name="input_domain_to_delegate_from"></a> [domain\_to\_delegate\_from](#input\_domain\_to\_delegate\_from) | The domain name of the domain that all delegation is coming from | `string` | n/a | yes |
| <a name="input_opsgenie_emails"></a> [opsgenie\_emails](#input\_opsgenie\_emails) | List of user email addresses | `list(string)` | n/a | yes |
| <a name="input_primary_region"></a> [primary\_region](#input\_primary\_region) | The primary S3 region to create S3 bucket in used for backups. This should be the same region as the one where the cluster is being deployed. | `string` | n/a | yes |
| <a name="input_this_is_development"></a> [this\_is\_development](#input\_this\_is\_development) | The development cluster environment and data/resources can be destroyed! | `string` | `false` | no |

Expand Down
91 changes: 91 additions & 0 deletions modules/opsgenie/0.1.0/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
locals {
users_set = toset(var.users)
cluster_environments_set = toset(var.cluster_environments)
time_zone = "Africa/Monrovia"
}

data "opsgenie_user" "users" {
for_each = local.users_set
username = each.key
}

resource "opsgenie_team" "teams" {
for_each = local.cluster_environments_set

name = "${var.company_key}-${each.value}-team"
description = "This is for company ${var.company_key} in the ${each.value} environment"
delete_default_resources = true

dynamic "member" {
for_each = data.opsgenie_user.users

content {
id = member.value.id
role = "user"
}
}
}

resource "opsgenie_team_routing_rule" "routing_rules" {
for_each = local.cluster_environments_set

name = "${var.company_key}-${each.value}-routing-rule"
team_id = opsgenie_team.teams[each.key].id
order = 0
timezone = local.time_zone
criteria {
type = "match-all"
}
notify {
name = opsgenie_schedule.schedules[each.key].name
type = "schedule"
}

}

resource "opsgenie_schedule" "schedules" {
for_each = local.cluster_environments_set

name = "${var.company_key}-${each.value}-schedule"
description = "This is for company ${var.company_key} in the ${each.value} environment"
timezone = local.time_zone
owner_team_id = opsgenie_team.teams[each.key].id
enabled = true
}

resource "opsgenie_schedule_rotation" "rotations" {
for_each = local.cluster_environments_set

schedule_id = opsgenie_schedule.schedules[each.key].id
name = "${var.company_key}-${each.value}-rotation"

dynamic "participant" {
for_each = data.opsgenie_user.users

content {
type = "user"
id = participant.value.id
}
}

start_date = "2023-03-14T09:00:00Z" # Set the start date and time for the rotation
type = "weekly"
length = 1
}

resource "opsgenie_api_integration" "prometheus" {
for_each = local.cluster_environments_set
name = "${var.company_key}-${each.value}-prometheus-api-int"
type = "API"

responders {
type = "team"
id = opsgenie_team.teams[each.key].id
}

enabled = true
allow_write_access = true
ignore_responders_from_payload = true
suppress_notifications = false
owner_team_id = opsgenie_team.teams[each.key].id
}
8 changes: 8 additions & 0 deletions modules/opsgenie/0.1.0/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
opsgenie = {
source = "opsgenie/opsgenie"
version = "0.6.20"
}
}
}
14 changes: 14 additions & 0 deletions modules/opsgenie/0.1.0/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
variable "users" {
description = "List of user email addresses"
type = list(string)
}

variable "company_key" {
description = "Unique identifier for the company"
type = string
}

variable "cluster_environments" {
description = "List of cluster environment names"
type = list(string)
}
6 changes: 6 additions & 0 deletions opsgenie.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module "opsgenie_teams" {
source = "./modules/opsgenie/0.1.0"
users = var.opsgenie_emails
company_key = var.company_key
cluster_environments = var.cluster_environments
}
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ locals {
ns_record_type = "NS"
bucket_name = "glueops-tenant-${local.company_key}"
}

variable "opsgenie_emails" {
description = "List of user email addresses"
type = list(string)
}

0 comments on commit b49aa19

Please sign in to comment.