Properly encode URL for Webtest configuration XML with Terraform on Azure

0 votes

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
}
Apr 4 in Azure by Edureka
• 12,390 points
302 views

1 answer to this question.

0 votes
Additionally, &domain hint= The domain userdomain.com is appended to the end of the URL request, where userdomain.com is the final portion of the user's email address - e.g. user@userdomain.com > Microsoft Docs | OAuth 2.0 Authorization Code Flow
Close and try it a several times to ensure it works before logging in with your work account in Edge or Chrome.
answered Apr 4 by Edureka
• 10,880 points

Related Questions In Azure

0 votes
1 answer

Error with Azure AD Authentication in Unity for Android

Depending on the version, Unity uses UnityPlayerActivity ...READ MORE

answered Mar 24 in Azure by Edureka
• 12,390 points
223 views
0 votes
1 answer

How to retrieve View definition on Synapse (Azure SQL DW)?

To authenticate with Azure SQL Database or ...READ MORE

answered Mar 4 in Azure by Edureka
• 12,390 points
248 views
0 votes
1 answer
0 votes
1 answer

Create Azure service health alert in Terraform

Had a similar challenge when setting up ...READ MORE

answered Apr 12 in Azure by Edureka
• 10,880 points
1,344 views
0 votes
0 answers

Terraform and Azure DevOps pipelines

I am accessing the terraform module through ...READ MORE

Apr 22 in Other DevOps Questions by Kichu
• 19,040 points
279 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Test environment for microsoft graph api and Azure v2.0

Yes, the type of application you register ...READ MORE

answered Mar 2 in Azure by Edureka
• 10,880 points
142 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP