Skip to content

Commit

Permalink
Add Opsgenie service, service_incident_rule and user modules an…
Browse files Browse the repository at this point in the history
…d tests. Update `team` module (#10)

* Add `Opsgenie User` module, example, and test

* Update `Opsgenie Team`

* Update `Opsgenie Team`

* Add `Opsgenie Service` module, example and test

* Add `Opsgenie Service` module, example and test

* Add `Opsgenie Service` module, example and test

* Add `Opsgenie Service` module, example and test

* Add `Opsgenie Service Incident Rule` module, example and test

* Add `Opsgenie Service Incident Rule` module, example and test

* Add `Opsgenie Service Incident Rule` module, example and test

* Add `Opsgenie Service Incident Rule` module, example and test

* Add `Opsgenie Service Incident Rule` module, example and test

* Update tests

* Update tests

* Update tests

* Update tests
  • Loading branch information
aknysh authored Oct 14, 2020
1 parent 717f041 commit 11be84f
Show file tree
Hide file tree
Showing 68 changed files with 1,506 additions and 96 deletions.
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ Available modules:
- [Notification Policy](modules/notification_policy)
- [Team](modules/team)
- [Team Routing Rule](modules/team_routing_rule)
- [User](modules/user)
- [Service](modules/service)
- [Service Incident Rule](modules/service_incident_rule)

**Note:** Root module is just an example that uses all of submodules.

Expand All @@ -91,7 +94,6 @@ module "team-name" {
name = "team-name"
description = "team-description"
}
}
```

Expand All @@ -111,6 +113,7 @@ Submodules examples:
- [`notification_policy`](examples/notification_policy)
- [`team`](examples/team)
- [`team_routing_rule`](examples/team_routing_rule)
- [`user`](examples/user)

Here is an example of using the `config` module, which incorporates all resource declarations into a single module:
- [`config`](examples/config)
Expand Down Expand Up @@ -149,25 +152,28 @@ No provider.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| additional\_tag\_map | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no |
| alert\_policy | This variable is used to configure Opsgenie Alert Policy | `map` | `{}` | no |
| api\_integration | This variable is used to configure Opsgenie API Integration | `map` | `{}` | no |
| alert\_policy | Opsgenie Alert Policy configuration | `map` | `{}` | no |
| api\_integration | Opsgenie API Integration configuration | `map` | `{}` | no |
| attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
| context | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | <pre>object({<br> enabled = bool<br> namespace = string<br> environment = string<br> stage = string<br> name = string<br> delimiter = string<br> attributes = list(string)<br> tags = map(string)<br> additional_tag_map = map(string)<br> regex_replace_chars = string<br> label_order = list(string)<br> id_length_limit = number<br> })</pre> | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_order": [],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {}<br>}</pre> | no |
| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
| enabled | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
| environment | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
| escalation | This variable is used to configure Opsgenie Escalation | `map` | `{}` | no |
| escalation | Opsgenie Escalation configuration | `map` | `{}` | no |
| id\_length\_limit | Limit `id` to this many characters.<br>Set to `0` for unlimited length.<br>Set to `null` for default, which is `0`.<br>Does not affect `id_full`. | `number` | `null` | no |
| label\_order | The naming order of the id output and Name tag.<br>Defaults to ["namespace", "environment", "stage", "name", "attributes"].<br>You can omit any of the 5 elements, but at least one must be present. | `list(string)` | `null` | no |
| name | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no |
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | `string` | `null` | no |
| notification\_policy | This variable is used to configure Opsgenie Notification Policy | `map` | `{}` | no |
| notification\_policy | Opsgenie Notification Policy configuration | `map` | `{}` | no |
| opsgenie\_provider\_api\_key | The API Key for the Opsgenie Integration. If omitted, the OPSGENIE\_API\_KEY environment variable is used | `string` | `""` | no |
| regex\_replace\_chars | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.<br>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
| service | Opsgenie Service configuration | `map` | `{}` | no |
| service\_incident\_rule | Opsgenie Service Incident Rule configuration | `map` | `{}` | no |
| stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
| tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | `map(string)` | `{}` | no |
| team | This variable is used to configure Opsgenie Team | `map` | `{}` | no |
| team\_routing\_rule | This variable is used to configure Opsgenie Team Routing Rule | `map` | `{}` | no |
| team | Opsgenie Team configuration | `map` | `{}` | no |
| team\_routing\_rule | Opsgenie Team Routing Rule configuration | `map` | `{}` | no |
| user | Opsgenie User configuration | `map` | `{}` | no |

## Outputs

Expand All @@ -186,10 +192,15 @@ No provider.
| escalation\_name | Name of the Opsgenie Escalation |
| notification\_policy\_id | The ID of the Opsgenie Notification Policy |
| notification\_policy\_name | The name of the Opsgenie Notification Policy |
| service\_id | The ID of the Opsgenie Service |
| service\_incident\_rule\_id | The ID of the Opsgenie Service Incident Rule |
| service\_name | The name of the Opsgenie Service |
| team\_id | The ID of the Opsgenie Team |
| team\_name | The name of the Opsgenie Team |
| team\_routing\_rule\_id | The ID of the Opsgenie Team Routing Rule |
| team\_routing\_rule\_name | The name of the Opsgenie Team Routing Rule |
| user\_id | The ID of the Opsgenie User |
| user\_name | The name of the Opsgenie User |

<!-- markdownlint-restore -->

Expand Down
5 changes: 4 additions & 1 deletion README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ introduction: |-
- [Notification Policy](modules/notification_policy)
- [Team](modules/team)
- [Team Routing Rule](modules/team_routing_rule)
- [User](modules/user)
- [Service](modules/service)
- [Service Incident Rule](modules/service_incident_rule)
**Note:** Root module is just an example that uses all of submodules.
Expand All @@ -81,7 +84,6 @@ usage: |-
name = "team-name"
description = "team-description"
}
}
```
Expand All @@ -98,6 +100,7 @@ examples: |-
- [`notification_policy`](examples/notification_policy)
- [`team`](examples/team)
- [`team_routing_rule`](examples/team_routing_rule)
- [`user`](examples/user)
Here is an example of using the `config` module, which incorporates all resource declarations into a single module:
- [`config`](examples/config)
Expand Down
20 changes: 14 additions & 6 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,28 @@ No provider.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| additional\_tag\_map | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no |
| alert\_policy | This variable is used to configure Opsgenie Alert Policy | `map` | `{}` | no |
| api\_integration | This variable is used to configure Opsgenie API Integration | `map` | `{}` | no |
| alert\_policy | Opsgenie Alert Policy configuration | `map` | `{}` | no |
| api\_integration | Opsgenie API Integration configuration | `map` | `{}` | no |
| attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
| context | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | <pre>object({<br> enabled = bool<br> namespace = string<br> environment = string<br> stage = string<br> name = string<br> delimiter = string<br> attributes = list(string)<br> tags = map(string)<br> additional_tag_map = map(string)<br> regex_replace_chars = string<br> label_order = list(string)<br> id_length_limit = number<br> })</pre> | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_order": [],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {}<br>}</pre> | no |
| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
| enabled | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
| environment | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
| escalation | This variable is used to configure Opsgenie Escalation | `map` | `{}` | no |
| escalation | Opsgenie Escalation configuration | `map` | `{}` | no |
| id\_length\_limit | Limit `id` to this many characters.<br>Set to `0` for unlimited length.<br>Set to `null` for default, which is `0`.<br>Does not affect `id_full`. | `number` | `null` | no |
| label\_order | The naming order of the id output and Name tag.<br>Defaults to ["namespace", "environment", "stage", "name", "attributes"].<br>You can omit any of the 5 elements, but at least one must be present. | `list(string)` | `null` | no |
| name | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no |
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | `string` | `null` | no |
| notification\_policy | This variable is used to configure Opsgenie Notification Policy | `map` | `{}` | no |
| notification\_policy | Opsgenie Notification Policy configuration | `map` | `{}` | no |
| opsgenie\_provider\_api\_key | The API Key for the Opsgenie Integration. If omitted, the OPSGENIE\_API\_KEY environment variable is used | `string` | `""` | no |
| regex\_replace\_chars | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.<br>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
| service | Opsgenie Service configuration | `map` | `{}` | no |
| service\_incident\_rule | Opsgenie Service Incident Rule configuration | `map` | `{}` | no |
| stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
| tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | `map(string)` | `{}` | no |
| team | This variable is used to configure Opsgenie Team | `map` | `{}` | no |
| team\_routing\_rule | This variable is used to configure Opsgenie Team Routing Rule | `map` | `{}` | no |
| team | Opsgenie Team configuration | `map` | `{}` | no |
| team\_routing\_rule | Opsgenie Team Routing Rule configuration | `map` | `{}` | no |
| user | Opsgenie User configuration | `map` | `{}` | no |

