Skip to content

Commit

Permalink
fix: Application insights web test preview migration from v2 (#22)
Browse files Browse the repository at this point in the history
* aligned with azurerm v2

* minor fix
  • Loading branch information
diegolagospagopa authored Jan 9, 2023
1 parent 98938f2 commit 4517ef3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
45 changes: 45 additions & 0 deletions application_insights_web_test_preview/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
# Application insights we test preview

This module allow to create an alert for the fqdn host

## How to use

```ts
locals {

test_urls = [
{
# management.env.cstar.pagopa.it
host = "google.com",
path = "/",
expected_http_status = 200
},
]

}

module "web_test_availability_alert_rules_for_api" {
for_each = { for v in local.test_urls : v.host => v if v != null }
source = "git::https://github.com/pagopa/terraform-azurerm-v3.git//application_insights_web_test_preview?ref=application-insights-web-test-preview-migration-v2"

subscription_id = data.azurerm_subscription.current.subscription_id
name = "${each.value.host}-test-avail"
location = azurerm_resource_group.monitor_rg.location
resource_group = azurerm_resource_group.monitor_rg.name
application_insight_name = azurerm_application_insights.application_insights.name
application_insight_id = azurerm_application_insights.application_insights.id
request_url = "https://${each.value.host}${each.value.path}"
ssl_cert_remaining_lifetime_check = 7
expected_http_status = each.value.expected_http_status

actions = [
{
action_group_id = azurerm_monitor_action_group.email.id,
},
{
action_group_id = azurerm_monitor_action_group.slack.id,
},
]
}
```

<!-- markdownlint-disable -->
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements
Expand Down
9 changes: 2 additions & 7 deletions application_insights_web_test_preview/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ locals {
})
}

data "azurerm_application_insights" "this" {
name = var.application_insight_name
resource_group_name = var.resource_group
}

resource "azurerm_template_deployment" "this" {
name = var.name
resource_group_name = var.resource_group
Expand All @@ -34,7 +29,7 @@ resource "azurerm_monitor_metric_alert" "this" {
resource_group_name = var.resource_group
severity = var.severity
scopes = [
data.azurerm_application_insights.this.id,
var.application_insight_id,
format("/subscriptions/%s/resourcegroups/%s/providers/microsoft.insights/webTests/%s-%s",
var.subscription_id,
var.resource_group,
Expand All @@ -52,7 +47,7 @@ resource "azurerm_monitor_metric_alert" "this" {
var.name,
var.application_insight_name
)
component_id = data.azurerm_application_insights.this.id
component_id = var.application_insight_id
failed_location_count = var.failed_location_count
}

Expand Down
5 changes: 5 additions & 0 deletions application_insights_web_test_preview/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ variable "application_insight_name" {
description = "Application insight instance name."
}

variable "application_insight_id" {
type = string
description = "Application insight id."
}

variable "frequency" {
type = number
description = "Interval in seconds between test runs for this WebTest."
Expand Down

0 comments on commit 4517ef3

Please sign in to comment.