Skip to content

Commit

Permalink
refactor: move webtest configuration into its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
afeld committed Jun 3, 2022
1 parent 7118ffe commit 642dea6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
14 changes: 3 additions & 11 deletions terraform/uptime/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,7 @@ resource "azurerm_application_insights_web_test" "healthcheck" {
"us-ca-sjc-azr", # West US
]

# boilerplate configuration
configuration = <<XML
<WebTest Name="dev-healthcheck" Enabled="True" CssProjectStructure="" CssIteration="" Timeout="120" WorkItemIds=""
xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" Description="" CredentialUserName="" CredentialPassword="" PreAuthenticate="True" Proxy="default" StopOnError="False" RecordedResultFile="" ResultsLocale="">
<Items>
<Request Method="GET" Version="1.1" Url="${var.url}" ThinkTime="0" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="200" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False" />
</Items>
</WebTest>
XML
configuration = templatefile("${path.module}/webtest.xml", { url = var.url })

lifecycle {
ignore_changes = [tags]
Expand All @@ -46,8 +38,8 @@ resource "azurerm_monitor_metric_alert" "uptime" {
severity = var.severity

application_insights_web_test_location_availability_criteria {
web_test_id = azurerm_application_insights_web_test.healthcheck.id
component_id = data.azurerm_application_insights.benefits.id
web_test_id = azurerm_application_insights_web_test.healthcheck.id
component_id = data.azurerm_application_insights.benefits.id
# "the optimal configuration is to have the number of test locations be equal to the alert location threshold + 2"
# https://docs.microsoft.com/en-us/azure/azure-monitor/app/monitor-web-app-availability#create-a-test
failed_location_count = length(azurerm_application_insights_web_test.healthcheck.geo_locations) - 2
Expand Down
6 changes: 3 additions & 3 deletions terraform/uptime/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ variable "action_group_id" {
}

variable "name" {
type = string
type = string
description = "What to call the ping test"
}

Expand All @@ -12,8 +12,8 @@ variable "resource_group_name" {
}

variable "severity" {
type = number
default = 1
type = number
default = 1
description = "https://docs.microsoft.com/en-us/azure/azure-monitor/best-practices-alerts#alert-severity"
}

Expand Down
7 changes: 7 additions & 0 deletions terraform/uptime/webtest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- boilerplate configuration -->
<WebTest Name="dev-healthcheck" Enabled="True" CssProjectStructure="" CssIteration="" Timeout="120" WorkItemIds=""
xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" Description="" CredentialUserName="" CredentialPassword="" PreAuthenticate="True" Proxy="default" StopOnError="False" RecordedResultFile="" ResultsLocale="">
<Items>
<Request Method="GET" Version="1.1" Url="${url}" ThinkTime="0" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="200" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False" />
</Items>
</WebTest>

0 comments on commit 642dea6

Please sign in to comment.