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

Feature Request: Insights Webtests - Url Ping Test #1687

Closed
cdhunt opened this issue Jul 31, 2018 · 17 comments · Fixed by #3331
Closed

Feature Request: Insights Webtests - Url Ping Test #1687

cdhunt opened this issue Jul 31, 2018 · 17 comments · Fixed by #3331

Comments

@cdhunt
Copy link

cdhunt commented Jul 31, 2018

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Please add a resource for microsoft.insights/webtests.

New or Affected Resource(s)

  • azure_application_insights_webtests (new)

Potential Terraform Configuration

resource "azure_application_insights_webtests" "url-ping" {
  name = "insights-pingtest"
  location = "East US"
  resource_group_name = "RSG1"
  kind = "ping"
  frequency = 300
  timeout = 120
  enabled = true
  test_locations = ["us-tx-sn1-azr", "us-il-ch1-azr", "us-ca-sjc-azr"]
  test_configuration = {
    url = "https://fabrikam.co"
    method = "GET"
    expected_http_status_code = 200
  }
}

References

@kevinneufeld
Copy link

kevinneufeld commented Aug 25, 2018

FWIW: Here is the start of our workaround module:

resource "random_uuid" "webtest" {
    keepers = {
       id_guid = "${format("%v-webtest", var.name)}"
    }
 }

resource "random_uuid" "request" {
    keepers = {
        request_guid = "${format("%v-request", var.name)}"
    }
}

data "template_file" "webtest" {
  template = <<EOF
<WebTest Name="$${name}" Id="$${idGuid}" Enabled="$${enabled}" CssProjectStructure="" CssIteration="" Timeout="$${timeout}" WorkItemIds="" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" Description="" CredentialUserName="$${credentialUserName}" CredentialPassword="$${credentialPassword}" PreAuthenticate="True" Proxy="default" StopOnError="False" RecordedResultFile="" ResultsLocale=""><Items><Request Method="$${requestMethod}" Guid="$${requestGuid}" Version="1.1" Url="$${requestURL}" ThinkTime="0" Timeout="$${timeout}" ParseDependentRequests="False" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="$${expectedHttpStatusCode}" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False" /></Items></WebTest>
EOF

  vars {
    name = "${var.name}"
    idGuid = "${random_uuid.webtest.result}"
    enabled = "${var.enabled}"
    timeout = "${var.timeout}"
    credentialUserName = "${var.credential_username}"
    credentialPassword = "${var.credential_password}"
    requestMethod = "${var.request_method}"
    requestGuid =  "${random_uuid.request.result}"
    requestURL = "${var.request_url}"
    expectedHttpStatusCode = "${var.expected_http_status_code}"
  }
}

