Skip to content

Commit

Permalink
Add support for JSON literal string conversion (#3510)
Browse files Browse the repository at this point in the history
* Add support for JSON literal string conversion

* Address comments

* Add test for unparseable JSON, JSON with comments

* Use TryFromJson
  • Loading branch information
anthony-c-martin authored Jul 9, 2021
1 parent 6987e17 commit 632fa2d
Show file tree
Hide file tree
Showing 32 changed files with 397 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ resource publicIP 'Microsoft.Network/publicIPAddresses@2020-06-01' = {
resource firewall 'Microsoft.Network/azureFirewalls@2020-06-01' = {
name: firewallName
location: location
zones: length(availabilityZones) == 0 ? json('null') : availabilityZones
zones: length(availabilityZones) == 0 ? null : availabilityZones
properties: {
ipConfigurations: [
{
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/101/azurefirewall-create-with-zones/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "16439774586836419118"
"templateHash": "1241648137071561964"
}
},
"parameters": {
Expand Down Expand Up @@ -85,7 +85,7 @@
"apiVersion": "2020-06-01",
"name": "[parameters('firewallName')]",
"location": "[parameters('location')]",
"zones": "[if(equals(length(parameters('availabilityZones')), 0), json('null'), parameters('availabilityZones'))]",
"zones": "[if(equals(length(parameters('availabilityZones')), 0), null(), parameters('availabilityZones'))]",
"properties": {
"ipConfigurations": [
{
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/201/private-aks-cluster/aks.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ resource aksCluster 'Microsoft.ContainerService/managedClusters@2021-02-01' = {
dockerBridgeCidr: aksClusterDockerBridgeCidr
loadBalancerSku: aksClusterLoadBalancerSku
}
aadProfile: (aadEnabled ? aadProfileConfiguration : json('null'))
aadProfile: (aadEnabled ? aadProfileConfiguration : null)
apiServerAccessProfile: {
enablePrivateCluster: aksClusterEnablePrivateCluster
}
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/201/private-aks-cluster/aks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "11819378221515304822"
"templateHash": "5882575949678654988"
}
},
"parameters": {
Expand Down Expand Up @@ -389,7 +389,7 @@
"dockerBridgeCidr": "[parameters('aksClusterDockerBridgeCidr')]",
"loadBalancerSku": "[parameters('aksClusterLoadBalancerSku')]"
},
"aadProfile": "[if(parameters('aadEnabled'), variables('aadProfileConfiguration'), json('null'))]",
"aadProfile": "[if(parameters('aadEnabled'), variables('aadProfileConfiguration'), null())]",
"apiServerAccessProfile": {
"enablePrivateCluster": "[parameters('aksClusterEnablePrivateCluster')]"
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/201/private-aks-cluster/jumpbox.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ resource virtualMachines 'Microsoft.Compute/virtualMachines@2020-12-01' = {
computerName: vmName
adminUsername: vmAdminUsername
adminPassword: vmAdminPasswordOrKey
linuxConfiguration: ((authenticationType == 'password') ? json('null') : linuxConfiguration)
linuxConfiguration: ((authenticationType == 'password') ? null : linuxConfiguration)
}
storageProfile: {
imageReference: {
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/201/private-aks-cluster/jumpbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "10939577128460965414"
"templateHash": "6673211936035085652"
}
},
"parameters": {
Expand Down Expand Up @@ -217,7 +217,7 @@
"computerName": "[parameters('vmName')]",
"adminUsername": "[parameters('vmAdminUsername')]",
"adminPassword": "[parameters('vmAdminPasswordOrKey')]",
"linuxConfiguration": "[if(equals(parameters('authenticationType'), 'password'), json('null'), variables('linuxConfiguration'))]"
"linuxConfiguration": "[if(equals(parameters('authenticationType'), 'password'), null(), variables('linuxConfiguration'))]"
},
"storageProfile": {
"copy": [
Expand Down
10 changes: 5 additions & 5 deletions docs/examples/201/private-aks-cluster/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "5568127674592377707"
"templateHash": "10839339689322770047"
}
},
"parameters": {
Expand Down Expand Up @@ -1076,7 +1076,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "10939577128460965414"
"templateHash": "6673211936035085652"
}
},
"parameters": {
Expand Down Expand Up @@ -1288,7 +1288,7 @@
"computerName": "[parameters('vmName')]",
"adminUsername": "[parameters('vmAdminUsername')]",
"adminPassword": "[parameters('vmAdminPasswordOrKey')]",
"linuxConfiguration": "[if(equals(parameters('authenticationType'), 'password'), json('null'), variables('linuxConfiguration'))]"
"linuxConfiguration": "[if(equals(parameters('authenticationType'), 'password'), null(), variables('linuxConfiguration'))]"
},
"storageProfile": {
"copy": [
Expand Down Expand Up @@ -1591,7 +1591,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "11819378221515304822"
"templateHash": "5882575949678654988"
}
},
"parameters": {
Expand Down Expand Up @@ -1975,7 +1975,7 @@
"dockerBridgeCidr": "[parameters('aksClusterDockerBridgeCidr')]",
"loadBalancerSku": "[parameters('aksClusterLoadBalancerSku')]"
},
"aadProfile": "[if(parameters('aadEnabled'), variables('aadProfileConfiguration'), json('null'))]",
"aadProfile": "[if(parameters('aadEnabled'), variables('aadProfileConfiguration'), null())]",
"apiServerAccessProfile": {
"enablePrivateCluster": "[parameters('aksClusterEnablePrivateCluster')]"
}
Expand Down
26 changes: 13 additions & 13 deletions docs/examples/201/wvd-create-hostpool/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "5336278593853148904"
"templateHash": "13154155776809438883"
}
},
"parameters": {
Expand Down Expand Up @@ -840,7 +840,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "16380997742108041127"
"templateHash": "12159192052625478905"
}
},
"parameters": {
Expand Down Expand Up @@ -1162,7 +1162,7 @@
}
],
"enableAcceleratedNetworking": "[parameters('enableAcceleratedNetworking')]",
"networkSecurityGroup": "[if(empty(parameters('networkSecurityGroupId')), json('null'), json(format('{{\"id\": \"{0}\"}}', variables('nsgId'))))]"
"networkSecurityGroup": "[if(empty(parameters('networkSecurityGroupId')), null(), json(format('{{\"id\": \"{0}\"}}', variables('nsgId'))))]"
},
"dependsOn": [
"[resourceId('Microsoft.Resources/deployments', 'NSG-linkedTemplate')]"
Expand All @@ -1185,7 +1185,7 @@
"hardwareProfile": {
"vmSize": "[parameters('rdshVmSize')]"
},
"availabilitySet": "[if(equals(parameters('availabilityOption'), 'AvailabilitySet'), variables('vmAvailabilitySetResourceId'), json('null'))]",
"availabilitySet": "[if(equals(parameters('availabilityOption'), 'AvailabilitySet'), variables('vmAvailabilitySetResourceId'), null())]",
"osProfile": {
"computerName": "[concat(parameters('rdshPrefix'), add(range(0, parameters('rdshNumberOfInstances'))[copyIndex()], parameters('vmInitialNumber')))]",
"adminUsername": "[variables('vmAdministratorUsername')]",
Expand Down Expand Up @@ -1528,7 +1528,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "3622114365539263083"
"templateHash": "3610555063404175184"
}
},
"parameters": {
Expand Down Expand Up @@ -1833,7 +1833,7 @@
}
],
"enableAcceleratedNetworking": "[parameters('enableAcceleratedNetworking')]",
"networkSecurityGroup": "[if(empty(parameters('networkSecurityGroupId')), json('null'), json(format('{{\"id\": \"{0}\"}}', variables('nsgId'))))]"
"networkSecurityGroup": "[if(empty(parameters('networkSecurityGroupId')), null(), json(format('{{\"id\": \"{0}\"}}', variables('nsgId'))))]"
},
"dependsOn": [
"[resourceId('Microsoft.Resources/deployments', 'NSG-linkedTemplate')]"
Expand All @@ -1856,7 +1856,7 @@
"hardwareProfile": {
"vmSize": "[parameters('rdshVmSize')]"
},
"availabilitySet": "[if(equals(parameters('availabilityOption'), 'AvailabilitySet'), variables('vmAvailabilitySetResourceId'), json('null'))]",
"availabilitySet": "[if(equals(parameters('availabilityOption'), 'AvailabilitySet'), variables('vmAvailabilitySetResourceId'), null())]",
"osProfile": {
"computerName": "[concat(parameters('rdshPrefix'), add(range(0, parameters('rdshNumberOfInstances'))[copyIndex()], parameters('vmInitialNumber')))]",
"adminUsername": "[variables('vmAdministratorUsername')]",
Expand Down Expand Up @@ -2201,7 +2201,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "13456880223628676085"
"templateHash": "11204922523232167930"
}
},
"parameters": {
Expand Down Expand Up @@ -2505,7 +2505,7 @@
}
],
"enableAcceleratedNetworking": "[parameters('enableAcceleratedNetworking')]",
"networkSecurityGroup": "[if(empty(parameters('networkSecurityGroupId')), json('null'), json(format('{{\"id\": \"{0}\"}}', variables('nsgId'))))]"
"networkSecurityGroup": "[if(empty(parameters('networkSecurityGroupId')), null(), json(format('{{\"id\": \"{0}\"}}', variables('nsgId'))))]"
},
"dependsOn": [
"[resourceId('Microsoft.Resources/deployments', 'NSG-linkedTemplate')]"
Expand All @@ -2528,7 +2528,7 @@
"hardwareProfile": {
"vmSize": "[parameters('rdshVmSize')]"
},
"availabilitySet": "[if(equals(parameters('availabilityOption'), 'AvailabilitySet'), variables('vmAvailabilitySetResourceId'), json('null'))]",
"availabilitySet": "[if(equals(parameters('availabilityOption'), 'AvailabilitySet'), variables('vmAvailabilitySetResourceId'), null())]",
"osProfile": {
"computerName": "[concat(parameters('rdshPrefix'), add(range(0, parameters('rdshNumberOfInstances'))[copyIndex()], parameters('vmInitialNumber')))]",
"adminUsername": "[variables('vmAdministratorUsername')]",
Expand Down Expand Up @@ -2870,7 +2870,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "3774652722909324444"
"templateHash": "1641105856964782992"
}
},
"parameters": {
Expand Down Expand Up @@ -3174,7 +3174,7 @@
}
],
"enableAcceleratedNetworking": "[parameters('enableAcceleratedNetworking')]",
"networkSecurityGroup": "[if(empty(parameters('networkSecurityGroupId')), json('null'), json(format('{{\"id\": \"{0}\"}}', variables('nsgId'))))]"
"networkSecurityGroup": "[if(empty(parameters('networkSecurityGroupId')), null(), json(format('{{\"id\": \"{0}\"}}', variables('nsgId'))))]"
},
"dependsOn": [
"[resourceId('Microsoft.Resources/deployments', 'NSG-linkedTemplate')]"
Expand All @@ -3197,7 +3197,7 @@
"hardwareProfile": {
"vmSize": "[parameters('rdshVmSize')]"
},
"availabilitySet": "[if(equals(parameters('availabilityOption'), 'AvailabilitySet'), variables('vmAvailabilitySetResourceId'), json('null'))]",
"availabilitySet": "[if(equals(parameters('availabilityOption'), 'AvailabilitySet'), variables('vmAvailabilitySetResourceId'), null())]",
"osProfile": {
"computerName": "[concat(parameters('rdshPrefix'), add(range(0, parameters('rdshNumberOfInstances'))[copyIndex()], parameters('vmInitialNumber')))]",
"adminUsername": "[variables('vmAdministratorUsername')]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ resource nic 'Microsoft.Network/networkInterfaces@2018-11-01' = [for i in range(
}
]
enableAcceleratedNetworking: enableAcceleratedNetworking
networkSecurityGroup: (empty(networkSecurityGroupId) ? json('null') : json('{"id": "${nsgId}"}'))
networkSecurityGroup: (empty(networkSecurityGroupId) ? null : json('{"id": "${nsgId}"}'))
}
dependsOn: [
NSG
Expand All @@ -182,7 +182,7 @@ resource vm 'Microsoft.Compute/virtualMachines@2018-10-01' = [for i in range(0,
hardwareProfile: {
vmSize: rdshVmSize
}
availabilitySet: ((availabilityOption == 'AvailabilitySet') ? vmAvailabilitySetResourceId : json('null'))
availabilitySet: ((availabilityOption == 'AvailabilitySet') ? vmAvailabilitySetResourceId : null)
osProfile: {
computerName: concat(rdshPrefix, (i + vmInitialNumber))
adminUsername: vmAdministratorUsername
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "13456880223628676085"
"templateHash": "11204922523232167930"
}
},
"parameters": {
Expand Down Expand Up @@ -309,7 +309,7 @@
}
],
"enableAcceleratedNetworking": "[parameters('enableAcceleratedNetworking')]",
"networkSecurityGroup": "[if(empty(parameters('networkSecurityGroupId')), json('null'), json(format('{{\"id\": \"{0}\"}}', variables('nsgId'))))]"
"networkSecurityGroup": "[if(empty(parameters('networkSecurityGroupId')), null(), json(format('{{\"id\": \"{0}\"}}', variables('nsgId'))))]"
},
"dependsOn": [
"[resourceId('Microsoft.Resources/deployments', 'NSG-linkedTemplate')]"
Expand All @@ -332,7 +332,7 @@
"hardwareProfile": {
"vmSize": "[parameters('rdshVmSize')]"
},
"availabilitySet": "[if(equals(parameters('availabilityOption'), 'AvailabilitySet'), variables('vmAvailabilitySetResourceId'), json('null'))]",
"availabilitySet": "[if(equals(parameters('availabilityOption'), 'AvailabilitySet'), variables('vmAvailabilitySetResourceId'), null())]",
"osProfile": {
"computerName": "[concat(parameters('rdshPrefix'), add(range(0, parameters('rdshNumberOfInstances'))[copyIndex()], parameters('vmInitialNumber')))]",
"adminUsername": "[variables('vmAdministratorUsername')]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ resource nic 'Microsoft.Network/networkInterfaces@2018-11-01' = [for i in range(
}
]
enableAcceleratedNetworking: enableAcceleratedNetworking
networkSecurityGroup: (empty(networkSecurityGroupId) ? json('null') : json('{"id": "${nsgId}"}'))
networkSecurityGroup: (empty(networkSecurityGroupId) ? null : json('{"id": "${nsgId}"}'))
}
dependsOn: [
NSG
Expand All @@ -199,7 +199,7 @@ resource vm 'Microsoft.Compute/virtualMachines@2018-10-01' = [for i in range(0,
hardwareProfile: {
vmSize: rdshVmSize
}
availabilitySet: ((availabilityOption == 'AvailabilitySet') ? vmAvailabilitySetResourceId : json('null'))
availabilitySet: ((availabilityOption == 'AvailabilitySet') ? vmAvailabilitySetResourceId : null)
osProfile: {
computerName: concat(rdshPrefix, (i + vmInitialNumber))
adminUsername: vmAdministratorUsername
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "16380997742108041127"
"templateHash": "12159192052625478905"
}
},
"parameters": {
Expand Down Expand Up @@ -327,7 +327,7 @@
}
],
"enableAcceleratedNetworking": "[parameters('enableAcceleratedNetworking')]",
"networkSecurityGroup": "[if(empty(parameters('networkSecurityGroupId')), json('null'), json(format('{{\"id\": \"{0}\"}}', variables('nsgId'))))]"
"networkSecurityGroup": "[if(empty(parameters('networkSecurityGroupId')), null(), json(format('{{\"id\": \"{0}\"}}', variables('nsgId'))))]"
},
"dependsOn": [
"[resourceId('Microsoft.Resources/deployments', 'NSG-linkedTemplate')]"
Expand All @@ -350,7 +350,7 @@
"hardwareProfile": {
"vmSize": "[parameters('rdshVmSize')]"
},
"availabilitySet": "[if(equals(parameters('availabilityOption'), 'AvailabilitySet'), variables('vmAvailabilitySetResourceId'), json('null'))]",
"availabilitySet": "[if(equals(parameters('availabilityOption'), 'AvailabilitySet'), variables('vmAvailabilitySetResourceId'), null())]",
"osProfile": {
"computerName": "[concat(parameters('rdshPrefix'), add(range(0, parameters('rdshNumberOfInstances'))[copyIndex()], parameters('vmInitialNumber')))]",
"adminUsername": "[variables('vmAdministratorUsername')]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ resource nic 'Microsoft.Network/networkInterfaces@2018-11-01' = [for i in range(
}
]
enableAcceleratedNetworking: enableAcceleratedNetworking
networkSecurityGroup: (empty(networkSecurityGroupId) ? json('null') : json('{"id": "${nsgId}"}'))
networkSecurityGroup: (empty(networkSecurityGroupId) ? null : json('{"id": "${nsgId}"}'))
}
dependsOn: [
NSG
Expand All @@ -182,7 +182,7 @@ resource vm 'Microsoft.Compute/virtualMachines@2018-10-01' = [for i in range(0,
hardwareProfile: {
vmSize: rdshVmSize
}
availabilitySet: ((availabilityOption == 'AvailabilitySet') ? vmAvailabilitySetResourceId : json('null'))
availabilitySet: ((availabilityOption == 'AvailabilitySet') ? vmAvailabilitySetResourceId : null)
osProfile: {
computerName: concat(rdshPrefix, (i + vmInitialNumber))
adminUsername: vmAdministratorUsername
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "3774652722909324444"
"templateHash": "1641105856964782992"
}
},
"parameters": {
Expand Down Expand Up @@ -309,7 +309,7 @@
}
],
"enableAcceleratedNetworking": "[parameters('enableAcceleratedNetworking')]",
"networkSecurityGroup": "[if(empty(parameters('networkSecurityGroupId')), json('null'), json(format('{{\"id\": \"{0}\"}}', variables('nsgId'))))]"
"networkSecurityGroup": "[if(empty(parameters('networkSecurityGroupId')), null(), json(format('{{\"id\": \"{0}\"}}', variables('nsgId'))))]"
},
"dependsOn": [
"[resourceId('Microsoft.Resources/deployments', 'NSG-linkedTemplate')]"
Expand All @@ -332,7 +332,7 @@
"hardwareProfile": {
"vmSize": "[parameters('rdshVmSize')]"
},
"availabilitySet": "[if(equals(parameters('availabilityOption'), 'AvailabilitySet'), variables('vmAvailabilitySetResourceId'), json('null'))]",
"availabilitySet": "[if(equals(parameters('availabilityOption'), 'AvailabilitySet'), variables('vmAvailabilitySetResourceId'), null())]",
"osProfile": {
"computerName": "[concat(parameters('rdshPrefix'), add(range(0, parameters('rdshNumberOfInstances'))[copyIndex()], parameters('vmInitialNumber')))]",
"adminUsername": "[variables('vmAdministratorUsername')]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ resource nic 'Microsoft.Network/networkInterfaces@2018-11-01' = [for i in range(
}
]
enableAcceleratedNetworking: enableAcceleratedNetworking
networkSecurityGroup: (empty(networkSecurityGroupId) ? json('null') : json('{"id": "${nsgId}"}'))
networkSecurityGroup: (empty(networkSecurityGroupId) ? null : json('{"id": "${nsgId}"}'))
}
dependsOn: [
NSG
Expand All @@ -183,7 +183,7 @@ resource vm 'Microsoft.Compute/virtualMachines@2018-10-01' = [for i in range(0,
hardwareProfile: {
vmSize: rdshVmSize
}
availabilitySet: ((availabilityOption == 'AvailabilitySet') ? vmAvailabilitySetResourceId : json('null'))
availabilitySet: ((availabilityOption == 'AvailabilitySet') ? vmAvailabilitySetResourceId : null)
osProfile: {
computerName: concat(rdshPrefix, (i + vmInitialNumber))
adminUsername: vmAdministratorUsername
Expand Down
Loading

0 comments on commit 632fa2d

Please sign in to comment.