Skip to content
This repository was archived by the owner on Mar 30, 2026. It is now read-only.
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# Local .terraform directories
.terraform

.terraform.lock.hcl
# .tfstate files
*.tfstate
*.tfstate.*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logic-App-Alert-To-Slack Building-Block
This logic app workflow is based on the consumption model. Using this Buildingblock, a connection resource will be created to access your slack channel.

## Requirements
- You have to authorize the access to slack via azure portal (in the slack-connection resource -> edit API -> authorize -> save)
- You have to manually copy the workflow URL from the logic app overview pane, and then paste it inside URI field of the webhook inside you action group

## How to use this Building Block in meshStack

1. Go to your meshStack admin area and click on "Building Blocks" from the left pane
2. Click on "Create Building Block"
3. Fill out the general information and click next
4. Select "Azure" as your supported platform
5. Select "Terraform" in Implementation Type and put in the Terraform version
6. Copy the repository HTTPS address to the "Git Repository URL" field (if its a private repo, add your SSH key) click next
7. For the input do the following
- add the service principal's "ARM_CLIENT_SECRET" and "ARM_CLIENT_ID" as Environmental Variable
- add the add the "subscription_id" as "Platform Tenant ID"
- add the rest of the variables as platform operator or user input
8. On the next page, add the outputs from outputs.tf file and click on Create Building Block
9. Now users can add this building block to their tenants

## Backend configuration
Here you can find an example of how to create a backend.tf file on this [Wiki Page](https://github.com/meshcloud/building-blocks/wiki/%5BUser-Guide%5D-Setting-up-the-Backend-for-terraform-state#how-to-configure-backendtf-file-for-these-providers)
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
locals {
logicapp_name = "alert-to-slack"
}
resource "azurerm_resource_group" "workflow_rg" {
name = "rg-${var.location}-workflow"
location = var.location
}

resource "azurerm_resource_group_template_deployment" "rg_worklow_deployment" {
name = local.logicapp_name
resource_group_name = azurerm_resource_group.workflow_rg.name
deployment_mode = "Incremental"
template_content = <<TEMPLATE
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"logicAppName": {
"type": "string",
"defaultValue": "${local.logicapp_name}",
"metadata": {
"description": "The name for the logic app."
}
},
"slackConnectionName": {
"type": "string",
"defaultValue": "SlackConnection",
"metadata": {
"description": "The name for the Slack connection."
}
},
"slackChannel": {
"type": "string",
"defaultValue": "${var.slackchannel}",
"metadata": {
"description": "The Slack channel to post to."
}
},
"location": {
"type": "string",
"defaultValue": "${azurerm_resource_group.workflow_rg.location}",
"metadata": {
"description": "Location for all resources."
}
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Web/connections",
"apiVersion": "2018-07-01-preview",
"location": "[parameters('location')]",
"name": "[parameters('slackConnectionName')]",
"properties": {
"api": {
"id": "[subscriptionResourceId('Microsoft.Web/locations/managedApis', parameters('location'), 'slack')]"
},
"displayName": "slack"
}
},
{
"type": "Microsoft.Logic/workflows",
"apiVersion": "2019-05-01",
"name": "[parameters('logicAppName')]",
"dependsOn": [
"[resourceId('Microsoft.Web/connections', parameters('slackConnectionName'))]"
],
"location": "[parameters('location')]",
"properties": {
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"type": "request",
"kind": "Http",
"inputs": {
"schema": {
"$schema": "http://json-schema.org/draft-04/schema#",
"properties": {
"context": {
"properties": {
"name": {
"type": "string"
},
"portalLink": {
"type": "string"
},
"resourceName": {
"type": "string"
}
},
"required": [
"name",
"portalLink",
"resourceName"
],
"type": "object"
},
"status": {
"type": "string"
}
},
"required": [
"status",
"context"
],
"type": "object"
}
}
}
},
"actions": {
"Post_Message": {
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['slack']['connectionId']"
}
},
"method": "post",
"path": "/chat.postMessage",
"queries": {
"channel": "[parameters('slackChannel')]",
"text": "Azure Alert - '@{triggerBody()['data']['essentials']['description']}' '@{triggerBody()['data']['alertContext']['AlertData']['BudgetName']}' '@{triggerBody()['data']['alertContext']['AlertData']['BudgetThreshold']}' '@{triggerBody()['data']['alertContext']['AlertData']['NotificationThresholdAmount']}' '@{triggerBody()['data']['alertContext']['AlertData']['Scope']}' "
}
}
}
},
"outputs": {}
},
"parameters": {
"$connections": {
"value": {
"slack": {
"id": "[subscriptionResourceId('Microsoft.Web/locations/managedApis', parameters('location'), 'slack')]",
"connectionId": "[resourceId('Microsoft.Web/connections', parameters('slackConnectionName'))]"
}
}
}
}
}
}
],
"outputs": {
"WebHookURI": {
"type": "string",
"value": "Use 'listCallbackURL(resourceId('Microsoft.Logic/workflows/triggers', parameter('logicAppName'), 'manual'), '2019-05-01').value' to retrieve the callback URL, the value contains a secret and is not recommended in an output."
}
}
}
TEMPLATE

