Skip to content

Commit

Permalink
Back out change to symbolic name dependency inference
Browse files Browse the repository at this point in the history
  • Loading branch information
jeskew committed Nov 27, 2024
1 parent 7f65b4d commit 7aceac6
Show file tree
Hide file tree
Showing 32 changed files with 249 additions and 186 deletions.
22 changes: 11 additions & 11 deletions src/Bicep.Core.IntegrationTests/Emit/DependencyInferenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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", """["deployedSa"]""");
result.Template.Should().HaveJsonAtPath("$.resources.newSa.dependsOn", """["existingSa"]""");
result.Template.Should().HaveJsonAtPath("$.resources.existingSa.dependsOn", """["deployedSa"]""");
}

Expand Down Expand Up @@ -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", """["deployedSa"]""");
result.Template.Should().HaveJsonAtPath("$.resources.newSa.dependsOn", """["[format('existingSa[{0}]', 0)]"]""");
result.Template.Should().HaveJsonAtPath("$.resources.existingSa.dependsOn", """["deployedSa"]""");
}

Expand Down Expand Up @@ -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", """["deployedSa"]""");
result.Template.Should().HaveJsonAtPath("$.resources.newSa.dependsOn", """["existingSa"]""");
result.Template.Should().HaveJsonAtPath("$.resources.existingSa.dependsOn", """["deployedSa"]""");
}

Expand Down Expand Up @@ -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", """["deployedSa"]""");
result.Template.Should().HaveJsonAtPath("$.resources.newSa.dependsOn", """["[format('existingSa[{0}]', 0)]"]""");
result.Template.Should().HaveJsonAtPath("$.resources.existingSa.dependsOn", """["deployedSa"]""");
}

Expand Down Expand Up @@ -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().NotHaveValueAtPath("$.resources.sa.dependsOn");
result.Template.Should().HaveJsonAtPath("$.resources.sa.dependsOn", """["subnet"]""");
}

[DataTestMethod]
Expand Down Expand Up @@ -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", """["vnets"]""");
result.Template.Should().HaveJsonAtPath("$.resources.vault.dependsOn", """["subnets"]""");
}
else
{
Expand Down Expand Up @@ -485,7 +485,7 @@ public void Looped_resource_depending_on_looped_existing_resource_should_depend_
{
result.Template.Should().HaveJsonAtPath(
"$.resources.vault.dependsOn",
"""["[format('vnets[{0}]', mod(range(0, 10)[sub(range(10, 10)[copyIndex()], 10)], 2))]"]""");
"""["[format('subnets[{0}]', sub(range(10, 10)[copyIndex()], 10))]"]""");
}
else
{
Expand Down Expand Up @@ -538,7 +538,7 @@ public void Looped_resource_depending_on_looped_variable_should_depend_on_transi
{
result.Template.Should().HaveJsonAtPath(
"$.resources.vault.dependsOn",
"""["[format('vnets[{0}]', mod(range(0, 10)[sub(range(20, 10)[sub(range(10, 10)[copyIndex()], 10)], 20)], 2))]"]""");
"""["[format('subnets[{0}]', sub(range(20, 10)[sub(range(10, 10)[copyIndex()], 10)], 20))]"]""");
}
else
{
Expand Down Expand Up @@ -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('vnets[{0}]', 0)]"]""");
result.Template.Should().HaveJsonAtPath("$.resources.vault.dependsOn", """["[format('subnets[{0}]', sub(range(10, 10)[copyIndex()], 10))]"]""");
}
else
{
Expand Down Expand Up @@ -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('vnets[{0}]', mod(range(0, 10)[0], 2))]"]""");
result.Template.Should().HaveJsonAtPath("$.resources.vault.dependsOn", """["[format('subnets[{0}]', 0)]"]""");
}
else
{
Expand Down Expand Up @@ -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().NotHaveValueAtPath("$.resources.empty.dependsOn");
result.Template.Should().HaveJsonAtPath("$.resources.empty.dependsOn", """["rg"]""");
}
}
7 changes: 4 additions & 3 deletions src/Bicep.Core.IntegrationTests/ScenarioTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5066,7 +5066,7 @@ public void Test_Issue10343()
"));

