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

Arm TTK : URIs Should Be Properly Constructed #777

Open
ashwinvenkatesha opened this issue Apr 25, 2024 · 1 comment
Open

Arm TTK : URIs Should Be Properly Constructed #777

ashwinvenkatesha opened this issue Apr 25, 2024 · 1 comment

Comments

@ashwinvenkatesha
Copy link

Here, is the variable in use
`"variables" : {

"LogAnaltyicsUri":"[replace(environment().portal, 'https://portal', concat('https://', toLower(parameters('WorkspaceId')), '.ods.opinsights'))]"
}`

While running arm-ttk tests locally, I noticed an error
[-] URIs Should Be Properly Constructed (17 ms) Function 'concat' found within 'LogAnaltyicsUri' Line: 95, Column: 6 Function 'concat' found within 'LogAnaltyicsUri' Line: 101, Column: 6

But looking into the branch, lots of other users have contributed with the above format itself, I dont know why this fails.
I tried using a different approach,
"LogAnaltyicsUri": "[format('https://%s.ods.opinsights.azure.com', parameters('AzureSentinelWorkspaceId'))]",

This too led to the following error,
Function 'format' found within 'LogAnaltyicsUri' Line: 95, Column: 6

I am creating this as an issue based on my initial question over here https://learn.microsoft.com/en-us/answers/questions/1660160/arm-ttk-validation-help?comment=question#newest-question-comment

@jimdigriz
Copy link

@ashwinvenkatesha, the problem is manual construction of variables that have 'url' or 'uri' contained in the name must have been formed used uri() which would not work for your use case as you create the URI yourself; one workaround for you simply remove uri from your variable name.

A real problem here that does need to be solved is the following Bicep:

resource storage 'Microsoft.Storage/storageAccounts@2022-09-01' existing = {
  name: storageName
}

resource vm 'Microsoft.Compute/virtualMachines@2024-07-01' = {
  ...
  diagnosticsProfile: {
    bootDiagnostics: {
      enabled: true
      storageUri: storage.properties.primaryEndpoints.blob
    }
  }
}

Results in the following ARM output for the virtual machine resource:

{
   ...
   "diagnosticsProfile": {
     "bootDiagnostics": {
       "enabled": true,
       "storageUri": "[reference(resourceId('Microsoft.Storage/storageAccounts', format('dev{0}', uniqueString(resourceGroup().id, 'dev'))), '2023-01-01').primaryEndpoints.blob]"
     }
   }
}

Though primaryEndpoints.blob is a URI, it is converted by bicep into something TTK deems unsafe. The problem is uri() is used to construction URI's with path components and so I am unable to see how to fix this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants