Skip to content

Commit

Permalink
Symbolic names: Generate dependsOn for "existing" resources (#11478)
Browse files Browse the repository at this point in the history
Closes #10343
  • Loading branch information
anthony-c-martin committed Aug 29, 2023
1 parent e3f82c6 commit feb4930
Show file tree
Hide file tree
Showing 32 changed files with 291 additions and 113 deletions.
26 changes: 26 additions & 0 deletions src/Bicep.Core.IntegrationTests/ScenarioTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4987,4 +4987,30 @@ public void Test_Issue502()

result.ExcludingLinterDiagnostics().Should().NotHaveAnyDiagnostics();
}

// https://github.com/Azure/bicep/issues/10343
[TestMethod]
public void Test_Issue10343()
{
var result = CompilationHelper.Compile(Services.WithFeatureOverrides(new(SymbolicNameCodegenEnabled: true)), ("main.bicep", @"
resource foo1 'Microsoft.Storage/storageAccounts@2022-09-01' = {
name: 'foo'
}
resource foo2 'Microsoft.Authorization/roleAssignments@2022-04-01' existing = {
scope: foo1
name: 'blah'
}
resource foo3 'Microsoft.Storage/storageAccounts@2022-09-01' = {
name: 'foo3'
properties: {
accessTier: foo2.id
}
}
"));

var evaluated = TemplateEvaluator.Evaluate(result.Template);
evaluated.Should().HaveValueAtPath("resources.foo3.dependsOn", new JArray("foo2"));
}
}
23 changes: 18 additions & 5 deletions src/Bicep.Core.Samples/Files/Modules_CRLF/main.symbolicnames.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "13851089608436625807"
"templateHash": "13086160146120413117"
}
},
"parameters": {
Expand Down Expand Up @@ -1801,7 +1801,10 @@
}
}
}
}
},
"dependsOn": [
"kv"
]
},
"secureModule2": {
"type": "Microsoft.Resources/deployments",
Expand Down Expand Up @@ -1859,7 +1862,10 @@
}
}
}
}
},
"dependsOn": [
"scopedKv"
]
},
"secureModuleLooped": {
"copy": {
Expand Down Expand Up @@ -1921,7 +1927,11 @@
}
}
}
}
},
"dependsOn": [
"[format('loopedKv[{0}]', copyIndex())]",
"[format('loopedKv[{0}]', copyIndex())]"
]
},
"secureModuleCondition": {
"type": "Microsoft.Resources/deployments",
Expand Down Expand Up @@ -1964,7 +1974,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": "236868819280717113"
"templateHash": "16972434704035043060"
}
},
"parameters": {
Expand Down Expand Up @@ -71,13 +71,19 @@
"properties": {
"size": "[reference('existingParent').size]",
"style": "[reference('existingParent::existingChild').style]"
}
},
"dependsOn": [
"existingParent::existingChild"
]
},
"existingParent::existingChild": {
"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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "13455596478469973466"
"templateHash": "8982011885688931227"
}
},
"parameters": {
Expand Down Expand Up @@ -359,7 +359,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 @@ -368,7 +368,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 @@ -617,7 +617,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 @@ -631,7 +634,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"
]
}
},
"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": "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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "16793550498477002119"
"templateHash": "8034218730798252475"
}
},
"parameters": {
Expand Down Expand Up @@ -56,7 +56,10 @@
"email": "[variables('usersSet')[copyIndex()].email]",
"state": "[variables('usersSet')[copyIndex()].state]",
"note": "[variables('usersSet')[copyIndex()].notes]"
}
},
"dependsOn": [
"parentAPIM"
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "13199377578825632986"
"templateHash": "5898567106534730923"
}
},
"parameters": {
Expand Down Expand Up @@ -149,7 +149,10 @@
]
}
}
}
},
"dependsOn": [
"existingVirtualNetwork"
]
},
"bastionHost": {
"type": "Microsoft.Network/bastionHosts",
Expand All @@ -172,6 +175,7 @@
]
},
"dependsOn": [
"existingVirtualNetwork",
"newVirtualNetwork",
"publicIp",
"subnet"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "14481747842301389436"
"templateHash": "16714276462655423062"
}
},
"parameters": {
Expand Down Expand Up @@ -275,6 +275,7 @@
}
},
"dependsOn": [
"managedResourceGroup",
"vnet"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "746252077949181675"
"templateHash": "18250750169409311102"
}
},
"parameters": {
Expand Down Expand Up @@ -217,7 +217,7 @@
},
"dependsOn": [
"function",
"virtualNetwork"
"subnet"
]
},
"subnet": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "13154103683186341528"
"templateHash": "18313409063500380309"
}
},
"parameters": {
Expand All @@ -28,7 +28,10 @@
"name": "DontDelete",
"properties": {
"level": "CanNotDelete"
}
},
"dependsOn": [
"storageAcc"
]
}
}
}
Loading

0 comments on commit feb4930

Please sign in to comment.