CompositionalIT / farmer

Repeatable Azure deployments with ARM templates - made easy!
https://compositionalit.github.io/farmer
MIT License
524 stars 157 forks source link

Farmer generates incorrect ARM expression while adding existing storage account to enable diagnostic logs during VM creation #939

Closed Vishal7Sharma closed 2 years ago

Vishal7Sharma commented 2 years ago

The Farmer library has builder for Virtual machine creation, though it has support for parameter "diagnostics_support_external" which enables the boot diagnostics with existing created storage account.

let storageAccount =  LinkedResource.Unmanaged resourceId
vm {
  diagnostics_support_external storageAccount
}

But it generates the incorrect arm template. Currently it generates the arm template with following property attached to it.

"properties": {
        "diagnosticsProfile": {
          "bootDiagnostics": {
            "enabled": true,
            "storageUri": "[reference('sa0ce3c1e410a5ec454941').primaryEndpoints.blob]"
          }
        },

The above generated templates fail to create resources as Azure complains with following error

{
  "code": "InvalidTemplate",
  "message": "Deployment template validation failed: 'The template reference 'sa0ce3c1e410a5ec454941' is not valid: could not find template resource or resource copy with this name. Please see https://aka.ms/arm-template-expressions/#reference for usage details.'."
}

The correct template should look like this, as after this modification Azure is able to resolve the Storage Account resource.

"diagnosticsProfile": {
          "bootDiagnostics": {
            "enabled": true,
            "storageUri": "[reference(concat('Microsoft.Storage/storageAccounts/', 'sa0ce3c1e410a5ec454941'),'2015-06-15').primaryEndpoints.blob]"
          }
        },

Please check.

ninjarobot commented 2 years ago

@Vishal7Sharma this fix is released in 1.7.4 and available now on nuget.