Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

breaking: notification support for microsoft-teams #57

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ The above custom role is similar to the "write" pre-existing role, but blocks ac
| <a name="input_execution_mode"></a> [execution\_mode](#input\_execution\_mode) | Which execution mode to use | `string` | `"remote"` | no |
| <a name="input_file_triggers_enabled"></a> [file\_triggers\_enabled](#input\_file\_triggers\_enabled) | Whether to filter runs based on the changed files in a VCS push | `bool` | `true` | no |
| <a name="input_global_remote_state"></a> [global\_remote\_state](#input\_global\_remote\_state) | Allow all workspaces in the organization to read the state of this workspace | `bool` | `null` | no |
| <a name="input_notification_configuration"></a> [notification\_configuration](#input\_notification\_configuration) | Notification configuration for this workspace | <pre>list(object({<br> destination_type = string<br> enabled = optional(bool, true)<br> url = string<br> triggers = optional(list(string), [<br> "run:created",<br> "run:planning",<br> "run:needs_attention",<br> "run:applying",<br> "run:completed",<br> "run:errored",<br> ])<br> }))</pre> | `[]` | no |
| <a name="input_oidc_settings"></a> [oidc\_settings](#input\_oidc\_settings) | OIDC settings to use if "auth\_method" is set to "iam\_role\_oidc" | <pre>object({<br> audience = optional(string, "aws.workload.identity")<br> provider_arn = string<br> site_address = optional(string, "app.terraform.io")<br> })</pre> | `null` | no |
| <a name="input_path"></a> [path](#input\_path) | Path in which to create the IAM role or user | `string` | `null` | no |
| <a name="input_permissions_boundary_arn"></a> [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 |
Expand All @@ -120,8 +121,6 @@ The above custom role is similar to the "write" pre-existing role, but blocks ac
| <a name="input_sensitive_env_variables"></a> [sensitive\_env\_variables](#input\_sensitive\_env\_variables) | An optional map with sensitive environment variables | `map(string)` | `{}` | no |
| <a name="input_sensitive_hcl_variables"></a> [sensitive\_hcl\_variables](#input\_sensitive\_hcl\_variables) | An optional map with sensitive HCL Terraform variables | <pre>map(object({<br> sensitive = string<br> }))</pre> | `{}` | no |
| <a name="input_sensitive_terraform_variables"></a> [sensitive\_terraform\_variables](#input\_sensitive\_terraform\_variables) | An optional map with sensitive Terraform variables | `map(string)` | `{}` | no |
| <a name="input_slack_notification_triggers"></a> [slack\_notification\_triggers](#input\_slack\_notification\_triggers) | The triggers to send to Slack | `list(string)` | <pre>[<br> "run:created",<br> "run:planning",<br> "run:needs_attention",<br> "run:applying",<br> "run:completed",<br> "run:errored"<br>]</pre> | no |
| <a name="input_slack_notification_url"></a> [slack\_notification\_url](#input\_slack\_notification\_url) | The Slack Webhook URL to send notification to | `string` | `null` | no |
| <a name="input_ssh_key_id"></a> [ssh\_key\_id](#input\_ssh\_key\_id) | The SSH key ID to assign to the workspace | `string` | `null` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | A mapping of tags to assign to resource | `map(string)` | `null` | no |
| <a name="input_team_access"></a> [team\_access](#input\_team\_access) | Map of team names and either type of fixed access or custom permissions to assign | <pre>map(object({<br> access = optional(string, null),<br> permissions = optional(object({<br> run_tasks = bool<br> runs = string<br> sentinel_mocks = string<br> state_versions = string<br> variables = string<br> workspace_locking = bool<br> }), null)<br> }))</pre> | `{}` | no |
Expand Down
11 changes: 11 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -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.
12 changes: 6 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
42 changes: 23 additions & 19 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down