resource "azurerm_template_deployment" "default" {
  name                = "${format("%s-arm-webtest", var.name)}"
  resource_group_name = "${var.resource_group_name}"
  deployment_mode     = "Incremental"

  template_body = <<DEPLOY
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "name": {
            "type": "string"
        },
        "appInsightsName": {
            "type": "string"
        },
        "appInsightsLocation" : {
            "type": "string"
        },
        "testLocations" : {
            "type": "string"
        },
        "timeout":{
            "type":"string",
            "defaultValue": "120"
        },
        "frequency":{
            "type":"string",
            "defaultValue": "300"
        },
        "enabled": {
            "type":"string",
            "defaultValue": "True"
        },
        "webTest":{
            "type": "string"
        }
    },
    "variables": {
        "concatName" : "[trim( toLower( concat( parameters('name'),'-', parameters('appInsightsName') ) ) )]",
        "aiLocation" : "[trim( toLower( replace( parameters('appInsightsLocation'),' ', '') ) )]",
        "testLocations" : "[split(parameters('testLocations'),',')]",
        "enabled" : "[bool(parameters('enabled'))]",
        "hiddenLink" : "[concat('hidden-link:',resourceId('microsoft.insights/components',parameters('appInsightsName')))]",
        "copy": [
            {
                "name":"locations",
                "count":"[length(variables('testLocations'))]",
                "input":{
                    "Id":"[variables('testLocations')[copyIndex('locations')]]"
                }
            }
        ]
    },
    "resources": [
        {
            "type": "microsoft.insights/webtests",
            "name": "[variables('concatName')]",
            "apiVersion": "2015-05-01",
            "location": "[variables('aiLocation')]",
            "tags": {
                "[variables('hiddenLink')]":"Resource"
            },
            "scale": null,
            "properties": {
                "SyntheticMonitorId": "[variables('concatName')]",
                "Name": "[parameters('name')]",
                "Description": "",
                "Enabled": "[variables('enabled')]",
                "Frequency":"[int(parameters('frequency'))]",
                "Timeout": "[int(parameters('timeout'))]",
                "Kind": "ping",
                "RetryEnabled": true,
                "Locations": "[variables('locations')]",
                "Configuration": {
                    "WebTest": "[trim(parameters('webTest'))]"
                }
            },
            "dependsOn": []
        }
    ],
    "outputs": {
        "hiddenLink": {
            "type": "string",
            "value": "[variables('hiddenLink')]"
        },
        "concatName": {
            "type": "string",
            "value": "[variables('concatName')]"
        },
        "aiLocation": {
            "type": "string",
            "value": "[variables('aiLocation')]"
        },
        "webTest": {
            "type": "string",
            "value": "[parameters('webTest')]"
        },
        "tetsLocations": {
            "type": "Array",
            "value": "[variables('locations')]"
        }
    }
}
DEPLOY

  parameters {
    name                   = "${var.name}"
    appInsightsName        = "${var.app_insights_name}"
    appInsightsLocation    = "${var.app_insights_location}"
    testLocations          = "${var.test_locations}"
    timeout                = "${var.timeout}"
    frequency              = "${var.frequency}"
    enabled                = "${var.enabled}"
    webTest                = "${data.template_file.webtest.rendered}"
  }
}

The caveat is the required reference to the Application Insights resource via the hinden-link in tags

@jamie3
Copy link

jamie3 commented Jan 30, 2019

Does anyone know if this has been implemented?

@wellingk
Copy link

wellingk commented Mar 4, 2019

After this now for my company as @jamie3 says above, anyone know if its been implemented?

@tombuildsstuff
Copy link
Member

@jamie3 @wellingk this functionality isn't natively supported at this time - however you can use the azurerm_template_deployment resource as shown above in the interim as a workaround.

Taking a quick look into this it appears support is available in the Azure SDK for Go such that it'd be possible to implement this - but unfortunately we don't have a timeline for when we'd support this at this time (although, we'd be happy to assist with a community PR in the interim if someone's interested in seeing this natively supported 😄)

Thanks!

@AndyMoore
Copy link
Contributor

i've had a go at this, and other than a few minor odds and ends i still need to sort the code looks ok (but i'm no Go expert by any stretch)

Problem I'm hitting is this:

* azurerm_application_insights_webtest.url-ping: Error creating Application Insights WebTest "testtf-weu-dev" (Resource Group "appinsights-testtf-weu-dev"): insights.WebTestsClient#CreateOrUpdate: Failure preparing request: StatusCode=0 -- Original Error: autorest: No scheme detected in URL 

On the off chance has anyone seen this before? (possibly @tombuildsstuff)

@AndyMoore
Copy link
Contributor

have this working. adding tests/docs and then will raise a PR

I've left the actual test config as xml. the original request above from @cdhunt went for parameters instead - thoughts?

data "template_file" "test" {
  template = "${file("${path.module}/test.xml")}"

  vars = {
    url = "http://www.microsoft.com"
    method = "GET"
    expected_http_status_code = "200"
  }
}

resource "azurerm_application_insights_webtest" "test1" {
  #count = 0
  name                    = "test1"
  location                = "${azurerm_resource_group.appinsights.location}"
  resource_group_name     = "${azurerm_resource_group.appinsights.name}"
  application_insights_id = "${azurerm_application_insights.appinsights.id}"
  kind                    = "Ping"
  frequency               = 300
  timeout                 = 120
  enabled                 = true
  geo_locations           = ["us-tx-sn1-azr", "us-il-ch1-azr", "us-ca-sjc-azr"]
  test_configuration      = "${data.template_file.test.rendered}"
}

