Skip to content

Commit

Permalink
Use data objects as fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
diraol committed Jul 25, 2024
1 parent 141680f commit eb7251e
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions modules/config/alert_policies.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ resource "opsgenie_alert_policy" "this" {
alert_description = try(each.value.alert_description, each.value.name)

# Look up our team id by name
team_id = try(opsgenie_team.this[each.value.owner_team_name].id, null)
team_id = try(opsgenie_team.this[each.value.owner_team_name].id, data.opsgenie_team.this[each.value.owner_team_name].id, null)

enabled = try(each.value.enabled, true)
continue_policy = try(each.value.continue, true)
Expand All @@ -32,7 +32,7 @@ resource "opsgenie_alert_policy" "this" {
type = responders.value.type

id = lookup(responders.value, "id", null) != null ? responders.value.id : (
responders.value.type == "team" ? opsgenie_team.this[responders.value.team_name].id : (
responders.value.type == "team" ? try(opsgenie_team.this[responders.value.team_name].id, data.opsgenie_team.this[responders.value.team_name].id) : (
responders.value.type == "user" ? try(opsgenie_user.this[responders.value.user_name].id, data.opsgenie_user.this[responders.value.user_name].id) : (
responders.value.type == "escalation" ? opsgenie_escalation.this[responders.value.escalation_name].id : (
null
Expand Down
2 changes: 1 addition & 1 deletion modules/config/api_integrations.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ resource "opsgenie_api_integration" "this" {
webhook_url = try(each.value.webhook_url, null)

# Look up our team id by name
owner_team_id = try(opsgenie_team.this[each.value.owner_team_name].id, null)
owner_team_id = try(opsgenie_team.this[each.value.owner_team_name].id, data.opsgenie_team.this[each.value.owner_team_name].id, null)
}
3 changes: 1 addition & 2 deletions modules/config/escalations.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resource "opsgenie_escalation" "this" {
description = try(each.value.description, each.value.name)

# Look up our team id by name
owner_team_id = try(opsgenie_team.this[each.value.owner_team_name].id, null)
owner_team_id = try(opsgenie_team.this[each.value.owner_team_name].id, data.opsgenie_team.this[each.value.owner_team_name].id, null)

dynamic "rules" {
for_each = each.value.rules
Expand All @@ -17,7 +17,6 @@ resource "opsgenie_escalation" "this" {

recipient {
type = rules.value.recipient.type

id = try(rules.value.recipient.id, null) != null ? rules.value.recipient.id : (
rules.value.recipient.type == "team" ? try(opsgenie_team.this[rules.value.recipient.team_name].id, data.opsgenie_team.this[rules.value.recipient.team_name].id) : (
rules.value.recipient.type == "user" ? try(opsgenie_user.this[rules.value.recipient.user_name].id, data.opsgenie_user.this[rules.value.recipient.user_name].id) : (
Expand Down
2 changes: 1 addition & 1 deletion modules/config/notification_policies.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resource "opsgenie_notification_policy" "this" {
name = each.key

# Look up our team id by name
team_id = opsgenie_team.this[each.value.team_name].id
team_id = try(opsgenie_team.this[each.value.team_name].id, data.opsgenie_team.this[each.value.team_name].id)
policy_description = try(each.value.description, each.value.name)

filter {
Expand Down
2 changes: 1 addition & 1 deletion modules/config/schedule_rotations.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ resource "opsgenie_schedule_rotation" "this" {
length = try(each.value.length, null)

# Look up our schedule id by name
schedule_id = try(opsgenie_schedule.this[each.value.schedule_name].id, null)
schedule_id = try(opsgenie_schedule.this[each.value.schedule_name].id, data.opsgenie_schedule.this[each.value.schedule_name].id, null)

dynamic "participant" {
for_each = try(each.value.participants, [])
Expand Down
2 changes: 1 addition & 1 deletion modules/config/schedules.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ resource "opsgenie_schedule" "this" {
timezone = try(each.value.timezone, each.value.name)

# Look up our team id by name
owner_team_id = try(opsgenie_team.this[each.value.owner_team_name].id, null)
owner_team_id = try(opsgenie_team.this[each.value.owner_team_name].id, data.opsgenie_team.this[each.value.owner_team_name].id, null)
}
2 changes: 1 addition & 1 deletion modules/config/services.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ resource "opsgenie_service" "this" {
for_each = module.this.enabled ? { for service in local.services : service.name => service } : tomap()

name = each.value.name
team_id = opsgenie_team.this[each.value.team_name].id
team_id = try(opsgenie_team.this[each.value.team_name].id, data.opsgenie_team.this[each.value.team_name].id)
description = try(each.value.description, null)
}
2 changes: 1 addition & 1 deletion modules/config/team_routing_rules.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resource "opsgenie_team_routing_rule" "this" {
is_default = try(each.value.is_default, false)

# Look up Team ID by name
team_id = opsgenie_team.this[each.value.owner_team_name].id
team_id = try(opsgenie_team.this[each.value.owner_team_name].id, data.opsgenie_team.this[each.value.owner_team_name].id)

order = try(each.value.order, 0)
timezone = try(each.value.timezone, "America/Los_Angeles")
Expand Down

0 comments on commit eb7251e

Please sign in to comment.