diff --git a/src/Bicep.Core.IntegrationTests/Emit/DependencyInferenceTests.cs b/src/Bicep.Core.IntegrationTests/Emit/DependencyInferenceTests.cs index 435bf4089be..9ff218d163a 100644 --- a/src/Bicep.Core.IntegrationTests/Emit/DependencyInferenceTests.cs +++ b/src/Bicep.Core.IntegrationTests/Emit/DependencyInferenceTests.cs @@ -240,7 +240,7 @@ public void Implicit_dependencies_on_existing_resource_identifying_properties_ar """); result.ExcludingLinterDiagnostics().Should().NotHaveAnyDiagnostics(); - result.Template.Should().HaveJsonAtPath("$.resources.newSa.dependsOn", """["existingSa"]"""); + result.Template.Should().HaveJsonAtPath("$.resources.newSa.dependsOn", """["deployedSa"]"""); result.Template.Should().HaveJsonAtPath("$.resources.existingSa.dependsOn", """["deployedSa"]"""); } @@ -279,7 +279,7 @@ public void Implicit_dependencies_on_existing_resource_collection_identifying_pr """); result.ExcludingLinterDiagnostics().Should().NotHaveAnyDiagnostics(); - result.Template.Should().HaveJsonAtPath("$.resources.newSa.dependsOn", """["[format('existingSa[{0}]', 0)]"]"""); + result.Template.Should().HaveJsonAtPath("$.resources.newSa.dependsOn", """["deployedSa"]"""); result.Template.Should().HaveJsonAtPath("$.resources.existingSa.dependsOn", """["deployedSa"]"""); } @@ -316,7 +316,7 @@ public void Existing_resource_function_calls_are_expressed_as_direct_dependencie """); result.ExcludingLinterDiagnostics().Should().NotHaveAnyDiagnostics(); - result.Template.Should().HaveJsonAtPath("$.resources.newSa.dependsOn", """["existingSa"]"""); + result.Template.Should().HaveJsonAtPath("$.resources.newSa.dependsOn", """["deployedSa"]"""); result.Template.Should().HaveJsonAtPath("$.resources.existingSa.dependsOn", """["deployedSa"]"""); } @@ -353,7 +353,7 @@ public void Existing_resource_collection_function_calls_are_expressed_as_direct_ """); result.ExcludingLinterDiagnostics().Should().NotHaveAnyDiagnostics(); - result.Template.Should().HaveJsonAtPath("$.resources.newSa.dependsOn", """["[format('existingSa[{0}]', 0)]"]"""); + result.Template.Should().HaveJsonAtPath("$.resources.newSa.dependsOn", """["deployedSa"]"""); result.Template.Should().HaveJsonAtPath("$.resources.existingSa.dependsOn", """["deployedSa"]"""); } @@ -394,7 +394,7 @@ public void Using_an_existing_resource_as_an_explicit_parent_does_not_generate_a """); result.ExcludingLinterDiagnostics().Should().NotHaveAnyDiagnostics(); - result.Template.Should().HaveJsonAtPath("$.resources.sa.dependsOn", """["subnet"]"""); + result.Template.Should().NotHaveValueAtPath("$.resources.sa.dependsOn"); } [DataTestMethod] @@ -436,7 +436,7 @@ public void Non_looped_resource_depending_on_looped_existing_resource_should_dep if (useSymbolicNameCodegen) { - result.Template.Should().HaveJsonAtPath("$.resources.vault.dependsOn", """["subnets"]"""); + result.Template.Should().HaveJsonAtPath("$.resources.vault.dependsOn", """["vnets"]"""); } else { @@ -485,7 +485,7 @@ public void Looped_resource_depending_on_looped_existing_resource_should_depend_ { result.Template.Should().HaveJsonAtPath( "$.resources.vault.dependsOn", - """["[format('subnets[{0}]', sub(range(10, 10)[copyIndex()], 10))]"]"""); + """["[format('vnets[{0}]', mod(range(0, 10)[sub(range(10, 10)[copyIndex()], 10)], 2))]"]"""); } else { @@ -538,7 +538,7 @@ public void Looped_resource_depending_on_looped_variable_should_depend_on_transi { result.Template.Should().HaveJsonAtPath( "$.resources.vault.dependsOn", - """["[format('subnets[{0}]', sub(range(20, 10)[sub(range(10, 10)[copyIndex()], 10)], 20))]"]"""); + """["[format('vnets[{0}]', mod(range(0, 10)[sub(range(20, 10)[sub(range(10, 10)[copyIndex()], 10)], 20)], 2))]"]"""); } else { @@ -587,7 +587,7 @@ public void CopyIndex_only_appears_in_compiled_expression_if_all_links_in_chain_ if (useSymbolicNameCodegen) { - result.Template.Should().HaveJsonAtPath("$.resources.vault.dependsOn", """["[format('subnets[{0}]', sub(range(10, 10)[copyIndex()], 10))]"]"""); + result.Template.Should().HaveJsonAtPath("$.resources.vault.dependsOn", """["[format('vnets[{0}]', 0)]"]"""); } else { @@ -636,7 +636,7 @@ public void CopyIndex_only_appears_in_compiled_expression_if_all_links_in_chain_ if (useSymbolicNameCodegen) { - result.Template.Should().HaveJsonAtPath("$.resources.vault.dependsOn", """["[format('subnets[{0}]', 0)]"]"""); + result.Template.Should().HaveJsonAtPath("$.resources.vault.dependsOn", """["[format('vnets[{0}]', mod(range(0, 10)[0], 2))]"]"""); } else { @@ -699,6 +699,6 @@ public void Using_an_existing_resource_as_a_scope_does_not_generate_an_explicit_ ("empty.bicep", string.Empty)); result.ExcludingLinterDiagnostics().Should().NotHaveAnyDiagnostics(); - result.Template.Should().HaveJsonAtPath("$.resources.empty.dependsOn", """["rg"]"""); + result.Template.Should().NotHaveValueAtPath("$.resources.empty.dependsOn"); } } diff --git a/src/Bicep.Core.IntegrationTests/ScenarioTests.cs b/src/Bicep.Core.IntegrationTests/ScenarioTests.cs index 2a24cd6bd89..c814652e0eb 100644 --- a/src/Bicep.Core.IntegrationTests/ScenarioTests.cs +++ b/src/Bicep.Core.IntegrationTests/ScenarioTests.cs @@ -5066,7 +5066,7 @@ public void Test_Issue10343() ")); var evaluated = TemplateEvaluator.Evaluate(result.Template).ToJToken(); - evaluated.Should().HaveValueAtPath("resources.foo3.dependsOn", new JArray("foo2")); + evaluated.Should().HaveValueAtPath("resources.foo3.dependsOn", new JArray("foo1")); } // https://github.com/Azure/bicep/issues/11292 @@ -6316,7 +6316,7 @@ public void Test_Issue13596(bool enableSymbolicNameCodegen) if (enableSymbolicNameCodegen) { - result.Template.Should().HaveJsonAtPath("$.resources.secret.dependsOn", """["sa"]"""); + result.Template.Should().HaveJsonAtPath("$.resources.secret.dependsOn", """["mod"]"""); } else { @@ -6478,7 +6478,7 @@ extension microsoftGraph } [TestMethod] - public void Test_Issue15686_repro() + public void Test_Issue15686() { var result = CompilationHelper.Compile(""" param eventSubscriptionName string @@ -6525,7 +6525,6 @@ param functionName string result.Template.Should().NotBeNull(); result.Template.Should().HaveJsonAtPath("$.resources.eventSubscription.dependsOn", """ [ - "eventGridTopic", "functionApp" ] """); diff --git a/src/Bicep.Core.Samples/Files/baselines/Modules_CRLF/main.symbolicnames.json b/src/Bicep.Core.Samples/Files/baselines/Modules_CRLF/main.symbolicnames.json index 3e017187bf6..d7d45d40a31 100644 --- a/src/Bicep.Core.Samples/Files/baselines/Modules_CRLF/main.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/baselines/Modules_CRLF/main.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "12632249060210513106" + "templateHash": "14846102413726496336" } }, "parameters": { @@ -1851,10 +1851,7 @@ } } } - }, - "dependsOn": [ - "kv" - ] + } }, "secureModule2": { "type": "Microsoft.Resources/deployments", @@ -1912,10 +1909,7 @@ } } } - }, - "dependsOn": [ - "scopedKv" - ] + } }, "secureModuleLooped": { "copy": { @@ -1977,11 +1971,7 @@ } } } - }, - "dependsOn": [ - "[format('loopedKv[{0}]', copyIndex())]", - "[format('loopedKv[{0}]', copyIndex())]" - ] + } }, "secureModuleCondition": { "type": "Microsoft.Resources/deployments", @@ -2024,10 +2014,7 @@ } } } - }, - "dependsOn": [ - "kv" - ] + } }, "withSpace": { "type": "Microsoft.Resources/deployments", diff --git a/src/Bicep.Core.Samples/Files/baselines/NestedResources_LF/main.symbolicnames.json b/src/Bicep.Core.Samples/Files/baselines/NestedResources_LF/main.symbolicnames.json index 7a5d6c9c527..afd6c4ed53b 100644 --- a/src/Bicep.Core.Samples/Files/baselines/NestedResources_LF/main.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/baselines/NestedResources_LF/main.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "9375757315581642416" + "templateHash": "15846782372928243436" } }, "parameters": { @@ -82,10 +82,7 @@ "existing": true, "type": "My.Rp/parentType/childType", "apiVersion": "2020-12-01", - "name": "[format('{0}/{1}', 'existingParent', 'existingChild')]", - "dependsOn": [ - "existingParent" - ] + "name": "[format('{0}/{1}', 'existingParent', 'existingChild')]" }, "conditionParent::conditionChild::conditionGrandchild": { "condition": "[and(and(parameters('createParent'), parameters('createChild')), parameters('createGrandchild'))]", @@ -162,4 +159,4 @@ "value": "loopChild" } } -} \ No newline at end of file +} diff --git a/src/Bicep.Core.Samples/Files/baselines/Resources_CRLF/main.symbolicnames.json b/src/Bicep.Core.Samples/Files/baselines/Resources_CRLF/main.symbolicnames.json index 661a30a1688..25832cea164 100644 --- a/src/Bicep.Core.Samples/Files/baselines/Resources_CRLF/main.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/baselines/Resources_CRLF/main.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "12953345672979673276" + "templateHash": "5924434758202725836" } }, "parameters": { @@ -407,7 +407,7 @@ "scope": "[extensionResourceId(extensionResourceId(format('Microsoft.Compute/virtualMachines/{0}', 'vmName'), 'My.Rp/extensionResource', 'extension'), 'Mock.Rp/existingExtensionResource', 'existing1')]", "name": "existing2", "dependsOn": [ - "existing1" + "extension1" ] }, "extension3": { @@ -416,7 +416,7 @@ "scope": "[extensionResourceId(extensionResourceId(format('Microsoft.Compute/virtualMachines/{0}', 'vmName'), 'My.Rp/extensionResource', 'extension'), 'Mock.Rp/existingExtensionResource', 'existing1')]", "name": "extension3", "dependsOn": [ - "existing1" + "extension1" ] }, "storageResources": { @@ -665,10 +665,7 @@ "p3_child1": { "type": "Microsoft.Rp1/resource1/child1", "apiVersion": "2020-06-01", - "name": "[format('{0}/{1}', 'res1', 'child1')]", - "dependsOn": [ - "p3_res1" - ] + "name": "[format('{0}/{1}', 'res1', 'child1')]" }, "p4_res1": { "existing": true, @@ -682,10 +679,7 @@ "type": "Microsoft.Rp1/resource1/child1", "apiVersion": "2020-06-01", "scope": "/", - "name": "[format('{0}/{1}', 'res1', 'child1')]", - "dependsOn": [ - "p4_res1" - ] + "name": "[format('{0}/{1}', 'res1', 'child1')]" }, "sqlServer": { "type": "Microsoft.Sql/servers", diff --git a/src/Bicep.Core.Samples/Files/user_submitted/101/api-management-modular/NameValues.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/101/api-management-modular/NameValues.symbolicnames.json index 60c427e12e0..845c44692a8 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/101/api-management-modular/NameValues.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/101/api-management-modular/NameValues.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "11528852364160566097" + "templateHash": "14248540637091011874" } }, "parameters": { @@ -56,10 +56,7 @@ "secret": "[variables('apimNameValueSet')[copyIndex()].isSecret]", "value": "[variables('apimNameValueSet')[copyIndex()].value]", "tags": "[variables('apimNameValueSet')[copyIndex()].tags]" - }, - "dependsOn": [ - "parentAPIM" - ] + } } }, "outputs": { diff --git a/src/Bicep.Core.Samples/Files/user_submitted/101/api-management-modular/groups.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/101/api-management-modular/groups.symbolicnames.json index 881398951c6..19d32e018c7 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/101/api-management-modular/groups.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/101/api-management-modular/groups.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "403029788224868668" + "templateHash": "6816770503491912011" } }, "parameters": { @@ -47,10 +47,7 @@ "properties": { "displayName": "[variables('groupsSet')[copyIndex()].groupDisplayName]", "description": "[variables('groupsSet')[copyIndex()].groupDescription]" - }, - "dependsOn": [ - "parentAPIM" - ] + } } }, "outputs": { diff --git a/src/Bicep.Core.Samples/Files/user_submitted/101/api-management-modular/main.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/101/api-management-modular/main.symbolicnames.json index 4a4fd0e31f6..93fb1129aba 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/101/api-management-modular/main.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/101/api-management-modular/main.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "13726378283629199613" + "templateHash": "2208926443863165998" } }, "parameters": { @@ -163,7 +163,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "403029788224868668" + "templateHash": "6816770503491912011" } }, "parameters": { @@ -204,10 +204,7 @@ "properties": { "displayName": "[variables('groupsSet')[copyIndex()].groupDisplayName]", "description": "[variables('groupsSet')[copyIndex()].groupDescription]" - }, - "dependsOn": [ - "parentAPIM" - ] + } } }, "outputs": { @@ -251,7 +248,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "8034218730798252475" + "templateHash": "16793550498477002119" } }, "parameters": { @@ -301,10 +298,7 @@ "email": "[variables('usersSet')[copyIndex()].email]", "state": "[variables('usersSet')[copyIndex()].state]", "note": "[variables('usersSet')[copyIndex()].notes]" - }, - "dependsOn": [ - "parentAPIM" - ] + } } } } @@ -336,7 +330,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "11528852364160566097" + "templateHash": "14248540637091011874" } }, "parameters": { @@ -386,10 +380,7 @@ "secret": "[variables('apimNameValueSet')[copyIndex()].isSecret]", "value": "[variables('apimNameValueSet')[copyIndex()].value]", "tags": "[variables('apimNameValueSet')[copyIndex()].tags]" - }, - "dependsOn": [ - "parentAPIM" - ] + } } }, "outputs": { diff --git a/src/Bicep.Core.Samples/Files/user_submitted/101/api-management-modular/users.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/101/api-management-modular/users.symbolicnames.json index eeabf03052f..5ddeded3c45 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/101/api-management-modular/users.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/101/api-management-modular/users.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "8034218730798252475" + "templateHash": "16793550498477002119" } }, "parameters": { @@ -56,10 +56,7 @@ "email": "[variables('usersSet')[copyIndex()].email]", "state": "[variables('usersSet')[copyIndex()].state]", "note": "[variables('usersSet')[copyIndex()].notes]" - }, - "dependsOn": [ - "parentAPIM" - ] + } } } } \ No newline at end of file diff --git a/src/Bicep.Core.Samples/Files/user_submitted/101/azure-bastion/main.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/101/azure-bastion/main.symbolicnames.json index 3b21ef6c973..3efaa313022 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/101/azure-bastion/main.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/101/azure-bastion/main.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "5898567106534730923" + "templateHash": "12715898051173612753" } }, "parameters": { @@ -149,10 +149,7 @@ ] } } - }, - "dependsOn": [ - "existingVirtualNetwork" - ] + } }, "bastionHost": { "type": "Microsoft.Network/bastionHosts", diff --git a/src/Bicep.Core.Samples/Files/user_submitted/101/databricks-all-in-one-template-for-vnet-injection/main.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/101/databricks-all-in-one-template-for-vnet-injection/main.symbolicnames.json index 5c21d866751..6d80df386ac 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/101/databricks-all-in-one-template-for-vnet-injection/main.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/101/databricks-all-in-one-template-for-vnet-injection/main.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "16714276462655423062" + "templateHash": "14481747842301389436" } }, "parameters": { @@ -275,7 +275,6 @@ } }, "dependsOn": [ - "managedResourceGroup", "vnet" ] } diff --git a/src/Bicep.Core.Samples/Files/user_submitted/101/function-premium-vnet-integration/main.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/101/function-premium-vnet-integration/main.symbolicnames.json index 8694153e7d6..492bcdc0395 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/101/function-premium-vnet-integration/main.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/101/function-premium-vnet-integration/main.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "18250750169409311102" + "templateHash": "746252077949181675" } }, "parameters": { @@ -217,7 +217,7 @@ }, "dependsOn": [ "function", - "subnet" + "virtualNetwork" ] }, "subnet": { diff --git a/src/Bicep.Core.Samples/Files/user_submitted/101/resource-with-lock-existing/main.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/101/resource-with-lock-existing/main.symbolicnames.json index 10c407d18c7..32c17048ad3 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/101/resource-with-lock-existing/main.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/101/resource-with-lock-existing/main.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "18313409063500380309" + "templateHash": "13154103683186341528" } }, "parameters": { @@ -28,10 +28,7 @@ "name": "DontDelete", "properties": { "level": "CanNotDelete" - }, - "dependsOn": [ - "storageAcc" - ] + } } } } \ No newline at end of file diff --git a/src/Bicep.Core.Samples/Files/user_submitted/101/template-spec-deploy/main.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/101/template-spec-deploy/main.symbolicnames.json index 4617215c39b..b29207a898f 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/101/template-spec-deploy/main.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/101/template-spec-deploy/main.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "1118487364434069107" + "templateHash": "12321629843193403120" } }, "parameters": { @@ -32,10 +32,7 @@ "apiVersion": "2019-06-01-preview", "subscriptionId": "[parameters('templateSpecSub')]", "resourceGroup": "[parameters('templateSpecRg')]", - "name": "[format('{0}/{1}', parameters('templateSpecName'), parameters('templateSpecVersion'))]", - "dependsOn": [ - "ts" - ] + "name": "[format('{0}/{1}', parameters('templateSpecName'), parameters('templateSpecVersion'))]" }, "ts": { "existing": true, @@ -55,10 +52,7 @@ "id": "[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', parameters('templateSpecSub'), parameters('templateSpecRg')), 'Microsoft.Resources/templateSpecs/versions', parameters('templateSpecName'), parameters('templateSpecVersion'))]" }, "parameters": {} - }, - "dependsOn": [ - "ts::tsVersion" - ] + } } } } \ No newline at end of file diff --git a/src/Bicep.Core.Samples/Files/user_submitted/101/website-with-container/main.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/101/website-with-container/main.symbolicnames.json index 23c17d94d9f..d8ee5cab6f8 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/101/website-with-container/main.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/101/website-with-container/main.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "13381616690819142544" + "templateHash": "15571119746721048953" } }, "parameters": { @@ -82,7 +82,6 @@ "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('farmName'))]" }, "dependsOn": [ - "containerRegistry", "farm" ] }, diff --git a/src/Bicep.Core.Samples/Files/user_submitted/201/avd-backplane-with-network-and-storage-and-monitoring/avd-LogAnalytics.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/201/avd-backplane-with-network-and-storage-and-monitoring/avd-LogAnalytics.symbolicnames.json index 3c73ad86209..0564be742f2 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/201/avd-backplane-with-network-and-storage-and-monitoring/avd-LogAnalytics.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/201/avd-backplane-with-network-and-storage-and-monitoring/avd-LogAnalytics.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "9356800282323307322" + "templateHash": "6607063108355547742" } }, "parameters": { @@ -72,7 +72,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "15977740014990001438" + "templateHash": "7397250722142967265" } }, "parameters": { @@ -128,10 +128,7 @@ "enabled": true } ] - }, - "dependsOn": [ - "hostPool" - ] + } }, "avdwsds": { "type": "Microsoft.Insights/diagnosticSettings", @@ -158,10 +155,7 @@ "enabled": true } ] - }, - "dependsOn": [ - "workspace" - ] + } } } } diff --git a/src/Bicep.Core.Samples/Files/user_submitted/201/avd-backplane-with-network-and-storage-and-monitoring/avd-backplane-module.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/201/avd-backplane-with-network-and-storage-and-monitoring/avd-backplane-module.symbolicnames.json index af2f1b505f2..d424dd568ef 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/201/avd-backplane-with-network-and-storage-and-monitoring/avd-backplane-module.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/201/avd-backplane-with-network-and-storage-and-monitoring/avd-backplane-module.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "16846926962182872904" + "templateHash": "16704253611176477253" } }, "parameters": { @@ -145,7 +145,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "9356800282323307322" + "templateHash": "6607063108355547742" } }, "parameters": { @@ -211,7 +211,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "15977740014990001438" + "templateHash": "7397250722142967265" } }, "parameters": { @@ -267,10 +267,7 @@ "enabled": true } ] - }, - "dependsOn": [ - "hostPool" - ] + } }, "avdwsds": { "type": "Microsoft.Insights/diagnosticSettings", @@ -297,10 +294,7 @@ "enabled": true } ] - }, - "dependsOn": [ - "workspace" - ] + } } } } diff --git a/src/Bicep.Core.Samples/Files/user_submitted/201/avd-backplane-with-network-and-storage-and-monitoring/avd-image-builder-module.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/201/avd-backplane-with-network-and-storage-and-monitoring/avd-image-builder-module.symbolicnames.json index efcd4d0c39e..54c2ede3073 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/201/avd-backplane-with-network-and-storage-and-monitoring/avd-image-builder-module.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/201/avd-backplane-with-network-and-storage-and-monitoring/avd-image-builder-module.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "9616745895991063718" + "templateHash": "2725585745262341266" } }, "parameters": { @@ -99,10 +99,7 @@ "replicationRegions": [] } ] - }, - "dependsOn": [ - "managedidentity" - ] + } }, "aibdef": { "condition": "[parameters('InvokeRunImageBuildThroughDeploymentScript')]", diff --git a/src/Bicep.Core.Samples/Files/user_submitted/201/avd-backplane-with-network-and-storage-and-monitoring/avd-monitor-diag.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/201/avd-backplane-with-network-and-storage-and-monitoring/avd-monitor-diag.symbolicnames.json index 876e2bc88e0..ddf85f0520c 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/201/avd-backplane-with-network-and-storage-and-monitoring/avd-monitor-diag.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/201/avd-backplane-with-network-and-storage-and-monitoring/avd-monitor-diag.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "15977740014990001438" + "templateHash": "7397250722142967265" } }, "parameters": { @@ -62,10 +62,7 @@ "enabled": true } ] - }, - "dependsOn": [ - "hostPool" - ] + } }, "avdwsds": { "type": "Microsoft.Insights/diagnosticSettings", @@ -92,10 +89,7 @@ "enabled": true } ] - }, - "dependsOn": [ - "workspace" - ] + } } } } \ No newline at end of file diff --git a/src/Bicep.Core.Samples/Files/user_submitted/201/avd-backplane-with-network-and-storage-and-monitoring/main.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/201/avd-backplane-with-network-and-storage-and-monitoring/main.symbolicnames.json index 7996c9f2d4e..b1b4515218d 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/201/avd-backplane-with-network-and-storage-and-monitoring/main.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/201/avd-backplane-with-network-and-storage-and-monitoring/main.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "14611001828329396005" + "templateHash": "7712144198658183766" } }, "parameters": { @@ -227,7 +227,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "16846926962182872904" + "templateHash": "16704253611176477253" } }, "parameters": { @@ -366,7 +366,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "9356800282323307322" + "templateHash": "6607063108355547742" } }, "parameters": { @@ -432,7 +432,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "15977740014990001438" + "templateHash": "7397250722142967265" } }, "parameters": { @@ -488,10 +488,7 @@ "enabled": true } ] - }, - "dependsOn": [ - "hostPool" - ] + } }, "avdwsds": { "type": "Microsoft.Insights/diagnosticSettings", @@ -518,10 +515,7 @@ "enabled": true } ] - }, - "dependsOn": [ - "workspace" - ] + } } } } @@ -1107,7 +1101,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "9616745895991063718" + "templateHash": "2725585745262341266" } }, "parameters": { @@ -1200,10 +1194,7 @@ "replicationRegions": [] } ] - }, - "dependsOn": [ - "managedidentity" - ] + } }, "aibdef": { "condition": "[parameters('InvokeRunImageBuildThroughDeploymentScript')]", diff --git a/src/Bicep.Core.Samples/Files/user_submitted/201/cloud-shell-vnet/main.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/201/cloud-shell-vnet/main.symbolicnames.json index 9c8a6af505f..c1a55e368f1 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/201/cloud-shell-vnet/main.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/201/cloud-shell-vnet/main.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "16407625085363720986" + "templateHash": "14742848894010970609" } }, "parameters": { @@ -138,10 +138,7 @@ } } ] - }, - "dependsOn": [ - "existingVNET" - ] + } }, "networkProfile": { "type": "Microsoft.Network/networkProfiles", @@ -237,8 +234,7 @@ } }, "dependsOn": [ - "containerSubnet", - "existingVNET" + "containerSubnet" ] }, "privateEndpoint": { @@ -303,7 +299,6 @@ } }, "dependsOn": [ - "existingVNET", "relaySubnet" ] }, diff --git a/src/Bicep.Core.Samples/Files/user_submitted/201/private-aks-cluster/aks.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/201/private-aks-cluster/aks.symbolicnames.json index 764dcccf1ce..15a8bfe0e48 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/201/private-aks-cluster/aks.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/201/private-aks-cluster/aks.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "17167772107049027399" + "templateHash": "15899882108574365379" } }, "parameters": { @@ -335,10 +335,7 @@ "existing": true, "type": "Microsoft.Network/virtualNetworks/subnets", "apiVersion": "2020-08-01", - "name": "[format('{0}/{1}', variables('virtualNetworkName'), parameters('aksSubnetName'))]", - "dependsOn": [ - "virtualNetwork" - ] + "name": "[format('{0}/{1}', variables('virtualNetworkName'), parameters('aksSubnetName'))]" }, "aksCluster": { "type": "Microsoft.ContainerService/managedClusters", @@ -408,10 +405,7 @@ "apiServerAccessProfile": { "enablePrivateCluster": "[parameters('aksClusterEnablePrivateCluster')]" } - }, - "dependsOn": [ - "aksSubnet" - ] + } } } } \ No newline at end of file diff --git a/src/Bicep.Core.Samples/Files/user_submitted/201/private-aks-cluster/main.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/201/private-aks-cluster/main.symbolicnames.json index 8aae100fd78..2f95d96fb07 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/201/private-aks-cluster/main.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/201/private-aks-cluster/main.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "13138224916093371784" + "templateHash": "7099217802857967896" } }, "parameters": { @@ -1620,7 +1620,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "17167772107049027399" + "templateHash": "15899882108574365379" } }, "parameters": { @@ -1949,10 +1949,7 @@ "existing": true, "type": "Microsoft.Network/virtualNetworks/subnets", "apiVersion": "2020-08-01", - "name": "[format('{0}/{1}', variables('virtualNetworkName'), parameters('aksSubnetName'))]", - "dependsOn": [ - "virtualNetwork" - ] + "name": "[format('{0}/{1}', variables('virtualNetworkName'), parameters('aksSubnetName'))]" }, "aksCluster": { "type": "Microsoft.ContainerService/managedClusters", @@ -2022,10 +2019,7 @@ "apiServerAccessProfile": { "enablePrivateCluster": "[parameters('aksClusterEnablePrivateCluster')]" } - }, - "dependsOn": [ - "aksSubnet" - ] + } } } } diff --git a/src/Bicep.Core.Samples/Files/user_submitted/201/redis-premium-persistence/main.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/201/redis-premium-persistence/main.symbolicnames.json index 4f6df8922fe..6eecc656081 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/201/redis-premium-persistence/main.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/201/redis-premium-persistence/main.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "308803406197414192" + "templateHash": "140703399417510606" } }, "parameters": { @@ -115,10 +115,7 @@ "rdb-backup-max-snapshot-count": "1", "rdb-storage-connection-string": "[format('DefaultEndpointsProtocol=https;BlobEndpoint=https://{0}.blob.{1};AccountName={2};AccountKey={3}', parameters('storageAccountName'), environment().suffixes.storage, parameters('storageAccountName'), listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2021-04-01').keys[0].value)]" } - }, - "dependsOn": [ - "storageAccount" - ] + } }, "diagSettings": { "type": "Microsoft.Insights/diagnosticSettings", diff --git a/src/Bicep.Core.Samples/Files/user_submitted/301/publish-api-to-apim-opendocs/main.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/301/publish-api-to-apim-opendocs/main.symbolicnames.json index e42168d3cf1..305ded79299 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/301/publish-api-to-apim-opendocs/main.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/301/publish-api-to-apim-opendocs/main.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "6433078083851594853" + "templateHash": "15303901391681280108" } }, "parameters": { @@ -93,10 +93,7 @@ "approvalRequired": "[variables('productsSet')[copyIndex()].isApprovalRequired]", "subscriptionsLimit": "[variables('productsSet')[copyIndex()].subscriptionLimit]", "state": "[variables('productsSet')[copyIndex()].publishState]" - }, - "dependsOn": [ - "apiManagementService" - ] + } }, "functionAPI": { "type": "Microsoft.ApiManagement/service/apis", @@ -106,10 +103,7 @@ "format": "[parameters('apiFormat')]", "value": "[parameters('apiEndPointURL')]", "path": "[parameters('apiPath')]" - }, - "dependsOn": [ - "apiManagementService" - ] + } }, "attachAPIToProducts": { "copy": { diff --git a/src/Bicep.Core.Samples/Files/user_submitted/301/sql-database-with-management/main.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/301/sql-database-with-management/main.symbolicnames.json index 668409e5091..b7eb3b99d1f 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/301/sql-database-with-management/main.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/301/sql-database-with-management/main.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "6525915520291992178" + "templateHash": "14707168431149009990" } }, "parameters": { @@ -59,7 +59,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "9981193661517957529" + "templateHash": "4780961502872576504" } }, "parameters": { @@ -172,7 +172,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "4926441281649354787" + "templateHash": "10368826450110315464" } }, "parameters": { @@ -404,9 +404,8 @@ "dependsOn": [ "auditSettings", "dummyDeployments", - "logAnalyticsWorkspace", - "masterDb", - "sqlDatabases" + "sqlDatabases", + "sqlLogicalServerRes" ] }, "diagnosticSettings": { @@ -438,9 +437,8 @@ }, "dependsOn": [ "dummyDeployments", - "logAnalyticsWorkspace", - "masterDb", - "sqlDatabases" + "sqlDatabases", + "sqlLogicalServerRes" ] }, "sqlFirewallRules": { @@ -538,7 +536,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "2334572005318909582" + "templateHash": "5796360048593136515" } }, "parameters": { @@ -663,7 +661,6 @@ }, "dependsOn": [ "auditSettings", - "logAnalyticsWorkspace", "sqlDb", "transparentDataEncryption" ] @@ -696,7 +693,6 @@ "workspaceId": "[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', parameters('sqlDatabase').diagnosticLogsAndMetrics.subscriptionId, parameters('sqlDatabase').diagnosticLogsAndMetrics.resourceGroupName), 'Microsoft.OperationalInsights/workspaces', parameters('sqlDatabase').diagnosticLogsAndMetrics.name)]" }, "dependsOn": [ - "logAnalyticsWorkspace", "sqlDb", "transparentDataEncryption" ] @@ -886,10 +882,7 @@ } } } - }, - "dependsOn": [ - "[format('sqlPassKeyVaults[{0}]', copyIndex())]" - ] + } } } } diff --git a/src/Bicep.Core.Samples/Files/user_submitted/301/sql-database-with-management/modules/sql-database.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/301/sql-database-with-management/modules/sql-database.symbolicnames.json index 666760ec5ce..91c2b2b44c7 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/301/sql-database-with-management/modules/sql-database.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/301/sql-database-with-management/modules/sql-database.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "2334572005318909582" + "templateHash": "5796360048593136515" } }, "parameters": { @@ -131,7 +131,6 @@ }, "dependsOn": [ "auditSettings", - "logAnalyticsWorkspace", "sqlDb", "transparentDataEncryption" ] @@ -164,7 +163,6 @@ "workspaceId": "[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', parameters('sqlDatabase').diagnosticLogsAndMetrics.subscriptionId, parameters('sqlDatabase').diagnosticLogsAndMetrics.resourceGroupName), 'Microsoft.OperationalInsights/workspaces', parameters('sqlDatabase').diagnosticLogsAndMetrics.name)]" }, "dependsOn": [ - "logAnalyticsWorkspace", "sqlDb", "transparentDataEncryption" ] diff --git a/src/Bicep.Core.Samples/Files/user_submitted/301/sql-database-with-management/modules/sql-logical-server.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/301/sql-database-with-management/modules/sql-logical-server.symbolicnames.json index 89652c209c8..0e98b84ee40 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/301/sql-database-with-management/modules/sql-logical-server.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/301/sql-database-with-management/modules/sql-logical-server.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "4926441281649354787" + "templateHash": "10368826450110315464" } }, "parameters": { @@ -238,9 +238,8 @@ "dependsOn": [ "auditSettings", "dummyDeployments", - "logAnalyticsWorkspace", - "masterDb", - "sqlDatabases" + "sqlDatabases", + "sqlLogicalServerRes" ] }, "diagnosticSettings": { @@ -272,9 +271,8 @@ }, "dependsOn": [ "dummyDeployments", - "logAnalyticsWorkspace", - "masterDb", - "sqlDatabases" + "sqlDatabases", + "sqlLogicalServerRes" ] }, "sqlFirewallRules": { @@ -372,7 +370,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "2334572005318909582" + "templateHash": "5796360048593136515" } }, "parameters": { @@ -497,7 +495,6 @@ }, "dependsOn": [ "auditSettings", - "logAnalyticsWorkspace", "sqlDb", "transparentDataEncryption" ] @@ -530,7 +527,6 @@ "workspaceId": "[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', parameters('sqlDatabase').diagnosticLogsAndMetrics.subscriptionId, parameters('sqlDatabase').diagnosticLogsAndMetrics.resourceGroupName), 'Microsoft.OperationalInsights/workspaces', parameters('sqlDatabase').diagnosticLogsAndMetrics.name)]" }, "dependsOn": [ - "logAnalyticsWorkspace", "sqlDb", "transparentDataEncryption" ] diff --git a/src/Bicep.Core.Samples/Files/user_submitted/301/sql-database-with-management/modules/sql-logical-servers.symbolicnames.json b/src/Bicep.Core.Samples/Files/user_submitted/301/sql-database-with-management/modules/sql-logical-servers.symbolicnames.json index 566dc2f2f90..42d995caac7 100644 --- a/src/Bicep.Core.Samples/Files/user_submitted/301/sql-database-with-management/modules/sql-logical-servers.symbolicnames.json +++ b/src/Bicep.Core.Samples/Files/user_submitted/301/sql-database-with-management/modules/sql-logical-servers.symbolicnames.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "9981193661517957529" + "templateHash": "4780961502872576504" } }, "parameters": { @@ -119,7 +119,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "4926441281649354787" + "templateHash": "10368826450110315464" } }, "parameters": { @@ -351,9 +351,8 @@ "dependsOn": [ "auditSettings", "dummyDeployments", - "logAnalyticsWorkspace", - "masterDb", - "sqlDatabases" + "sqlDatabases", + "sqlLogicalServerRes" ] }, "diagnosticSettings": { @@ -385,9 +384,8 @@ }, "dependsOn": [ "dummyDeployments", - "logAnalyticsWorkspace", - "masterDb", - "sqlDatabases" + "sqlDatabases", + "sqlLogicalServerRes" ] }, "sqlFirewallRules": { @@ -485,7 +483,7 @@ "_generator": { "name": "bicep", "version": "dev", - "templateHash": "2334572005318909582" + "templateHash": "5796360048593136515" } }, "parameters": { @@ -610,7 +608,6 @@ }, "dependsOn": [ "auditSettings", - "logAnalyticsWorkspace", "sqlDb", "transparentDataEncryption" ] @@ -643,7 +640,6 @@ "workspaceId": "[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', parameters('sqlDatabase').diagnosticLogsAndMetrics.subscriptionId, parameters('sqlDatabase').diagnosticLogsAndMetrics.resourceGroupName), 'Microsoft.OperationalInsights/workspaces', parameters('sqlDatabase').diagnosticLogsAndMetrics.name)]" }, "dependsOn": [ - "logAnalyticsWorkspace", "sqlDb", "transparentDataEncryption" ] @@ -833,10 +829,7 @@ } } } - }, - "dependsOn": [ - "[format('sqlPassKeyVaults[{0}]', copyIndex())]" - ] + } } } } \ No newline at end of file diff --git a/src/Bicep.Core.UnitTests/Diagnostics/LinterRuleTests/NoUnnecessaryDependsOnRuleTests.cs b/src/Bicep.Core.UnitTests/Diagnostics/LinterRuleTests/NoUnnecessaryDependsOnRuleTests.cs index 85ab17b4f2d..43b39aac6ed 100644 --- a/src/Bicep.Core.UnitTests/Diagnostics/LinterRuleTests/NoUnnecessaryDependsOnRuleTests.cs +++ b/src/Bicep.Core.UnitTests/Diagnostics/LinterRuleTests/NoUnnecessaryDependsOnRuleTests.cs @@ -269,7 +269,7 @@ public void If_DuplicateEntries_ShouldFailForEach() { CompileAndTest( @" - resource vn 'Microsoft.Network/virtualNetworks@2020-06-01' existing = { + resource vn 'Microsoft.Network/virtualNetworks@2020-06-01' = { name: 'vn' resource subnet1 'subnets@2020-06-01' = { @@ -305,10 +305,6 @@ public void If_DuplicateEntries_WhereOneValid_ShouldFailForLast() { CompileAndTest( """ - resource otherVn 'Microsoft.Network/virtualNetworks@2020-06-01' = { - name: 'otherVn' - } - resource vn 'Microsoft.Network/virtualNetworks@2020-06-01' existing = { name: 'vn' @@ -325,15 +321,15 @@ public void If_DuplicateEntries_WhereOneValid_ShouldFailForLast() addressPrefix: '10.0.1.0/24' } dependsOn: [ - otherVn + vn subnet1 - otherVn + vn ] } } """, OnCompileErrors.IncludeErrors, - ["Remove unnecessary dependsOn entry 'otherVn'."]); + ["Remove unnecessary dependsOn entry 'vn'."]); } [TestMethod] @@ -386,7 +382,7 @@ public void If_Explicit_DependsOn_ToParent_FromGrandChild_UsingColonNotation_Sho public void If_UnnecessaryReferenceToParent_FromLoop_ToNonLoopedParent_Should_Fail() { CompileAndTest(@" - resource vn 'Microsoft.Network/virtualNetworks@2021-02-01' existing = { + resource vn 'Microsoft.Network/virtualNetworks@2021-02-01' = { name: 'vn' } @@ -405,6 +401,24 @@ public void If_UnnecessaryReferenceToParent_FromLoop_ToNonLoopedParent_Should_Fa ); } + [TestMethod] + public void Explicit_dependsOn_on_existing_parent_should_ignore_and_pass() => CompileAndTest( + """ + resource vn 'Microsoft.Network/virtualNetworks@2021-02-01' existing = { + name: 'vn' + } + + resource blobServices 'Microsoft.Network/virtualNetworks/subnets@2021-02-01' = [for i in range(0, 3): { + name: 'blobs${i}' + parent: vn + dependsOn: [ + vn + ] + }] + """, + OnCompileErrors.IncludeErrors, + []); + [TestMethod] public void If_ReferencesResourceByIndex_Simple_Should_IgnoreAndPass() { @@ -648,7 +662,7 @@ public void Codefix_removes_dependsOn_element() => AssertCodeFix(@" [TestMethod] public void Codefix_for_If_UnnecessaryReferenceToParent_FromLoop_ToNonLoopedParent() => AssertCodeFix(@" -resource vn 'Microsoft.Network/virtualNetworks@2021-02-01' existing = { +resource vn 'Microsoft.Network/virtualNetworks@2021-02-01' = { name: 'vn' } @@ -660,7 +674,7 @@ public void Codefix_for_If_UnnecessaryReferenceToParent_FromLoop_ToNonLoopedPare ] }] ", @" -resource vn 'Microsoft.Network/virtualNetworks@2021-02-01' existing = { +resource vn 'Microsoft.Network/virtualNetworks@2021-02-01' = { name: 'vn' } diff --git a/src/Bicep.Core/Analyzers/Linter/Rules/NoUnnecessaryDependsOnRule.cs b/src/Bicep.Core/Analyzers/Linter/Rules/NoUnnecessaryDependsOnRule.cs index 87b1d7a9b97..bb2146f6ac9 100644 --- a/src/Bicep.Core/Analyzers/Linter/Rules/NoUnnecessaryDependsOnRule.cs +++ b/src/Bicep.Core/Analyzers/Linter/Rules/NoUnnecessaryDependsOnRule.cs @@ -100,7 +100,12 @@ private ImmutableDictionary dependenciesToWalk.EnqueueRange(transitiveDependencies); } - allDependencies.Add(dependency); + if (!dependency.WeakReference || + dependency.Resource is not ResourceSymbol r || + !r.DeclaringResource.IsExistingResource()) + { + allDependencies.Add(dependency with { WeakReference = false }); + } } builder[kvp.Key] = allDependencies.ToImmutable(); diff --git a/src/Bicep.Core/Emit/ResourceDependency.cs b/src/Bicep.Core/Emit/ResourceDependency.cs index 9a98538a530..55751c301e0 100644 --- a/src/Bicep.Core/Emit/ResourceDependency.cs +++ b/src/Bicep.Core/Emit/ResourceDependency.cs @@ -8,4 +8,6 @@ namespace Bicep.Core.Emit; public record ResourceDependency( DeclaredSymbol Resource, - SyntaxBase? IndexExpression); + SyntaxBase? IndexExpression, + // A reference is considered "weak" if it would not automatically create an implicit dependency in the ARM engine + bool WeakReference = false); diff --git a/src/Bicep.Core/Emit/ResourceDependencyVisitor.cs b/src/Bicep.Core/Emit/ResourceDependencyVisitor.cs index c07d9a5a4ee..abc07782f0b 100644 --- a/src/Bicep.Core/Emit/ResourceDependencyVisitor.cs +++ b/src/Bicep.Core/Emit/ResourceDependencyVisitor.cs @@ -1,18 +1,23 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +using System.Collections.Frozen; using System.Collections.Immutable; using System.Diagnostics; using Bicep.Core.DataFlow; using Bicep.Core.Extensions; using Bicep.Core.Semantics; using Bicep.Core.Semantics.Metadata; +using Bicep.Core.Semantics.Namespaces; using Bicep.Core.Syntax; using Bicep.Core.TypeSystem; +using Bicep.Core.TypeSystem.Types; namespace Bicep.Core.Emit { public class ResourceDependencyVisitor : AstVisitor { + private static readonly FrozenSet ResourceInfoProperties + = new[] { "id", "name", "type", "apiVersion" }.ToFrozenSet(); private readonly SemanticModel model; private Options? options; private readonly IDictionary> resourceDependencies; @@ -76,7 +81,8 @@ public override void VisitResourceDeclarationSyntax(ResourceDeclarationSyntax sy HashSet dependencies = new(); if (model.ResourceAncestors.GetAncestors(resource).LastOrDefault() is { } parent) { - dependencies.Add(new(parent.Resource.Symbol, parent.IndexExpression)); + // Resource ancestors are always weak references. + dependencies.Add(new(parent.Resource.Symbol, parent.IndexExpression, WeakReference: true)); } resourceDependencies[resource.Symbol] = dependencies; @@ -146,7 +152,7 @@ public override void VisitVariableAccessSyntax(VariableAccessSyntax syntax) return; case ResourceSymbol resourceSymbol: - currentResourceDependencies.Add(new(resourceSymbol, GetIndexExpression(syntax, resourceSymbol.IsCollection))); + currentResourceDependencies.Add(new(resourceSymbol, GetIndexExpression(syntax, resourceSymbol.IsCollection), IsWeakReference(syntax, resourceSymbol))); return; case ModuleSymbol moduleSymbol: @@ -155,6 +161,65 @@ public override void VisitVariableAccessSyntax(VariableAccessSyntax syntax) } } + /// + /// Determines whether a reference to a resource is weak. + /// + /// + /// A reference is "weak" if it will not read from the body of a resource. For ARM resources, that means that + /// the reference is only used to read one of the referent's identifiers (id, name, type, apiVersion) or to + /// call a function. (list*() functions will generate an implicit dependency in the ARM engine, + /// but any functions that are resolved at compile time (such as keyVault.getSecret()) will not + /// need to access the resource's body. + /// + /// The referencing syntax. + /// The referenced resource. + private bool IsWeakReference(SyntaxBase syntax, ResourceSymbol resourceSymbol) + => resourceSymbol.TryGetResourceType()?.IsAzResource() is true && ( + IsResourceInfoAccessBase(syntax, resourceSymbol) || + IsResourceFunctionCallBase(syntax) || + IsWithinExplicitParentDeclaration(syntax) || + IsWithinScopeDeclaration(syntax)); + + private bool IsResourceInfoAccessBase(SyntaxBase syntax, ResourceSymbol resource) + => model.Binder.GetParent(syntax) switch + { + PropertyAccessSyntax propertyAccess + => IsResourceInfoAccessBase(resource, propertyAccess.PropertyName.IdentifierName), + ArrayAccessSyntax arrayAccess => model.GetTypeInfo(arrayAccess.IndexExpression) switch + { + // array access can be used to dereference properties, e.g., resourceSymbolicRef['id'] + StringLiteralType indexStr => IsResourceInfoAccessBase(resource, indexStr.RawStringValue), + // it can also dereference a member of a resource collection, e.g., resourceSymbolicRef[0].id + var t when resource.IsCollection && TypeValidator.AreTypesAssignable(t, LanguageConstants.Int) + => IsResourceInfoAccessBase(arrayAccess, resource), + _ => false, + }, + _ => false, + }; + + private static bool IsResourceInfoAccessBase(ResourceSymbol resource, string propertyName) + // if specific top-level properties of an ARM resource are accessed, the compiler will migrate syntax from + // the resource declaration or emit a `resourceInfo()` function + => ResourceInfoProperties.Contains(propertyName); + + private bool IsResourceFunctionCallBase(SyntaxBase syntax) => model.Binder.GetParent(syntax) switch + { + InstanceFunctionCallSyntax => true, + ArrayAccessSyntax arrayAccess when model.GetSymbolInfo(arrayAccess.BaseExpression) is ResourceSymbol r && + r.IsCollection && + TypeValidator.AreTypesAssignable(model.GetTypeInfo(arrayAccess.IndexExpression), LanguageConstants.Int) + => IsResourceFunctionCallBase(arrayAccess), + _ => false, + }; + + private bool IsWithinExplicitParentDeclaration(SyntaxBase syntax) + => TryGetCurrentDeclarationTopLevelProperty(LanguageConstants.ResourceParentPropertyName) is { } nonNull && + model.Binder.IsDescendant(syntax, nonNull); + + private bool IsWithinScopeDeclaration(SyntaxBase syntax) + => TryGetCurrentDeclarationTopLevelProperty(LanguageConstants.ResourceScopePropertyName) is { } nonNull && + model.Binder.IsDescendant(syntax, nonNull); + private ObjectPropertySyntax? TryGetCurrentDeclarationTopLevelProperty(string propertyName) { ObjectSyntax? declaringSyntax = this.currentDeclaration switch @@ -183,7 +248,7 @@ public override void VisitResourceAccessSyntax(ResourceAccessSyntax syntax) switch (model.GetSymbolInfo(syntax)) { case ResourceSymbol resourceSymbol: - currentResourceDependencies.Add(new(resourceSymbol, GetIndexExpression(syntax, resourceSymbol.IsCollection))); + currentResourceDependencies.Add(new(resourceSymbol, GetIndexExpression(syntax, resourceSymbol.IsCollection), IsWeakReference(syntax, resourceSymbol))); return; case ModuleSymbol moduleSymbol: diff --git a/src/Bicep.Core/Intermediate/ExpressionBuilder.cs b/src/Bicep.Core/Intermediate/ExpressionBuilder.cs index 0536e6167bd..74b42dd79bb 100644 --- a/src/Bicep.Core/Intermediate/ExpressionBuilder.cs +++ b/src/Bicep.Core/Intermediate/ExpressionBuilder.cs @@ -1441,7 +1441,9 @@ private IEnumerable> GatherDependencyPaths( private bool IsDependencyPathTerminus(ResourceDependency dependency) => dependency.Resource switch { ModuleSymbol => true, - ResourceSymbol r => !r.DeclaringResource.IsExistingResource() || Context.Settings.EnableSymbolicNames, + ResourceSymbol r => !r.DeclaringResource.IsExistingResource() || + // only use an existing resource as the terminus iff the compilation will include existing resources and the reference is not weak + (Context.Settings.EnableSymbolicNames && !dependency.WeakReference), _ => false, };