@nexxai
Copy link
Contributor

nexxai commented Apr 28, 2019

@AndyMoore This looks awesome, but have two questions:

  1. Where would one define the contact email addresses for a failed test?
  2. I've personally never used a template - do you have an example that you should share that would explain the correct formatting?

I'm super excited for this resource to be merged, so if there's any way I can help please let me know.

@AndyMoore
Copy link
Contributor

i'll definitely put an example into the documentation - i've used one for testing (iirc) straight off the Microsoft site, but there's some things in there I'm not a fan of (each test will need a unique guid for example, and i'm not sure that can be bodged)

If we were to go back to the design from the original post, there'd be less flexibility, but it'd be easier to use. It'd also be reasonably trivial to extend

Or we could have both maybe.. (i think)

I've never done one of these before, so looking to someone else to give pointers

In terms of alerts @nexxai I think this i a different API - https://docs.microsoft.com/en-gb/azure/templates/microsoft.insights/2016-03-01/alertrules - so might well be a separate resource for this

@cdhunt
Copy link
Author

cdhunt commented Apr 29, 2019

@AndyMoore That makes sense given the variability it test definitions.

@AndyMoore
Copy link
Contributor

fwiw @nexxai I think what you're after is https://www.terraform.io/docs/providers/azurerm/r/monitor_metric_alert.html and https://www.terraform.io/docs/providers/azurerm/r/monitor_metric_alertrule.html

will be looking to test these myself over the next few days..

@katbyte katbyte added this to the v1.29.0 milestone May 18, 2019
katbyte pushed a commit that referenced this issue May 18, 2019
@ghost
Copy link

ghost commented May 26, 2019

This has been released in version 1.29.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
	version = "~> 1.29.0"
}
# ... other configuration ...

@praneetloke
Copy link
Contributor

@AndyMoore thanks for implementing the web test resource!

For the alerts, it looks like alertRules maps to the "Alerts" configuration of a web test. I believe what you were suggesting in your comment would actually create an alert under the "Metrics" feature of App Insights and would also show up under the "Alerts" section of Azure Monitor.

Below is a snippet from this quickstart example showing how to setup alertRules for a web test using an ARM template. From what I can tell, this closely matches with the configuration done in the portal from my screenshot below. Also, I think this is what @nexxai was referring to?

https://github.com/Azure/azure-quickstart-templates/blob/76c4e50d9520c12e333f3f597280fca960af8a6c/201-dynamic-web-tests/azuredeploy.json#L76-L111

Screenshot_2019-05-27 Microsoft Azure

@nexxai
Copy link
Contributor

nexxai commented May 27, 2019

Yes, that is exactly what I was referring to, thanks @praneetloke !

@kdevesh
Copy link

kdevesh commented May 27, 2019

Hi Guys,
I have updated my azurerm provider to 1.29.0 but still I can't find azurerm_application_insights_web_tests.
I get an error when I try to reference it.My Terraform version is 0.11.14

@ccarrido
Copy link

Error
The provider provider.azurerm does not support resource type
"azurerm_application_insights_webtest".

To recreate, copy/paste the example in the Terraform documentation: https://www.terraform.io/docs/providers/azurerm/r/application_insights_webtests.html

Also fails on my own test definition with the same error.

Versions
Terraform v0.12.0

  • provider.azurerm v1.29.0

@iangore
Copy link

iangore commented Jun 3, 2019

it would appear that the module name is actually azurerm_application_insights_web_test so either the documentation needs to be changed or the module needs to be changed.

There is also an issue with the section of the documentation "output "webtest_provisioning_state" {
value = "${azurerm_application_insights_webtest.test.provisioning_state}"
}"

This does not appear to be a valid output for the module.

@ghost
Copy link

ghost commented Jun 18, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Jun 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.