Skip to content

Commit

Permalink
[Tests] Update GHA to run all tests (#76)
Browse files Browse the repository at this point in the history
* update makefile in test

* run all tests

* update tests

* cleanup test conflicts with eachother (same resources)

* update deduplication and delay action vars

* terraform fmt

* terraform fmt

* suppress toggled off for dedup

* fix some tests

* fix some tests

* skip some tests and update module.this.id

* fix value examples routing rule

* time_restriction is an array

* time_restriction is an array

* update teams to avoid conflicts

* update restrictions

* update restrictions

* fix

* turn of notiication policy, fix value for routing rule, add user for config

* all teams are dynamic

* update scheudle config

* skip config
  • Loading branch information
Benbentwo authored Jul 23, 2024
1 parent 08a701f commit 0901010
Show file tree
Hide file tree
Showing 36 changed files with 221 additions and 71 deletions.
1 change: 0 additions & 1 deletion examples/advanced_features/fixtures.tfvars
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
enabled = true
namespace = "eg"
name = "incident-management-workflow"
stage = "test"
1 change: 0 additions & 1 deletion examples/alert_policy/fixtures.tfvars
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
enabled = true
namespace = "eg"
name = "alert-policy"
stage = "test"
1 change: 0 additions & 1 deletion examples/config/fixtures.tfvars
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
enabled = true
3 changes: 2 additions & 1 deletion examples/config/resources/escalations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ escalations:
- name: acme.dev.some-service-escalation
description: "repo: https://github.com/acme/some-service;owner:David Lightman @David Lightman"
owner_team_name: acme.dev
rule:
# please note - config uses `rules` but escalation modules uses `rule`
rules:
condition: if-not-acked
notify_type: default
delay: 0
Expand Down
14 changes: 13 additions & 1 deletion examples/config/resources/notification_policies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ notification_policies:
- name: auto-close-based-on-priority
team_name: acme.dev
auto_close_action:
time_amount: 60
duration:
time_amount: 60
filter:
type: match-all-conditions
conditions:
Expand All @@ -16,6 +17,17 @@ notification_policies:
time_unit: minutes
time_amount: 5

- name: delay-action-test
team_name: acme.dev
auto_close_action:
duration:
time_amount: 60
filter:
type: match-all-conditions
conditions:
- field: priority
operation: less-than
expected_value: P3
delay_action:
delay_option: for-duration
duration:
Expand Down
6 changes: 3 additions & 3 deletions examples/config/resources/schedule_rotations.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
schedule_rotations:
- name: acme.default.rotation
schedule_name: acme.default
- name: acme.default.rotation
schedule_name: acme-default
start_date: "1970-01-01T00:00:00Z"
type: weekly
length: 1
Expand All @@ -15,4 +15,4 @@ schedule_rotations:
- start_hour: 8
start_min: 0
end_hour: 20
end_min: 0
end_min: 0
4 changes: 2 additions & 2 deletions examples/config/resources/schedules.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
schedules:
- name: acme.default
- name: acme-default
description: "Acme Infrastructure Team"
timezone: "America/Los_Angeles"
owner_team_name: acme
enabled: true
enabled: true
6 changes: 6 additions & 0 deletions examples/config/resources/users.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ users:
role: User
locale: "en_US"
timezone: "America/New_York"

- username: opsgenie-test-2@cloudposse.com
full_name: Opsgenie Test User 2
role: User
locale: "en_US"
timezone: "America/New_York"
1 change: 0 additions & 1 deletion examples/escalation/fixtures.tfvars
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
enabled = true
namespace = "eg"
name = "escalation"
stage = "test"
6 changes: 3 additions & 3 deletions examples/escalation/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module "owner_team" {
source = "../../modules/team"

team = {
name = "owner-team"
name = format("%s-%s", module.this.id, "owner-team")
description = "owner-team-description"
}

Expand All @@ -17,7 +17,7 @@ module "escalation_team" {
source = "../../modules/team"

team = {
name = "escalation-team"
name = format("%s-%s", module.this.id, "escalation-team")
description = "owner-team-description"
}

Expand All @@ -39,5 +39,5 @@ module "escalation" {
}
}

context = module.this.contexts
context = module.this.context
}
1 change: 0 additions & 1 deletion examples/integration_action/fixtures.tfvars
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
enabled = true
namespace = "eg"
name = "integration"
stage = "test"
12 changes: 12 additions & 0 deletions examples/notification_policy/fixtures.de_duplication_action.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace = "eg"
name = "notification-policy"
stage = "test"

de_duplication_action = {
de_duplication_action_type = "frequency-based"
count = 2
duration = {
time_unit = "minutes"
time_amount = 5
}
}
12 changes: 12 additions & 0 deletions examples/notification_policy/fixtures.delay_action.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace = "eg"
name = "notification-policy"
stage = "test"

delay_action = {
delay_option = "for-duration"
duration = {
time_unit = "minutes"
time_amount = 10
}
}

4 changes: 0 additions & 4 deletions examples/notification_policy/fixtures.tfvars

This file was deleted.

32 changes: 16 additions & 16 deletions examples/notification_policy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module "team" {
source = "../../modules/team"

team = {
name = "owner-team"
name = module.this.id
description = "owner-team-description"
}

Expand All @@ -22,34 +22,34 @@ module "notification_policy" {

filter = {
type = "match-all-conditions"
conditions = [{
field = "tags"
operation = "contains"
expected_value = "recommendation:auto-close"
}]
conditions = [
{
field = "tags"
operation = "contains"
expected_value = "recommendation:auto-close"
}
]
}

de_duplication_action = {
de_duplication_action_type = "frequency-based"
count = 2
de_duplication_action = var.de_duplication_action
delay_action = var.delay_action

auto_close_action = {
duration = {
time_unit = "minutes"
time_amount = 5
}
}

delay_action = {
delay_option = "for-duration"
auto_restart_action = {
duration = {
time_unit = "minutes"
time_amount = 10
time_amount = 5
}
max_repeat_count = 3
}

auto_close_action = {
time_unit = "minutes"
time_amount = 5
}
suppress = var.suppress
}

context = module.this.context
Expand Down
31 changes: 31 additions & 0 deletions examples/notification_policy/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,34 @@ variable "opsgenie_provider_api_key" {
description = "The API Key for the Opsgenie Integration. If omitted, the OPSGENIE_API_KEY environment variable is used"
default = null
}

variable "de_duplication_action" {
type = object({
de_duplication_action_type = string
count = number
duration = object({
time_unit = string
time_amount = number
})
})
description = "The de-duplication action for the notification policy"
default = null
}

variable "delay_action" {
type = object({
delay_option = string
duration = object({
time_unit = string
time_amount = number
})
})
description = "The delay action for the notification policy"
default = null
}

variable "suppress" {
type = bool
description = "The suppress flag for the notification policy"
default = null
}
1 change: 0 additions & 1 deletion examples/schedule/fixtures.tfvars
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
enabled = true
namespace = "eg"
name = "schedule"
stage = "test"
2 changes: 1 addition & 1 deletion examples/schedule/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module "owner_team" {
source = "../../modules/team"

team = {
name = "owner-team"
name = format("%s-%s", module.this.id, "owner-team")
description = "owner-team-description"
}

Expand Down
1 change: 0 additions & 1 deletion examples/team/fixtures.tfvars
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
enabled = true
namespace = "eg"
name = "team"
stage = "test"
1 change: 0 additions & 1 deletion examples/team_routing_rule/fixtures.tfvars
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
enabled = true
namespace = "eg"
name = "team-routing-rule"
stage = "test"
30 changes: 17 additions & 13 deletions examples/team_routing_rule/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module "escalation_team" {
source = "../../modules/team"

team = {
name = "escalation-team"
description = "owner-team-description"
name = module.this.id
description = "escalation-team-description"
}

context = module.this.context
Expand All @@ -21,10 +21,12 @@ module "escalation" {
owner_team_id = module.owner_team.team_id

rule = {
recipients = [{
type = "team"
id = module.escalation_team.team_id
}]
recipients = [
{
type = "team"
id = module.escalation_team.team_id
}
]
}
}

Expand All @@ -35,7 +37,7 @@ module "owner_team" {
source = "../../modules/team"

team = {
name = "owner-team"
name = format("%s-%s", module.this.id, "owner-team")
description = "owner-team-description"
}

Expand All @@ -58,12 +60,14 @@ module "team_routing_rule" {

time_restriction = {
type = "time-of-day"
restriction = {
end_hour = 17
end_min = 0
start_hour = 9
start_min = 0
}
restrictions = [
{
end_hour = 17
end_min = 0
start_hour = 9
start_min = 0
}
]
}
}

Expand Down
1 change: 0 additions & 1 deletion examples/user/fixtures.tfvars
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
enabled = true
namespace = "eg"
stage = "test"
name = "user"
2 changes: 1 addition & 1 deletion examples/user/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module "user" {
source = "../../modules/user"

user = {
username = "opsgenie-test@cloudposse.com"
username = format("opsgenie-test+%s@cloudposse.com", var.random_string)
full_name = "Opsgenie Test User"
role = "User"
locale = "en_US"
Expand Down
6 changes: 6 additions & 0 deletions examples/user/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ variable "opsgenie_provider_api_key" {
description = "The API Key for the Opsgenie Integration. If omitted, the OPSGENIE_API_KEY environment variable is used"
default = null
}

variable "random_string" {
type = string
description = "A random string to append to the resource names"
default = null
}
2 changes: 1 addition & 1 deletion modules/config/escalations.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ resource "opsgenie_escalation" "this" {
owner_team_id = try(opsgenie_team.this[each.value.owner_team_name].id, null)

dynamic "rules" {
for_each = try(each.value.rules, [])
for_each = try([each.value.rules], [])

content {
condition = try(rules.value.condition, "if-not-acked")
Expand Down
6 changes: 3 additions & 3 deletions modules/notification_policy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ resource "opsgenie_notification_policy" "this" {
}

dynamic "auto_close_action" {
for_each = try(each.value.auto_close_action, null) != null ? [each.value.auto_close_action] : []
for_each = try(var.notification_policy.auto_close_action, null) != null ? [var.notification_policy.auto_close_action] : []

content {
duration {
Expand All @@ -70,7 +70,7 @@ resource "opsgenie_notification_policy" "this" {
}

dynamic "auto_restart_action" {
for_each = try(each.value.auto_restart_action, null) != null ? [each.value.auto_restart_action] : []
for_each = try(var.notification_policy.auto_restart_action, null) != null ? [var.notification_policy.auto_restart_action] : []

content {
duration {
Expand Down Expand Up @@ -120,5 +120,5 @@ resource "opsgenie_notification_policy" "this" {
}
}

suppress = try(each.value.suppress, null)
suppress = try(var.notification_policy.suppress, null)
}
Loading

0 comments on commit 0901010

Please sign in to comment.