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, 2022 in Azure by Edureka
• 13,620 points
1,241 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, 2022 by Edureka
• 12,690 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, 2022 in Azure by Edureka
• 13,620 points
920 views
0 votes
0 answers
0 votes
0 answers

Using XML with REST API through Azure Datafactory V2

I need to use a REST API ...READ MORE

Feb 15, 2023 in Azure by Damonlang
• 1,230 points
778 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, 2022 in Azure by Edureka
• 13,620 points
1,724 views
0 votes
0 answers
0 votes
1 answer

Create Azure service health alert in Terraform

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

answered Apr 12, 2022 in Azure by Edureka
• 12,690 points
4,627 views
0 votes
1 answer

Terraform and Azure DevOps pipelines

This error message is normal. Usually, the ...READ MORE

answered Apr 23, 2022 in Other DevOps Questions by narikkadan
• 63,600 points
1,000 views
0 votes
1 answer

Can I create virtual machine without virtual network in Azure Resource Manager?

A VNet is used to provide the ...READ MORE

answered Mar 4, 2022 in Azure by Edureka
• 13,620 points
2,185 views
0 votes
1 answer

How to create a service connection for Azure in Azure Devops (with pictures)

to create a service connection for Azure ...READ MORE

answered Mar 29, 2022 in Azure by Edureka
• 12,690 points

edited Jul 4, 2023 by Khan Sarfaraz 8,910 views
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, 2022 in Azure by Edureka
• 12,690 points
754 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