// NOTE: whilst we show an inline template here, we recommend
// sourcing this from a file for readability/editor support
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "resource_group_id" {
value = azurerm_resource_group.workflow_rg.id
}

output "deployment" {
value = azurerm_resource_group_template_deployment.rg_worklow_deployment.output_content
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
terraform {
required_version = ">= 1.0"
required_providers {
azurerm = {
version = ">= 3.0, < 4.0"
}
}
}


#Configure the Azure Provider
provider "azurerm" {
features {
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

variable "slackchannel" {
type = string
default = "#dev-notifications"
}

variable "location" {
type = string
description = "Location where the resources will be deployed"
default = "germanywestcentral"
}
21 changes: 21 additions & 0 deletions azure/terraform/monitoring/action-group/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Action Group Building-Block
This is a monitorin action group building block. Can be used in several places in alerting purposes and configured to trigger different APIs or functions.
more info on: https://learn.microsoft.com/en-us/shows/azure-friday/azure-monitor-action-groups

## How to use this Building Block in meshStack

1. Go to your meshStack admin area and click on "Building Blocks" from the left pane
2. Click on "Create Building Block"
3. Fill out the general information and click next
4. Select "Azure" as your supported platform
5. Select "Terraform" in Implementation Type and put in the Terraform version
6. Copy the repository HTTPS address to the "Git Repository URL" field (if its a private repo, add your SSH key) click next
7. For the input do the following
- add the service principal's "ARM_CLIENT_SECRET" and "ARM_CLIENT_ID" as Environmental Variable
- add the add the "subscription_id" as "Platform Tenant ID"
- add the rest of the variables as platform operator or user input
8. On the next page, add the outputs from outputs.tf file and click on Create Building Block
9. Now users can add this building block to their tenants

## Backend configuration
Here you can find an example of how to create a backend.tf file on this [Wiki Page](https://github.com/meshcloud/building-blocks/wiki/%5BUser-Guide%5D-Setting-up-the-Backend-for-terraform-state#how-to-configure-backendtf-file-for-these-providers)
25 changes: 25 additions & 0 deletions azure/terraform/monitoring/action-group/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
locals {
location = var.location
action_group_name = var.action_group_name
action_group_short_name = var.action_group_short_name
}

//-----------------------------------------------
// Action Group
//-----------------------------------------------
resource "azurerm_resource_group" "rg_action_group" {
name = var.resource_group_name
location = local.location
}
resource "azurerm_monitor_action_group" "action_group" {
name = local.action_group_name
resource_group_name = azurerm_resource_group.rg_action_group.name
short_name = local.action_group_short_name


webhook_receiver {
name = var.webhook_name
service_uri = var.webhook_uri
use_common_alert_schema = true
}
}
20 changes: 20 additions & 0 deletions azure/terraform/monitoring/action-group/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
output "action_group_name" {
value = azurerm_monitor_action_group.action_group.name
}

output "action_group_id" {
value = azurerm_monitor_action_group.action_group.id
}

output "webhook_receiver" {
value = azurerm_monitor_action_group.action_group.webhook_receiver
}

output "resource_group_id" {
value = azurerm_resource_group.rg_action_group.id
}

output "resource_group_name" {
value = azurerm_resource_group.rg_action_group.name
}

15 changes: 15 additions & 0 deletions azure/terraform/monitoring/action-group/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.76.0"
}
}
}

provider "azurerm" {
features {
}
}
30 changes: 30 additions & 0 deletions azure/terraform/monitoring/action-group/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
variable "location" {
type = string
default = "germanywestcentral"
}

variable "action_group_name" {
type = string
description = "Name of the Action group"
}

variable "action_group_short_name" {
type = string
description = "Short Name of the Action group"
}

variable "resource_group_name" {
type = string
description = "name of the resource group where the action group will reside"
}

variable "webhook_name" {
type = string
description = "Name of the webhook used to receive the message in Action group"
}

variable "webhook_uri" {
type = string
description = "Url of the webhook. e.g. in case of using logic app, you can retrieve this value from overview pane of that logic app (workflow URL)"
default = "https://webhookuri.local"
}
Loading