## Outputs

Expand All @@ -52,9 +55,14 @@ No provider.
| escalation\_name | Name of the Opsgenie Escalation |
| notification\_policy\_id | The ID of the Opsgenie Notification Policy |
| notification\_policy\_name | The name of the Opsgenie Notification Policy |
| service\_id | The ID of the Opsgenie Service |
| service\_incident\_rule\_id | The ID of the Opsgenie Service Incident Rule |
| service\_name | The name of the Opsgenie Service |
| team\_id | The ID of the Opsgenie Team |
| team\_name | The name of the Opsgenie Team |
| team\_routing\_rule\_id | The ID of the Opsgenie Team Routing Rule |
| team\_routing\_rule\_name | The name of the Opsgenie Team Routing Rule |
| user\_id | The ID of the Opsgenie User |
| user\_name | The name of the Opsgenie User |

<!-- markdownlint-restore -->
1 change: 1 addition & 0 deletions examples/alert_policy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module "alert_policy" {
type = "match-all-conditions"
conditions = [
{
# Possible values are "message", "alias", "description", "source", "entity", "tags", "actions", "details", "extra-properties", "recipients", "teams", "priority"
field = "source"
operation = "matches"
expected_value = ".*prod.*"
Expand Down
5 changes: 0 additions & 5 deletions examples/alert_policy/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,3 @@ 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 "opsgenie_alert_policy" {
description = "This variable is used to configure opsgenie alert policy"
default = {}
}
5 changes: 0 additions & 5 deletions examples/api_integration/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,3 @@ 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 "opsgenie_integration" {
description = "This variable is used to configure opsgenie integration"
default = {}
}
1 change: 1 addition & 0 deletions examples/complete/alert_policy.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module "alert_policy" {
type = "match-all"
conditions = [
{
# Possible values are "message", "alias", "description", "source", "entity", "tags", "actions", "details", "extra-properties", "recipients", "teams", "priority"
field = "source"
operation = "matches"
expected_value = ".*stage.*"
Expand Down
83 changes: 79 additions & 4 deletions examples/complete/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,84 @@
output "escalation_id" {
description = "The ID of the Opsgenie escalation"
value = module.escalation.escalation_id
}

output "escalation_name" {
description = "The Name of the Opsgenie escalation"
description = "The name of the Opsgenie escalation"
value = module.escalation.escalation_name
}

output "escalation_id" {
description = "The ID of the Opsgenie escalation"
value = module.escalation.escalation_id
output "api_integration_id" {
description = "The ID of the Opsgenie integration"
value = module.api_integration.api_integration_id
}

output "api_integration_name" {
description = "The name of the Opsgenie integration"
value = module.api_integration.api_integration_name
}

output "alert_policy_id" {
description = "The ID of the Opsgenie policy"
value = module.alert_policy.alert_policy_id
}

output "alert_policy_name" {
description = "The name of the Opsgenie policy"
value = module.alert_policy.alert_policy_name
}

output "notification_policy_id" {
description = "The ID of the Opsgenie notification policy"
value = module.notification_policy.notification_policy_id
}

output "notification_policy_name" {
description = "The name of the Opsgenie notification policy"
value = module.notification_policy.notification_policy_name
}

output "team_routing_rule_id" {
description = "The ID of the Opsgenie team routing rule"
value = module.team_routing_rule.team_routing_rule_id
}

output "team_routing_rule_name" {
description = "The name of the Opsgenie team routing rule"
value = module.team_routing_rule.team_routing_rule_name
}

output "team_id" {
description = "The ID of the Opsgenie team"
value = module.team.team_id
}

output "team_name" {
description = "The name of the Opsgenie team"
value = module.team.team_name
}

output "user_id" {
description = "The ID of the Opsgenie user"
value = module.user.user_id
}

output "user_name" {
description = "The name of the Opsgenie user"
value = module.user.user_name
}

output "service_id" {
description = "The ID of the Opsgenie service"
value = module.service.service_id
}

output "service_name" {
description = "The name of the Opsgenie service"
value = module.service.service_name
}

output "service_incident_rule_id" {
description = "The ID of the Opsgenie service incident rule"
value = module.service_incident_rule.service_incident_rule_id
}
12 changes: 12 additions & 0 deletions examples/complete/service.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module "service" {
source = "../../modules/service"

# Services are Opsgenie Enterprise feature, disable it for now
enabled = false

service = {
name = "frontend"
description = "Frontend service"
team_id = module.team.team_id
}
}
38 changes: 38 additions & 0 deletions examples/complete/service_incident_rule.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module "service_incident_rule" {
source = "../../modules/service_incident_rule"

# Services are Opsgenie Enterprise feature, disable it for now
enabled = false

service_incident_rule = {
service_id = module.service.service_id

incident_rule = {
condition_match_type = "match-all"

conditions = [
{
# Possibke values: message, description, tags, extra-properties, recipients, teams, priority
field = "message"
operation = "matches"
expected_value = ".*stage.*"
},
{
field = "tags"
operation = "contains"
expected_value = "severity:info"
}
]

incident_properties = {
message = "This is a test message"
priority = "P3"

stakeholder_properties = {
message = "Message for stakeholders"
enable = true
}
}
}
}
}
2 changes: 1 addition & 1 deletion examples/complete/team.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module "team" {
team = {
name = module.this.id
description = "team-description"
ignore_members = var.ignore_members
ignore_members = false
}
}

Expand Down
14 changes: 14 additions & 0 deletions examples/complete/user.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module "user" {
source = "../../modules/user"

# Users can't be destroyed
enabled = false

user = {
username = "[email protected]"
full_name = "Opsgenie Test User"
role = "User"
locale = "en_US"
timezone = "America/New_York"
}
}
11 changes: 0 additions & 11 deletions examples/complete/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,3 @@ 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 "opsgenie_team" {
description = "This variable is used to configure opsgenie team"
default = {}
}

variable "ignore_members" {
type = bool
description = "Set to true to ignore any configured member blocks and any team member added/updated/removed via OpsGenie web UI"
default = false
}
Loading

0 comments on commit 11be84f

Please sign in to comment.