var evaluated = TemplateEvaluator.Evaluate(result.Template).ToJToken();
evaluated.Should().HaveValueAtPath("resources.foo3.dependsOn", new JArray("foo1"));
evaluated.Should().HaveValueAtPath("resources.foo3.dependsOn", new JArray("foo2"));
}

// https://github.com/Azure/bicep/issues/11292
Expand Down Expand Up @@ -6316,7 +6316,7 @@ public void Test_Issue13596(bool enableSymbolicNameCodegen)

if (enableSymbolicNameCodegen)
{
result.Template.Should().HaveJsonAtPath("$.resources.secret.dependsOn", """["mod"]""");
result.Template.Should().HaveJsonAtPath("$.resources.secret.dependsOn", """["sa"]""");
}
else
{
Expand Down Expand Up @@ -6478,7 +6478,7 @@ extension microsoftGraph
}

[TestMethod]
public void Test_Issue15686()
public void Test_Issue15686_repro()
{
var result = CompilationHelper.Compile("""
param eventSubscriptionName string
Expand Down Expand Up @@ -6525,6 +6525,7 @@ param functionName string
result.Template.Should().NotBeNull();
result.Template.Should().HaveJsonAtPath("$.resources.eventSubscription.dependsOn", """
[
"eventGridTopic",
"functionApp"
]
""");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "14846102413726496336"
"templateHash": "12632249060210513106"
}
},
"parameters": {
Expand Down Expand Up @@ -1851,7 +1851,10 @@
}
}
}
}
},
"dependsOn": [
"kv"
]
},
"secureModule2": {
"type": "Microsoft.Resources/deployments",
Expand Down Expand Up @@ -1909,7 +1912,10 @@
}
}
}
}
},
"dependsOn": [
"scopedKv"
]
},
"secureModuleLooped": {
"copy": {
Expand Down Expand Up @@ -1971,7 +1977,11 @@
}
}
}
}
},
"dependsOn": [
"[format('loopedKv[{0}]', copyIndex())]",
"[format('loopedKv[{0}]', copyIndex())]"
]
},
"secureModuleCondition": {
"type": "Microsoft.Resources/deployments",
Expand Down Expand Up @@ -2014,7 +2024,10 @@
}
}
}
}
},
"dependsOn": [
"kv"
]
},
"withSpace": {
"type": "Microsoft.Resources/deployments",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "15846782372928243436"
"templateHash": "9375757315581642416"
}
},
"parameters": {
Expand Down Expand Up @@ -82,7 +82,10 @@
"existing": true,
"type": "My.Rp/parentType/childType",
"apiVersion": "2020-12-01",
"name": "[format('{0}/{1}', 'existingParent', 'existingChild')]"
"name": "[format('{0}/{1}', 'existingParent', 'existingChild')]",
"dependsOn": [
"existingParent"
]
},
"conditionParent::conditionChild::conditionGrandchild": {
"condition": "[and(and(parameters('createParent'), parameters('createChild')), parameters('createGrandchild'))]",
Expand Down Expand Up @@ -159,4 +162,4 @@
"value": "loopChild"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "5924434758202725836"
"templateHash": "12953345672979673276"
}
},
"parameters": {
Expand Down Expand Up @@ -407,7 +407,7 @@
"scope": "[extensionResourceId(extensionResourceId(format('Microsoft.Compute/virtualMachines/{0}', 'vmName'), 'My.Rp/extensionResource', 'extension'), 'Mock.Rp/existingExtensionResource', 'existing1')]",
"name": "existing2",
"dependsOn": [
"extension1"
"existing1"
]
},
"extension3": {
Expand All @@ -416,7 +416,7 @@
"scope": "[extensionResourceId(extensionResourceId(format('Microsoft.Compute/virtualMachines/{0}', 'vmName'), 'My.Rp/extensionResource', 'extension'), 'Mock.Rp/existingExtensionResource', 'existing1')]",
"name": "extension3",
"dependsOn": [
"extension1"
"existing1"
]
},
"storageResources": {
Expand Down Expand Up @@ -665,7 +665,10 @@
"p3_child1": {
"type": "Microsoft.Rp1/resource1/child1",
"apiVersion": "2020-06-01",
"name": "[format('{0}/{1}', 'res1', 'child1')]"
"name": "[format('{0}/{1}', 'res1', 'child1')]",
"dependsOn": [
"p3_res1"
]
},
"p4_res1": {
"existing": true,
Expand All @@ -679,7 +682,10 @@
"type": "Microsoft.Rp1/resource1/child1",
"apiVersion": "2020-06-01",
"scope": "/",
"name": "[format('{0}/{1}', 'res1', 'child1')]"
"name": "[format('{0}/{1}', 'res1', 'child1')]",
"dependsOn": [
"p4_res1"
]
},
"sqlServer": {
"type": "Microsoft.Sql/servers",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "14248540637091011874"
"templateHash": "11528852364160566097"
}
},
"parameters": {
Expand Down Expand Up @@ -56,7 +56,10 @@
"secret": "[variables('apimNameValueSet')[copyIndex()].isSecret]",
"value": "[variables('apimNameValueSet')[copyIndex()].value]",
"tags": "[variables('apimNameValueSet')[copyIndex()].tags]"
}
},
"dependsOn": [
"parentAPIM"
]
}
},
"outputs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "6816770503491912011"
"templateHash": "403029788224868668"
}
},
"parameters": {
Expand Down Expand Up @@ -47,7 +47,10 @@
"properties": {
"displayName": "[variables('groupsSet')[copyIndex()].groupDisplayName]",
"description": "[variables('groupsSet')[copyIndex()].groupDescription]"
}
},
"dependsOn": [
"parentAPIM"
]
}
},
"outputs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "2208926443863165998"
"templateHash": "13726378283629199613"
}
},
"parameters": {
Expand Down Expand Up @@ -163,7 +163,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "6816770503491912011"
"templateHash": "403029788224868668"
}
},
"parameters": {
Expand Down Expand Up @@ -204,7 +204,10 @@
"properties": {
"displayName": "[variables('groupsSet')[copyIndex()].groupDisplayName]",
"description": "[variables('groupsSet')[copyIndex()].groupDescription]"
}
},
"dependsOn": [
"parentAPIM"
]
}
},
"outputs": {
Expand Down Expand Up @@ -248,7 +251,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "16793550498477002119"
"templateHash": "8034218730798252475"
}
},
"parameters": {
Expand Down Expand Up @@ -298,7 +301,10 @@
"email": "[variables('usersSet')[copyIndex()].email]",
"state": "[variables('usersSet')[copyIndex()].state]",
"note": "[variables('usersSet')[copyIndex()].notes]"
}
},
"dependsOn": [
"parentAPIM"
]
}
}
}
Expand Down Expand Up @@ -330,7 +336,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "14248540637091011874"
"templateHash": "11528852364160566097"
}
},
"parameters": {
Expand Down Expand Up @@ -380,7 +386,10 @@
"secret": "[variables('apimNameValueSet')[copyIndex()].isSecret]",
"value": "[variables('apimNameValueSet')[copyIndex()].value]",
"tags": "[variables('apimNameValueSet')[copyIndex()].tags]"
}
},
"dependsOn": [
"parentAPIM"
]
}
},
"outputs": {
Expand Down
Loading

0 comments on commit 7aceac6

Please sign in to comment.