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

Test 'URIs Should Be Properly Constructed' limits usage of templates #417

Closed
pavelsalamon opened this issue Jun 16, 2021 · 7 comments
Closed
Labels
bug Something isn't working
Milestone

Comments

@pavelsalamon
Copy link

With newly added test URIs Should Be Properly Constructed, it's impossible to produce url as template output dynamically.

I was producing template output in this way:

"outputs": {
    "ServerUrl": {
      "type": "string",
      "value": "[concat('http://', reference(variables('publicIPAddressName')).dnsSettings.fqdn, '/somepath')]"
    }
  }

This doesn't pass through the test because of usage of concat function.

However, I can't produce the url without using concat function - trying to use uri() instead is not possible because uri() is too restrictive on its first parameter. Any attempt to use uri() function fails with errors like these:

The template language function 'uri' expects its first argument to be a uri string. The provided value is 'http://'

Here's an example of my attempt with uri:

"outputs": {
    "ServerUrl": {
      "type": "string",
      "value": "[uri(uri('http://', reference(variables('publicIPAddressName')).dnsSettings.fqdn), 'somepath')]"
    }
}

I tried putting various strings as first parameter of uri: http, http:, http:// and they all fail. It only accepts uri with some path in it, but I can only produce that using concat function.

@ghost ghost added the Needs: triage 🔍 label Jun 16, 2021
@bmoore-msft bmoore-msft added bug Something isn't working and removed Needs: triage 🔍 labels Jun 16, 2021
@bmoore-msft
Copy link
Contributor

We are also incorrectly flagging concat/format in the value - it should be disallowed at the beginning of the expression only.

@pavelsalamon - the proper format for your case would be:

"outputs": {
    "ServerUrl": {
      "type": "string",
      "value": "[uri(concat('http://', reference(variables('publicIPAddressName')).dnsSettings.fqdn), 'somepath')]"
    }
}

But the test will also flag that (you may have tried already) - so the test is to broad in it's assumptions and needs to be fixed.

@bmoore-msft
Copy link
Contributor

I've commented out the test for now...

@StartAutomating
Copy link
Collaborator

👍 let's see how we can improve this.

@bmoore-msft bmoore-msft added this to the M5 milestone Sep 10, 2021
StartAutomating pushed a commit to StartAutomating/arm-ttk that referenced this issue Jan 13, 2022
bmoore-msft added a commit that referenced this issue Jan 14, 2022
* Fixing #417:  Re-adding URI format test and ensuring that functions are allowed within a uri

* Fixing unknown api version in deployments (false negative)

* Delete URI-Using-Concat.json

Co-authored-by: James Brundage <@github.com>
Co-authored-by: Brian Moore <bmoore@microsoft.com>
@bmoore-msft
Copy link
Contributor

#564

@grube
Copy link

grube commented Jan 28, 2022

A few days ago our ARM template validation tests started failing with this error:
arm fail 1

We are creating a dynamic URL like this:
"myURL": "[concat('https://mydownloaddeployment=', guid(deployment().name))]",
could it be related to this change?

@bmoore-msft
Copy link
Contributor

Likely as the test was re-enabled... the test is checking for the uri function and flagging other functions for creating URLs/URIs... So flagging:

"myURL": "[concat('https://mydownloaddeployment=', guid(deployment().name))]",

would be intentional.

The fix would be to use the uri() function.

@grube
Copy link

grube commented Jan 31, 2022

Yes, using of Concat() inside of URI() function works, and passes validation.
Just needed to tweak a bit my Uri and split it in base and relative parts, something like this:

"myURL": "[uri('https://',concat('mydownloaddeployment=', guid(deployment().name)))]"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants