bicep icon indicating copy to clipboard operation
bicep copied to clipboard

Visualiser doesn't show dependencies with existing resources

Open afscrome opened this issue 3 years ago • 2 comments

Bicep version VS Code 0.4.1

Describe the bug If you have a reference to an existing resource, the visualiser doesn't show a dependency between the resources

To Reproduce

resource galleryImageVersion 'Microsoft.Compute/galleries/images/versions@2020-09-30' existing = {
  name: 'gallery/image/version'
}

resource vmScaleSet 'Microsoft.Compute/virtualMachineScaleSets@2021-03-01' = {
  name: 'foo'
  location: resourceGroup().location
  properties: {
    virtualMachineProfile: {
      storageProfile: {
        imageReference: {
          id: galleryImageVersion.id
        }
      }
    }
  }
}

image

Additional context If you remove the existing keyword, then the visualiser does render the dependency correctly

image

afscrome avatar Jun 03 '21 20:06 afscrome

I think this may be due to the compiler not generating a dependsOn for existing resources - the above compiles to:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.4.1.14562",
      "templateHash": "10263985305782681691"
    }
  },
  "functions": [],
  "resources": [
    {
      "type": "Microsoft.Compute/virtualMachineScaleSets",
      "apiVersion": "2021-03-01",
      "name": "foo",
      "location": "[resourceGroup().location]",
      "properties": {
        "virtualMachineProfile": {
          "storageProfile": {
            "imageReference": {
              "id": "[resourceId('Microsoft.Compute/galleries/images/versions', split('gallery/image/version', '/')[0], split('gallery/image/version', '/')[1], split('gallery/image/version', '/')[2])]"
            }
          }
        }
      }
    }
  ]
}

afscrome avatar Jun 03 '21 22:06 afscrome

FWIW, there is technically no dependency here. By virtue of using the existing keyword, we assume that the resource exists and we don't need the explicit dependency. Though conceptually it makes sense to show this the same as a dependency so that it's easy to appreciate the relationship.

alex-frankel avatar Jun 09 '21 00:06 alex-frankel