From f154af856dd905c13aa781b533cf1a09dd356b0f Mon Sep 17 00:00:00 2001 From: Thulasiraj Komminar <39799163+thulasirajkomminar@users.noreply.github.com> Date: Fri, 10 Nov 2023 14:37:48 +0100 Subject: [PATCH 1/2] breaking: notification support for `microsoft-teams` This allows to easily configure notifications for both slack and teams. --- UPGRADING.md | 11 +++++++++++ main.tf | 12 ++++++------ variables.tf | 42 +++++++++++++++++++++++------------------- 3 files changed, 40 insertions(+), 25 deletions(-) create mode 100644 UPGRADING.md diff --git a/UPGRADING.md b/UPGRADING.md new file mode 100644 index 0000000..861aa96 --- /dev/null +++ b/UPGRADING.md @@ -0,0 +1,11 @@ +This document captures breaking changes. + +## Upgrading to v1.0.0 + +### Variables + +The following variables have been merged: + +- `slack_notification_triggers` & `slack_notification_url` -> `notification_configuration` + +This allows to easily configure notifications for both slack and teams. diff --git a/main.tf b/main.tf index 6e355c3..f6cf11f 100644 --- a/main.tf +++ b/main.tf @@ -37,13 +37,13 @@ resource "tfe_workspace" "default" { } resource "tfe_notification_configuration" "default" { - count = var.slack_notification_url != null ? 1 : 0 + for_each = length(var.notification_configuration) != 0 ? { for v in var.notification_configuration : v.url => v } : {} - name = tfe_workspace.default.name - destination_type = "slack" - enabled = length(coalesce(var.slack_notification_triggers, [])) > 0 - triggers = var.slack_notification_triggers - url = var.slack_notification_url + name = "${tfe_workspace.default.name}-${each.value.destination_type}" + destination_type = each.value.destination_type + enabled = each.value.enabled + triggers = each.value.triggers + url = each.value.url workspace_id = tfe_workspace.default.id } diff --git a/variables.tf b/variables.tf index e80d945..5ff8c1b 100644 --- a/variables.tf +++ b/variables.tf @@ -80,6 +80,29 @@ variable "global_remote_state" { description = "Allow all workspaces in the organization to read the state of this workspace" } +variable "notification_configuration" { + type = list(object({ + destination_type = string + enabled = optional(bool, true) + url = string + triggers = optional(list(string), [ + "run:created", + "run:planning", + "run:needs_attention", + "run:applying", + "run:completed", + "run:errored", + ]) + })) + default = [] + description = "Notification configuration for this workspace" + + validation { + condition = alltrue([for v in var.notification_configuration : contains(["slack", "microsoft-teams"], v.destination_type)]) + error_message = "Supported destination types are: slack, microsoft-teams" + } +} + variable "oauth_token_id" { type = string description = "The OAuth token ID of the VCS provider" @@ -169,25 +192,6 @@ variable "sensitive_hcl_variables" { description = "An optional map with sensitive HCL Terraform variables" } -variable "slack_notification_triggers" { - type = list(string) - default = [ - "run:created", - "run:planning", - "run:needs_attention", - "run:applying", - "run:completed", - "run:errored" - ] - description = "The triggers to send to Slack" -} - -variable "slack_notification_url" { - type = string - default = null - description = "The Slack Webhook URL to send notification to" -} - variable "ssh_key_id" { type = string default = null From 22e6ad7d45c6e3f4ddf586acead6fbdeab9ebadd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 10 Nov 2023 13:38:30 +0000 Subject: [PATCH 2/2] docs(readme): update module usage --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 7e50bad..f48b692 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,7 @@ The above custom role is similar to the "write" pre-existing role, but blocks ac | [execution\_mode](#input\_execution\_mode) | Which execution mode to use | `string` | `"remote"` | no | | [file\_triggers\_enabled](#input\_file\_triggers\_enabled) | Whether to filter runs based on the changed files in a VCS push | `bool` | `true` | no | | [global\_remote\_state](#input\_global\_remote\_state) | Allow all workspaces in the organization to read the state of this workspace | `bool` | `null` | no | +| [notification\_configuration](#input\_notification\_configuration) | Notification configuration for this workspace |
list(object({
destination_type = string
enabled = optional(bool, true)
url = string
triggers = optional(list(string), [
"run:created",
"run:planning",
"run:needs_attention",
"run:applying",
"run:completed",
"run:errored",
])
}))
| `[]` | no | | [oidc\_settings](#input\_oidc\_settings) | OIDC settings to use if "auth\_method" is set to "iam\_role\_oidc" |
object({
audience = optional(string, "aws.workload.identity")
provider_arn = string
site_address = optional(string, "app.terraform.io")
})
| `null` | no | | [path](#input\_path) | Path in which to create the IAM role or user | `string` | `null` | no | | [permissions\_boundary\_arn](#input\_permissions\_boundary\_arn) | ARN of the policy that is used to set the permissions boundary for the IAM role or IAM user | `string` | `null` | no | @@ -120,8 +121,6 @@ The above custom role is similar to the "write" pre-existing role, but blocks ac | [sensitive\_env\_variables](#input\_sensitive\_env\_variables) | An optional map with sensitive environment variables | `map(string)` | `{}` | no | | [sensitive\_hcl\_variables](#input\_sensitive\_hcl\_variables) | An optional map with sensitive HCL Terraform variables |
map(object({
sensitive = string
}))
| `{}` | no | | [sensitive\_terraform\_variables](#input\_sensitive\_terraform\_variables) | An optional map with sensitive Terraform variables | `map(string)` | `{}` | no | -| [slack\_notification\_triggers](#input\_slack\_notification\_triggers) | The triggers to send to Slack | `list(string)` |
[
"run:created",
"run:planning",
"run:needs_attention",
"run:applying",
"run:completed",
"run:errored"
]
| no | -| [slack\_notification\_url](#input\_slack\_notification\_url) | The Slack Webhook URL to send notification to | `string` | `null` | no | | [ssh\_key\_id](#input\_ssh\_key\_id) | The SSH key ID to assign to the workspace | `string` | `null` | no | | [tags](#input\_tags) | A mapping of tags to assign to resource | `map(string)` | `null` | no | | [team\_access](#input\_team\_access) | Map of team names and either type of fixed access or custom permissions to assign |
map(object({
access = optional(string, null),
permissions = optional(object({
run_tasks = bool
runs = string
sentinel_mocks = string
state_versions = string
variables = string
workspace_locking = bool
}), null)
}))
| `{}` | no |