diff --git a/docs/examples/101/aks/main.json b/docs/examples/101/aks/main.json index e6b8a6a6717..c8b046a5b74 100644 --- a/docs/examples/101/aks/main.json +++ b/docs/examples/101/aks/main.json @@ -43,7 +43,6 @@ } }, "functions": [], - "variables": {}, "resources": [ { "type": "Microsoft.ContainerService/managedClusters", diff --git a/docs/examples/101/app-config/main.json b/docs/examples/101/app-config/main.json index 9dc158d7bf4..3d4eec1f54c 100644 --- a/docs/examples/101/app-config/main.json +++ b/docs/examples/101/app-config/main.json @@ -30,7 +30,6 @@ } }, "functions": [], - "variables": {}, "resources": [ { "type": "Microsoft.AppConfiguration/configurationStores", diff --git a/docs/examples/101/container-registry/main.json b/docs/examples/101/container-registry/main.json index cf338278cf4..58ab9dcba1a 100644 --- a/docs/examples/101/container-registry/main.json +++ b/docs/examples/101/container-registry/main.json @@ -39,7 +39,6 @@ } }, "functions": [], - "variables": {}, "resources": [ { "type": "Microsoft.ContainerRegistry/registries", diff --git a/docs/examples/101/cosmosdb-webapp/main.json b/docs/examples/101/cosmosdb-webapp/main.json index 72d8e884934..35391c7467f 100644 --- a/docs/examples/101/cosmosdb-webapp/main.json +++ b/docs/examples/101/cosmosdb-webapp/main.json @@ -136,6 +136,5 @@ "[resourceId('Microsoft.Web/sites', variables('websiteName'))]" ] } - ], - "outputs": {} + ] } \ No newline at end of file diff --git a/docs/examples/101/databricks-all-in-one-template-for-vnet-injection/main.json b/docs/examples/101/databricks-all-in-one-template-for-vnet-injection/main.json index bb9f0b6b9d7..b19b400239f 100644 --- a/docs/examples/101/databricks-all-in-one-template-for-vnet-injection/main.json +++ b/docs/examples/101/databricks-all-in-one-template-for-vnet-injection/main.json @@ -138,6 +138,5 @@ "[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetName'))]" ] } - ], - "outputs": {} + ] } \ No newline at end of file diff --git a/docs/examples/101/function-app-create/main.json b/docs/examples/101/function-app-create/main.json index e7cce4aea1e..b7304e6dc86 100644 --- a/docs/examples/101/function-app-create/main.json +++ b/docs/examples/101/function-app-create/main.json @@ -275,6 +275,5 @@ "[resourceId('Microsoft.Web/sites', variables('functionAppName'))]" ] } - ], - "outputs": {} + ] } \ No newline at end of file diff --git a/docs/examples/101/key-vault-secret-only/main.json b/docs/examples/101/key-vault-secret-only/main.json index 62f4b305972..82d3db6cce2 100644 --- a/docs/examples/101/key-vault-secret-only/main.json +++ b/docs/examples/101/key-vault-secret-only/main.json @@ -18,7 +18,6 @@ } }, "functions": [], - "variables": {}, "resources": [ { "type": "Microsoft.KeyVault/vaults/secrets", @@ -29,6 +28,5 @@ "value": "[parameters('secretValue')]" } } - ], - "outputs": {} + ] } \ No newline at end of file diff --git a/docs/examples/101/logic-app-create/main.json b/docs/examples/101/logic-app-create/main.json index 934d4f27aea..1a8a6a0c67f 100644 --- a/docs/examples/101/logic-app-create/main.json +++ b/docs/examples/101/logic-app-create/main.json @@ -54,6 +54,5 @@ } } } - ], - "outputs": {} + ] } \ No newline at end of file diff --git a/docs/examples/101/monitor-action-groups/main.json b/docs/examples/101/monitor-action-groups/main.json index 6475cc7ce82..1b8ce9b0660 100644 --- a/docs/examples/101/monitor-action-groups/main.json +++ b/docs/examples/101/monitor-action-groups/main.json @@ -50,7 +50,6 @@ } }, "functions": [], - "variables": {}, "resources": [ { "type": "microsoft.insights/actionGroups", diff --git a/docs/examples/101/storage-blob-container/main.json b/docs/examples/101/storage-blob-container/main.json index aefb392c73c..111559db519 100644 --- a/docs/examples/101/storage-blob-container/main.json +++ b/docs/examples/101/storage-blob-container/main.json @@ -15,7 +15,6 @@ } }, "functions": [], - "variables": {}, "resources": [ { "type": "Microsoft.Storage/storageAccounts", @@ -39,6 +38,5 @@ "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]" ] } - ], - "outputs": {} + ] } \ No newline at end of file diff --git a/docs/examples/101/vnet-two-subnets/main.json b/docs/examples/101/vnet-two-subnets/main.json index 09452569980..2dd072994c2 100644 --- a/docs/examples/101/vnet-two-subnets/main.json +++ b/docs/examples/101/vnet-two-subnets/main.json @@ -57,6 +57,5 @@ ] } } - ], - "outputs": {} + ] } \ No newline at end of file diff --git a/docs/examples/201/decrypt-running-windows-vm-without-aad/main.json b/docs/examples/201/decrypt-running-windows-vm-without-aad/main.json index ebe09cefad4..6cc71578b2a 100644 --- a/docs/examples/201/decrypt-running-windows-vm-without-aad/main.json +++ b/docs/examples/201/decrypt-running-windows-vm-without-aad/main.json @@ -19,7 +19,6 @@ } }, "functions": [], - "variables": {}, "resources": [ { "type": "Microsoft.Compute/virtualMachines/extensions", @@ -38,6 +37,5 @@ } } } - ], - "outputs": {} + ] } \ No newline at end of file diff --git a/docs/examples/201/firewall-with-ip-from-prefix/main.json b/docs/examples/201/firewall-with-ip-from-prefix/main.json index 8dcca859d28..a4e00979245 100644 --- a/docs/examples/201/firewall-with-ip-from-prefix/main.json +++ b/docs/examples/201/firewall-with-ip-from-prefix/main.json @@ -130,6 +130,5 @@ "[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetname'))]" ] } - ], - "outputs": {} + ] } \ No newline at end of file diff --git a/docs/examples/201/iot-with-storage/main.json b/docs/examples/201/iot-with-storage/main.json index 780ffe304e5..b061aa32853 100644 --- a/docs/examples/201/iot-with-storage/main.json +++ b/docs/examples/201/iot-with-storage/main.json @@ -128,6 +128,5 @@ "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]" ] } - ], - "outputs": {} + ] } \ No newline at end of file diff --git a/docs/examples/201/key-vault-secret-create/main.json b/docs/examples/201/key-vault-secret-create/main.json index 1a9b0e4714c..f8a2bd4dae7 100644 --- a/docs/examples/201/key-vault-secret-create/main.json +++ b/docs/examples/201/key-vault-secret-create/main.json @@ -138,6 +138,5 @@ "[resourceId('Microsoft.KeyVault/vaults', parameters('keyVaultName'))]" ] } - ], - "outputs": {} + ] } \ No newline at end of file diff --git a/docs/examples/201/log-analytics-with-solutions-and-diagnostics/main.json b/docs/examples/201/log-analytics-with-solutions-and-diagnostics/main.json index d2e972507f9..2e9c2eb65ce 100644 --- a/docs/examples/201/log-analytics-with-solutions-and-diagnostics/main.json +++ b/docs/examples/201/log-analytics-with-solutions-and-diagnostics/main.json @@ -139,6 +139,5 @@ "[resourceId('Microsoft.OperationalInsights/workspaces', parameters('logAnalyticsWorkspaceName'))]" ] } - ], - "outputs": {} + ] } \ No newline at end of file diff --git a/docs/examples/201/policy-with-initiative-definition-and-assignment/main.json b/docs/examples/201/policy-with-initiative-definition-and-assignment/main.json index 6ff1e66396d..6a046537886 100644 --- a/docs/examples/201/policy-with-initiative-definition-and-assignment/main.json +++ b/docs/examples/201/policy-with-initiative-definition-and-assignment/main.json @@ -109,6 +109,5 @@ "[resourceId('Microsoft.Authorization/policySetDefinitions', variables('initiativeDefinitionName'))]" ] } - ], - "outputs": {} + ] } \ No newline at end of file diff --git a/docs/examples/201/sql/main.json b/docs/examples/201/sql/main.json index 3e503505cb5..49b46594571 100644 --- a/docs/examples/201/sql/main.json +++ b/docs/examples/201/sql/main.json @@ -68,6 +68,5 @@ "[resourceId('Microsoft.Sql/servers/databases', split(format('{0}/{1}', variables('sqlServerName'), variables('databaseName')), '/')[0], split(format('{0}/{1}', variables('sqlServerName'), variables('databaseName')), '/')[1])]" ] } - ], - "outputs": {} + ] } \ No newline at end of file diff --git a/docs/examples/201/vm-push-cert-windows/main.json b/docs/examples/201/vm-push-cert-windows/main.json index 801897bbcf7..d034470657b 100644 --- a/docs/examples/201/vm-push-cert-windows/main.json +++ b/docs/examples/201/vm-push-cert-windows/main.json @@ -179,6 +179,5 @@ "[resourceId('Microsoft.Network/networkInterfaces', 'certNic')]" ] } - ], - "outputs": {} + ] } \ No newline at end of file diff --git a/docs/examples/201/vm-windows-with-custom-script-extension/main.json b/docs/examples/201/vm-windows-with-custom-script-extension/main.json index 016c33bf137..24351879674 100644 --- a/docs/examples/201/vm-windows-with-custom-script-extension/main.json +++ b/docs/examples/201/vm-windows-with-custom-script-extension/main.json @@ -289,6 +289,5 @@ "[resourceId('Microsoft.Compute/virtualMachines', variables('virtualMachine').name)]" ] } - ], - "outputs": {} + ] } \ No newline at end of file diff --git a/docs/examples/201/vnet-peering/main.json b/docs/examples/201/vnet-peering/main.json index f660b6bce6d..9ca70a46904 100644 --- a/docs/examples/201/vnet-peering/main.json +++ b/docs/examples/201/vnet-peering/main.json @@ -13,7 +13,6 @@ } }, "functions": [], - "variables": {}, "resources": [ { "type": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings", @@ -29,6 +28,5 @@ } } } - ], - "outputs": {} + ] } \ No newline at end of file diff --git a/docs/examples/201/vnet-to-vnet-bgp/main.json b/docs/examples/201/vnet-to-vnet-bgp/main.json index 3793607baf3..2f02451f4c3 100644 --- a/docs/examples/201/vnet-to-vnet-bgp/main.json +++ b/docs/examples/201/vnet-to-vnet-bgp/main.json @@ -239,6 +239,5 @@ "[resourceId('Microsoft.Network/virtualNetworkGateways', variables('vnet2cfg').gatewayName)]" ] } - ], - "outputs": {} + ] } \ No newline at end of file diff --git a/docs/examples/modules/1vm-2nics-2subnets-1vnet/main.json b/docs/examples/modules/1vm-2nics-2subnets-1vnet/main.json index 6f1b3f13960..cef560c11f0 100644 --- a/docs/examples/modules/1vm-2nics-2subnets-1vnet/main.json +++ b/docs/examples/modules/1vm-2nics-2subnets-1vnet/main.json @@ -229,7 +229,6 @@ } }, "functions": [], - "variables": {}, "resources": [ { "type": "Microsoft.Compute/virtualMachines", @@ -284,8 +283,7 @@ } } } - ], - "outputs": {} + ] } }, "dependsOn": [ diff --git a/docs/examples/modules/1vm-2nics-2subnets-1vnet/vm.json b/docs/examples/modules/1vm-2nics-2subnets-1vnet/vm.json index 7f6b61c9fa3..7b95316233e 100644 --- a/docs/examples/modules/1vm-2nics-2subnets-1vnet/vm.json +++ b/docs/examples/modules/1vm-2nics-2subnets-1vnet/vm.json @@ -29,7 +29,6 @@ } }, "functions": [], - "variables": {}, "resources": [ { "type": "Microsoft.Compute/virtualMachines", @@ -84,6 +83,5 @@ } } } - ], - "outputs": {} + ] } \ No newline at end of file diff --git a/docs/examples/modules/basic-publicip/main.json b/docs/examples/modules/basic-publicip/main.json index 87eea4ef175..466f87dca9b 100644 --- a/docs/examples/modules/basic-publicip/main.json +++ b/docs/examples/modules/basic-publicip/main.json @@ -1,81 +1,79 @@ -{ - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "publicIpName": { - "type": "string", - "defaultValue": "mypublicip" - } - }, - "functions": [], - "variables": {}, - "resources": [ - { - "type": "Microsoft.Resources/deployments", - "apiVersion": "2019-10-01", - "name": "publicIp", - "properties": { - "expressionEvaluationOptions": { - "scope": "inner" - }, - "mode": "Incremental", - "parameters": { - "publicIpResourceName": { - "value": "[parameters('publicIpName')]" - }, - "dynamicAllocation": { - "value": true - } - }, - "template": { - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "publicIpResourceName": { - "type": "string" - }, - "publicIpDnsLabel": { - "type": "string", - "defaultValue": "[format('{0}-{1}', parameters('publicIpResourceName'), newGuid())]" - }, - "location": { - "type": "string", - "defaultValue": "[resourceGroup().location]" - }, - "dynamicAllocation": { - "type": "bool" - } - }, - "functions": [], - "variables": {}, - "resources": [ - { - "type": "Microsoft.Network/publicIPAddresses", - "apiVersion": "2020-06-01", - "name": "[parameters('publicIpResourceName')]", - "location": "[parameters('location')]", - "properties": { - "publicIPAllocationMethod": "[if(parameters('dynamicAllocation'), 'Dynamic', 'Static')]", - "dnsSettings": { - "domainNameLabel": "[parameters('publicIpDnsLabel')]" - } - } - } - ], - "outputs": { - "ipFqdn": { - "type": "string", - "value": "[reference(resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIpResourceName'))).dnsSettings.fqdn]" - } - } - } - } - } - ], - "outputs": { - "ipFqdn": { - "type": "string", - "value": "[reference(resourceId('Microsoft.Resources/deployments', 'publicIp'), '2019-10-01').outputs.ipFqdn.value]" - } - } +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "publicIpName": { + "type": "string", + "defaultValue": "mypublicip" + } + }, + "functions": [], + "resources": [ + { + "type": "Microsoft.Resources/deployments", + "apiVersion": "2019-10-01", + "name": "publicIp", + "properties": { + "expressionEvaluationOptions": { + "scope": "inner" + }, + "mode": "Incremental", + "parameters": { + "publicIpResourceName": { + "value": "[parameters('publicIpName')]" + }, + "dynamicAllocation": { + "value": true + } + }, + "template": { + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "publicIpResourceName": { + "type": "string" + }, + "publicIpDnsLabel": { + "type": "string", + "defaultValue": "[format('{0}-{1}', parameters('publicIpResourceName'), newGuid())]" + }, + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]" + }, + "dynamicAllocation": { + "type": "bool" + } + }, + "functions": [], + "resources": [ + { + "type": "Microsoft.Network/publicIPAddresses", + "apiVersion": "2020-06-01", + "name": "[parameters('publicIpResourceName')]", + "location": "[parameters('location')]", + "properties": { + "publicIPAllocationMethod": "[if(parameters('dynamicAllocation'), 'Dynamic', 'Static')]", + "dnsSettings": { + "domainNameLabel": "[parameters('publicIpDnsLabel')]" + } + } + } + ], + "outputs": { + "ipFqdn": { + "type": "string", + "value": "[reference(resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIpResourceName'))).dnsSettings.fqdn]" + } + } + } + } + } + ], + "outputs": { + "ipFqdn": { + "type": "string", + "value": "[reference(resourceId('Microsoft.Resources/deployments', 'publicIp'), '2019-10-01').outputs.ipFqdn.value]" + } + } } \ No newline at end of file diff --git a/docs/examples/modules/basic-publicip/publicIpAddress.json b/docs/examples/modules/basic-publicip/publicIpAddress.json index 62090f4ace7..1b2aa69263f 100644 --- a/docs/examples/modules/basic-publicip/publicIpAddress.json +++ b/docs/examples/modules/basic-publicip/publicIpAddress.json @@ -18,7 +18,6 @@ } }, "functions": [], - "variables": {}, "resources": [ { "type": "Microsoft.Network/publicIPAddresses", diff --git a/docs/examples/not-working-yet/301-nested-vms-in-virtual-network/main.json b/docs/examples/not-working-yet/301-nested-vms-in-virtual-network/main.json index bfd469e042e..892c7c91c07 100644 --- a/docs/examples/not-working-yet/301-nested-vms-in-virtual-network/main.json +++ b/docs/examples/not-working-yet/301-nested-vms-in-virtual-network/main.json @@ -400,6 +400,5 @@ "[resourceId('Microsoft.Network/networkInterfaces', parameters('HostNetworkInterface2Name'))]" ] } - ], - "outputs": {} + ] } \ No newline at end of file diff --git a/src/Bicep.Core.Samples/Files/AKS_LF/main.json b/src/Bicep.Core.Samples/Files/AKS_LF/main.json index 8aa8a981dfe..9cba2cae593 100644 --- a/src/Bicep.Core.Samples/Files/AKS_LF/main.json +++ b/src/Bicep.Core.Samples/Files/AKS_LF/main.json @@ -43,7 +43,6 @@ } }, "functions": [], - "variables": {}, "resources": [ { "type": "Microsoft.ContainerService/managedClusters", @@ -77,6 +76,5 @@ } } } - ], - "outputs": {} + ] } \ No newline at end of file diff --git a/src/Bicep.Core.Samples/Files/Empty/main.json b/src/Bicep.Core.Samples/Files/Empty/main.json index 0f79e407ac3..fcb4c0407db 100644 --- a/src/Bicep.Core.Samples/Files/Empty/main.json +++ b/src/Bicep.Core.Samples/Files/Empty/main.json @@ -1,9 +1,6 @@ { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", - "parameters": {}, "functions": [], - "variables": {}, - "resources": [], - "outputs": {} + "resources": [] } \ No newline at end of file diff --git a/src/Bicep.Core.Samples/Files/Modules_CRLF/main.json b/src/Bicep.Core.Samples/Files/Modules_CRLF/main.json index 61d418174fa..2b104f84d45 100644 --- a/src/Bicep.Core.Samples/Files/Modules_CRLF/main.json +++ b/src/Bicep.Core.Samples/Files/Modules_CRLF/main.json @@ -1,9 +1,7 @@ { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", - "parameters": {}, "functions": [], - "variables": {}, "resources": [ { "type": "Mock.Rp/mockResource", @@ -64,7 +62,6 @@ } }, "functions": [], - "variables": {}, "resources": [ { "type": "Mock.Rp/mockResource", @@ -126,7 +123,6 @@ } }, "functions": [], - "variables": {}, "resources": [ { "type": "Mock.Rp/mockResource", @@ -181,7 +177,6 @@ } }, "functions": [], - "variables": {}, "resources": [], "outputs": { "outputObj": { @@ -235,7 +230,6 @@ } }, "functions": [], - "variables": {}, "resources": [], "outputs": { "outputObj": { @@ -302,7 +296,6 @@ } }, "functions": [], - "variables": {}, "resources": [], "outputs": { "outputObj": { diff --git a/src/Bicep.Core.Samples/Files/Outputs_CRLF/main.json b/src/Bicep.Core.Samples/Files/Outputs_CRLF/main.json index 684faf2312e..a7fa209d296 100644 --- a/src/Bicep.Core.Samples/Files/Outputs_CRLF/main.json +++ b/src/Bicep.Core.Samples/Files/Outputs_CRLF/main.json @@ -1,9 +1,7 @@ { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", - "parameters": {}, "functions": [], - "variables": {}, "resources": [], "outputs": { "myStr": { diff --git a/src/Bicep.Core.Samples/Files/Parameters_CRLF/main.json b/src/Bicep.Core.Samples/Files/Parameters_CRLF/main.json index 0a0d9b1532f..3cf69295f03 100644 --- a/src/Bicep.Core.Samples/Files/Parameters_CRLF/main.json +++ b/src/Bicep.Core.Samples/Files/Parameters_CRLF/main.json @@ -159,7 +159,5 @@ } }, "functions": [], - "variables": {}, - "resources": [], - "outputs": {} + "resources": [] } \ No newline at end of file diff --git a/src/Bicep.Core.Samples/Files/Parameters_LF/main.json b/src/Bicep.Core.Samples/Files/Parameters_LF/main.json index 43cf71108f0..3e7e2f3457d 100644 --- a/src/Bicep.Core.Samples/Files/Parameters_LF/main.json +++ b/src/Bicep.Core.Samples/Files/Parameters_LF/main.json @@ -157,7 +157,5 @@ } }, "functions": [], - "variables": {}, - "resources": [], - "outputs": {} + "resources": [] } \ No newline at end of file diff --git a/src/Bicep.Core.Samples/Files/Variables_LF/main.json b/src/Bicep.Core.Samples/Files/Variables_LF/main.json index 011bf4f7024..e691e0f7003 100644 --- a/src/Bicep.Core.Samples/Files/Variables_LF/main.json +++ b/src/Bicep.Core.Samples/Files/Variables_LF/main.json @@ -155,6 +155,5 @@ "isFalse": "[not(variables('isTrue'))]", "someText": "[if(variables('isTrue'), concat('a', concat('b', 'c')), 'someText')]" }, - "resources": [], - "outputs": {} + "resources": [] } \ No newline at end of file diff --git a/src/Bicep.Core/Emit/EmitterContext.cs b/src/Bicep.Core/Emit/EmitterContext.cs index 9827ef7c206..e6358f7c4aa 100644 --- a/src/Bicep.Core/Emit/EmitterContext.cs +++ b/src/Bicep.Core/Emit/EmitterContext.cs @@ -18,7 +18,7 @@ public EmitterContext(SemanticModel.SemanticModel semanticModel) public SemanticModel.SemanticModel SemanticModel { get; } - public ImmutableArray VariablesToInline { get; } + public ImmutableHashSet VariablesToInline { get; } public ImmutableDictionary> ResourceDependencies { get; } } diff --git a/src/Bicep.Core/Emit/InlineDependencyVisitor.cs b/src/Bicep.Core/Emit/InlineDependencyVisitor.cs index 4bff905f3f3..73d966bb0d3 100644 --- a/src/Bicep.Core/Emit/InlineDependencyVisitor.cs +++ b/src/Bicep.Core/Emit/InlineDependencyVisitor.cs @@ -16,7 +16,7 @@ public class InlineDependencyVisitor : SyntaxVisitor private IDictionary shouldInlineCache; private VariableSymbol? currentDeclaration; - public static ImmutableArray GetVariablesToInline(SemanticModel.SemanticModel model) + public static ImmutableHashSet GetVariablesToInline(SemanticModel.SemanticModel model) { var visitor = new InlineDependencyVisitor(model); visitor.Visit(model.Root.Syntax); @@ -24,7 +24,7 @@ public static ImmutableArray GetVariablesToInline(SemanticModel. return visitor.shouldInlineCache .Where(kvp => kvp.Value) .Select(kvp => kvp.Key) - .ToImmutableArray(); + .ToImmutableHashSet(); } private InlineDependencyVisitor(SemanticModel.SemanticModel model) diff --git a/src/Bicep.Core/Emit/TemplateWriter.cs b/src/Bicep.Core/Emit/TemplateWriter.cs index f7d3430b2a3..9b149573174 100644 --- a/src/Bicep.Core/Emit/TemplateWriter.cs +++ b/src/Bicep.Core/Emit/TemplateWriter.cs @@ -53,27 +53,29 @@ public void Write() this.emitter.EmitProperty("contentVersion", "1.0.0.0"); - writer.WritePropertyName("parameters"); - this.EmitParameters(); - + this.EmitParametersIfPresent(); + writer.WritePropertyName("functions"); writer.WriteStartArray(); writer.WriteEndArray(); - writer.WritePropertyName("variables"); - this.EmitVariables(); + this.EmitVariablesIfPresent(); - writer.WritePropertyName("resources"); - this.EmitResources(); - - writer.WritePropertyName("outputs"); - this.EmitOutputs(); + this.EmitResources(); + + this.EmitOutputsIfPresent(); writer.WriteEndObject(); - } - - private void EmitParameters() + } + + private void EmitParametersIfPresent() { + if (this.context.SemanticModel.Root.ParameterDeclarations.Length == 0) + { + return; + } + + writer.WritePropertyName("parameters"); writer.WriteStartObject(); foreach (var parameterSymbol in this.context.SemanticModel.Root.ParameterDeclarations) @@ -132,8 +134,14 @@ private void EmitParameter(ParameterSymbol parameterSymbol) writer.WriteEndObject(); } - private void EmitVariables() + private void EmitVariablesIfPresent() { + if (!this.context.SemanticModel.Root.VariableDeclarations.Any(symbol => !this.context.VariablesToInline.Contains(symbol))) + { + return; + } + + writer.WritePropertyName("variables"); writer.WriteStartObject(); foreach (var variableSymbol in this.context.SemanticModel.Root.VariableDeclarations) @@ -155,7 +163,8 @@ private void EmitVariable(VariableSymbol variableSymbol) } private void EmitResources() - { + { + writer.WritePropertyName("resources"); writer.WriteStartArray(); foreach (var resourceSymbol in this.context.SemanticModel.Root.ResourceDeclarations) @@ -298,8 +307,14 @@ private void EmitDependsOn(DeclaredSymbol declaredSymbol) writer.WriteEndArray(); } - private void EmitOutputs() - { + private void EmitOutputsIfPresent() + { + if (this.context.SemanticModel.Root.OutputDeclarations.Length == 0) + { + return; + } + + writer.WritePropertyName("outputs"); writer.WriteStartObject(); foreach (var outputSymbol in this.context.SemanticModel.Root.OutputDeclarations)