I'm trying to setup a azurerm_application_insights_web_test with Terraform. Currently having issues with the Url parameter in the configuration WebTest XML.
I'm just not figuring out how I'd have to properly encode the string. For "simple" URLs, it's no problem. But what about eg. https://a.skwar.me/example=yes? The problem is with the "=" (equal) sign in the URL.
If I set Url="https://a.skwar.me/example=yes" in the XML, terraform apply fails:
2021-12-03T08:32:47.4173868Z Error: creating/updating Application Insights Web Test: (Name "dummy3aaiwt" / Resource Group "SharedienDevopsTesting"): insights.WebTestsClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="BadRequest" Message="Specified argument was out of the range of valid values.\r\nParameter name: Web test 'dummy3aaiwt' is invalid. Ensure it is a well formed XML and that it adheres to the web test schema. Technical error: '=' is an unexpected token. The expected token is ';'. Line 23, position 33." InnerError={"diagnosticcontext":"6a6fb5be-fba9-4110-be6a-beffd2a44ef1","time":"2021-12-03T08:32:47.3359710Z"}
Note: Technical error: '=' is an unexpected token. The expected token is ';'
I tried to simply urlencode() the whole URL. Apply works, but no tests are being done. If I go Azure Portal, I see that the parameter hasn't been decoded; ie. I see https%3A%2F%2Fa.skwar.me%2Fexample%3Dyes. I also cannot save the test, as the URL is invalid (… d'oh!)
I've got this:
resource "azurerm_application_insights_web_test" "dummy3" {
name = "dummy3aaiwt"
location = local.ai_this.location
resource_group_name = local.ai_this.resource_group_name
application_insights_id = local.ai_this.id
kind = "ping"
frequency = 900
timeout = 120
enabled = true
retry_enabled = true
geo_locations = split(",", local.test_locations)
configuration = <<XML
<WebTest
Name="abcdefXML"
Id="${random_uuid.dummy.result}"
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"
Guid="${random_uuid.dummy2.result}"
Version="1.1"
Url="${urlencode("https://a.skwar.me/some-exampe?foo=bar")}"
ThinkTime="0"
Timeout="120"
ParseDependentRequests="False"
FollowRedirects="True"
RecordResult="True"
Cache="False"
ResponseTimeGoal="0"
Encoding="utf-8"
ExpectedHttpStatusCode="302"
ExpectedResponseUrl=""
ReportingName=""
IgnoreHttpStatusCode="False" />
</Items>
</WebTest>
XML
}