Skip to content

Commit

Permalink
Feat: Add Support for Integration Actions (#20)
Browse files Browse the repository at this point in the history
* Add support for the opsgenie_integration_action resource in both its own submodule and the config submodule.
* update context.tf in example configs
  • Loading branch information
korenyoni authored Jun 7, 2021
1 parent cf423eb commit 8c47287
Show file tree
Hide file tree
Showing 42 changed files with 1,672 additions and 146 deletions.
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Available modules:
- [API Integration](modules/api_integration)
- [Config](modules/config)
- [Escalation](modules/escalation)
- [Integration Action](modules/integration_action) (advanced feature — not available to all OpsGenie plans)
- [Notification Policy](modules/notification_policy)
- [Team](modules/team)
- [Team Routing Rule](modules/team_routing_rule)
Expand All @@ -78,6 +79,8 @@ Available modules:

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

**Note:** See the [Advanced Features Example](examples/advanced_features) for features only available to some OpsGenie plans.


## Security & Compliance [<img src="https://cloudposse.com/wp-content/uploads/2020/11/bridgecrew.svg" width="250" align="right" />](https://bridgecrew.io/)

Expand Down Expand Up @@ -140,6 +143,7 @@ Submodules examples:
- [`alert_policy`](examples/alert_policy)
- [`api_integration`](examples/api_integration)
- [`escalation`](examples/escalation)
- [`integration_action`](examples/integration_action) (advanced feature — not available to all OpsGenie plans)
- [`notification_policy`](examples/notification_policy)
- [`team`](examples/team)
- [`team_routing_rule`](examples/team_routing_rule)
Expand Down Expand Up @@ -181,16 +185,17 @@ No providers.

| Name | Source | Version |
|------|--------|---------|
| <a name="module_alert_policy"></a> [alert\_policy](#module\_alert\_policy) | ./modules/alert_policy | |
| <a name="module_api_integration"></a> [api\_integration](#module\_api\_integration) | ./modules/api_integration | |
| <a name="module_escalation"></a> [escalation](#module\_escalation) | ./modules/escalation | |
| <a name="module_notification_policy"></a> [notification\_policy](#module\_notification\_policy) | ./modules/notification_policy | |
| <a name="module_service"></a> [service](#module\_service) | ./modules/service | |
| <a name="module_service_incident_rule"></a> [service\_incident\_rule](#module\_service\_incident\_rule) | ./modules/service_incident_rule | |
| <a name="module_team"></a> [team](#module\_team) | ./modules/team | |
| <a name="module_team_routing_rule"></a> [team\_routing\_rule](#module\_team\_routing\_rule) | ./modules/team_routing_rule | |
| <a name="module_alert_policy"></a> [alert\_policy](#module\_alert\_policy) | ./modules/alert_policy | n/a |
| <a name="module_api_integration"></a> [api\_integration](#module\_api\_integration) | ./modules/api_integration | n/a |
| <a name="module_escalation"></a> [escalation](#module\_escalation) | ./modules/escalation | n/a |
| <a name="module_integration_action"></a> [integration\_action](#module\_integration\_action) | ./modules/integration_action | n/a |
| <a name="module_notification_policy"></a> [notification\_policy](#module\_notification\_policy) | ./modules/notification_policy | n/a |
| <a name="module_service"></a> [service](#module\_service) | ./modules/service | n/a |
| <a name="module_service_incident_rule"></a> [service\_incident\_rule](#module\_service\_incident\_rule) | ./modules/service_incident_rule | n/a |
| <a name="module_team"></a> [team](#module\_team) | ./modules/team | n/a |
| <a name="module_team_routing_rule"></a> [team\_routing\_rule](#module\_team\_routing\_rule) | ./modules/team_routing_rule | n/a |
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.24.1 |
| <a name="module_user"></a> [user](#module\_user) | ./modules/user | |
| <a name="module_user"></a> [user](#module\_user) | ./modules/user | n/a |

## Resources

Expand All @@ -210,6 +215,7 @@ No resources.
| <a name="input_environment"></a> [environment](#input\_environment) | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
| <a name="input_escalation"></a> [escalation](#input\_escalation) | Opsgenie Escalation configuration | `map` | `{}` | no |
| <a name="input_id_length_limit"></a> [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).<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 |
| <a name="input_integration_action"></a> [integration\_action](#input\_integration\_action) | Opsgenie Integration Action configuration | `map` | `{}` | no |
| <a name="input_label_key_case"></a> [label\_key\_case](#input\_label\_key\_case) | The letter case of label keys (`tag` names) (i.e. `name`, `namespace`, `environment`, `stage`, `attributes`) to use in `tags`.<br>Possible values: `lower`, `title`, `upper`.<br>Default value: `title`. | `string` | `null` | no |
| <a name="input_label_order"></a> [label\_order](#input\_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 |
| <a name="input_label_value_case"></a> [label\_value\_case](#input\_label\_value\_case) | The letter case of output label values (also used in `tags` and `id`).<br>Possible values: `lower`, `title`, `upper` and `none` (no transformation).<br>Default value: `lower`. | `string` | `null` | no |
Expand Down Expand Up @@ -241,6 +247,7 @@ No resources.
| <a name="output_api_integration_name"></a> [api\_integration\_name](#output\_api\_integration\_name) | The name of the Opsgenie API Integration |
| <a name="output_escalation_id"></a> [escalation\_id](#output\_escalation\_id) | The ID of the Opsgenie Escalation |
| <a name="output_escalation_name"></a> [escalation\_name](#output\_escalation\_name) | Name of the Opsgenie Escalation |
| <a name="output_integration_action_id"></a> [integration\_action\_id](#output\_integration\_action\_id) | The ID of the Opsgenie Integration Action |
| <a name="output_notification_policy_id"></a> [notification\_policy\_id](#output\_notification\_policy\_id) | The ID of the Opsgenie Notification Policy |
| <a name="output_notification_policy_name"></a> [notification\_policy\_name](#output\_notification\_policy\_name) | The name of the Opsgenie Notification Policy |
| <a name="output_service_id"></a> [service\_id](#output\_service\_id) | The ID of the Opsgenie Service |
Expand Down
4 changes: 4 additions & 0 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ introduction: |-
- [API Integration](modules/api_integration)
- [Config](modules/config)
- [Escalation](modules/escalation)
- [Integration Action](modules/integration_action) (advanced feature — not available to all OpsGenie plans)
- [Notification Policy](modules/notification_policy)
- [Team](modules/team)
- [Team Routing Rule](modules/team_routing_rule)
Expand All @@ -73,6 +74,8 @@ introduction: |-
**Note:** Root module is just an example that uses all of submodules.
**Note:** See the [Advanced Features Example](examples/advanced_features) for features only available to some OpsGenie plans.
usage: |-
Here's how to invoke `team` module in your projects
Expand All @@ -99,6 +102,7 @@ examples: |-
- [`alert_policy`](examples/alert_policy)
- [`api_integration`](examples/api_integration)
- [`escalation`](examples/escalation)
- [`integration_action`](examples/integration_action) (advanced feature — not available to all OpsGenie plans)
- [`notification_policy`](examples/notification_policy)
- [`team`](examples/team)
- [`team_routing_rule`](examples/team_routing_rule)
Expand Down
21 changes: 12 additions & 9 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ No providers.

| Name | Source | Version |
|------|--------|---------|
| <a name="module_alert_policy"></a> [alert\_policy](#module\_alert\_policy) | ./modules/alert_policy | |
| <a name="module_api_integration"></a> [api\_integration](#module\_api\_integration) | ./modules/api_integration | |
| <a name="module_escalation"></a> [escalation](#module\_escalation) | ./modules/escalation | |
| <a name="module_notification_policy"></a> [notification\_policy](#module\_notification\_policy) | ./modules/notification_policy | |
| <a name="module_service"></a> [service](#module\_service) | ./modules/service | |
| <a name="module_service_incident_rule"></a> [service\_incident\_rule](#module\_service\_incident\_rule) | ./modules/service_incident_rule | |
| <a name="module_team"></a> [team](#module\_team) | ./modules/team | |
| <a name="module_team_routing_rule"></a> [team\_routing\_rule](#module\_team\_routing\_rule) | ./modules/team_routing_rule | |
| <a name="module_alert_policy"></a> [alert\_policy](#module\_alert\_policy) | ./modules/alert_policy | n/a |
| <a name="module_api_integration"></a> [api\_integration](#module\_api\_integration) | ./modules/api_integration | n/a |
| <a name="module_escalation"></a> [escalation](#module\_escalation) | ./modules/escalation | n/a |
| <a name="module_integration_action"></a> [integration\_action](#module\_integration\_action) | ./modules/integration_action | n/a |
| <a name="module_notification_policy"></a> [notification\_policy](#module\_notification\_policy) | ./modules/notification_policy | n/a |
| <a name="module_service"></a> [service](#module\_service) | ./modules/service | n/a |
| <a name="module_service_incident_rule"></a> [service\_incident\_rule](#module\_service\_incident\_rule) | ./modules/service_incident_rule | n/a |
| <a name="module_team"></a> [team](#module\_team) | ./modules/team | n/a |
| <a name="module_team_routing_rule"></a> [team\_routing\_rule](#module\_team\_routing\_rule) | ./modules/team_routing_rule | n/a |
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.24.1 |
| <a name="module_user"></a> [user](#module\_user) | ./modules/user | |
| <a name="module_user"></a> [user](#module\_user) | ./modules/user | n/a |

## Resources

Expand All @@ -43,6 +44,7 @@ No resources.
| <a name="input_environment"></a> [environment](#input\_environment) | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
| <a name="input_escalation"></a> [escalation](#input\_escalation) | Opsgenie Escalation configuration | `map` | `{}` | no |
| <a name="input_id_length_limit"></a> [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).<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 |
| <a name="input_integration_action"></a> [integration\_action](#input\_integration\_action) | Opsgenie Integration Action configuration | `map` | `{}` | no |
| <a name="input_label_key_case"></a> [label\_key\_case](#input\_label\_key\_case) | The letter case of label keys (`tag` names) (i.e. `name`, `namespace`, `environment`, `stage`, `attributes`) to use in `tags`.<br>Possible values: `lower`, `title`, `upper`.<br>Default value: `title`. | `string` | `null` | no |
| <a name="input_label_order"></a> [label\_order](#input\_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 |
| <a name="input_label_value_case"></a> [label\_value\_case](#input\_label\_value\_case) | The letter case of output label values (also used in `tags` and `id`).<br>Possible values: `lower`, `title`, `upper` and `none` (no transformation).<br>Default value: `lower`. | `string` | `null` | no |
Expand Down Expand Up @@ -74,6 +76,7 @@ No resources.
| <a name="output_api_integration_name"></a> [api\_integration\_name](#output\_api\_integration\_name) | The name of the Opsgenie API Integration |
| <a name="output_escalation_id"></a> [escalation\_id](#output\_escalation\_id) | The ID of the Opsgenie Escalation |
| <a name="output_escalation_name"></a> [escalation\_name](#output\_escalation\_name) | Name of the Opsgenie Escalation |
| <a name="output_integration_action_id"></a> [integration\_action\_id](#output\_integration\_action\_id) | The ID of the Opsgenie Integration Action |
| <a name="output_notification_policy_id"></a> [notification\_policy\_id](#output\_notification\_policy\_id) | The ID of the Opsgenie Notification Policy |
| <a name="output_notification_policy_name"></a> [notification\_policy\_name](#output\_notification\_policy\_name) | The name of the Opsgenie Notification Policy |
| <a name="output_service_id"></a> [service\_id](#output\_service\_id) | The ID of the Opsgenie Service |
Expand Down
9 changes: 9 additions & 0 deletions examples/advanced_features/api_integration.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module "api_integration" {
source = "../../modules/api_integration"

api_integration = {
name = module.this.id
type = "AmazonSns"
owner_team_id = module.team.team_id
}
}
202 changes: 202 additions & 0 deletions examples/advanced_features/context.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
#
# ONLY EDIT THIS FILE IN github.com/cloudposse/terraform-null-label
# All other instances of this file should be a copy of that one
#
#
# Copy this file from https://github.com/cloudposse/terraform-null-label/blob/master/exports/context.tf
# and then place it in your Terraform module to automatically get
# Cloud Posse's standard configuration inputs suitable for passing
# to Cloud Posse modules.
#
# Modules should access the whole context as `module.this.context`
# to get the input variables with nulls for defaults,
# for example `context = module.this.context`,
# and access individual variables as `module.this.<var>`,
# with final values filled in.
#
# For example, when using defaults, `module.this.context.delimiter`
# will be null, and `module.this.delimiter` will be `-` (hyphen).
#

module "this" {
source = "cloudposse/label/null"
version = "0.24.1" # requires Terraform >= 0.13.0

enabled = var.enabled
namespace = var.namespace
environment = var.environment
stage = var.stage
name = var.name
delimiter = var.delimiter
attributes = var.attributes
tags = var.tags
additional_tag_map = var.additional_tag_map
label_order = var.label_order
regex_replace_chars = var.regex_replace_chars
id_length_limit = var.id_length_limit
label_key_case = var.label_key_case
label_value_case = var.label_value_case

context = var.context
}

# Copy contents of cloudposse/terraform-null-label/variables.tf here

variable "context" {
type = any
default = {
enabled = true
namespace = null
environment = null
stage = null
name = null
delimiter = null
attributes = []
tags = {}
additional_tag_map = {}
regex_replace_chars = null
label_order = []
id_length_limit = null
label_key_case = null
label_value_case = null
}
description = <<-EOT
Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional_tag_map, which are merged.
EOT

validation {
condition = lookup(var.context, "label_key_case", null) == null ? true : contains(["lower", "title", "upper"], var.context["label_key_case"])
error_message = "Allowed values: `lower`, `title`, `upper`."
}

validation {
condition = lookup(var.context, "label_value_case", null) == null ? true : contains(["lower", "title", "upper", "none"], var.context["label_value_case"])
error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
}
}

variable "enabled" {
type = bool
default = null
description = "Set to false to prevent the module from creating any resources"
}

variable "namespace" {
type = string
default = null
description = "Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp'"
}

variable "environment" {
type = string
default = null
description = "Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT'"
}

variable "stage" {
type = string
default = null
description = "Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release'"
}

variable "name" {
type = string
default = null
description = "Solution name, e.g. 'app' or 'jenkins'"
}

variable "delimiter" {
type = string
default = null
description = <<-EOT
Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all.
EOT
}

variable "attributes" {
type = list(string)
default = []
description = "Additional attributes (e.g. `1`)"
}

variable "tags" {
type = map(string)
default = {}
description = "Additional tags (e.g. `map('BusinessUnit','XYZ')`"
}

variable "additional_tag_map" {
type = map(string)
default = {}
description = "Additional tags for appending to tags_as_list_of_maps. Not added to `tags`."
}

variable "label_order" {
type = list(string)
default = null
description = <<-EOT
The naming order of the id output and Name tag.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 5 elements, but at least one must be present.
EOT
}

variable "regex_replace_chars" {
type = string
default = null
description = <<-EOT
Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits.
EOT
}

variable "id_length_limit" {
type = number
default = null
description = <<-EOT
Limit `id` to this many characters (minimum 6).
Set to `0` for unlimited length.
Set to `null` for default, which is `0`.
Does not affect `id_full`.
EOT
validation {
condition = var.id_length_limit == null ? true : var.id_length_limit >= 6 || var.id_length_limit == 0
error_message = "The id_length_limit must be >= 6 if supplied (not null), or 0 for unlimited length."
}
}

variable "label_key_case" {
type = string
default = null
description = <<-EOT
The letter case of label keys (`tag` names) (i.e. `name`, `namespace`, `environment`, `stage`, `attributes`) to use in `tags`.
Possible values: `lower`, `title`, `upper`.
Default value: `title`.
EOT

validation {
condition = var.label_key_case == null ? true : contains(["lower", "title", "upper"], var.label_key_case)
error_message = "Allowed values: `lower`, `title`, `upper`."
}
}

variable "label_value_case" {
type = string
default = null
description = <<-EOT
The letter case of output label values (also used in `tags` and `id`).
Possible values: `lower`, `title`, `upper` and `none` (no transformation).
Default value: `lower`.
EOT

validation {
condition = var.label_value_case == null ? true : contains(["lower", "title", "upper", "none"], var.label_value_case)
error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
}
}
#### End of copy of cloudposse/terraform-null-label/variables.tf
4 changes: 4 additions & 0 deletions examples/advanced_features/fixtures.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
enabled = true
namespace = "eg"
name = "incident-management-workflow"
stage = "test"
26 changes: 26 additions & 0 deletions examples/advanced_features/integration_action.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module "integration_action" {
source = "../../modules/integration_action"

integration_action = {
integration_id = module.api_integration.api_integration_id
team_id = module.team.team_id

create = [
{
name = "Create Non-informational Alerts"
alias = "{{title}}"
filter = {
type = "match-all-conditions"
conditions = [
{
field = "priority"
not = true
operation = "equals"
expected_value = "P5"
}
]
}
}
]
}
}
3 changes: 3 additions & 0 deletions examples/advanced_features/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "opsgenie" {
api_key = var.opsgenie_provider_api_key
}
Loading

0 comments on commit 8c47287

Please sign in to comment.