Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loops - code generation and emit limit checks #1521

Merged
merged 6 commits into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,6 @@ FodyWeavers.xsd
# Language Server bits
bicepLanguageServer/
src/vscode-bicep/bicepLanguageServer

# user-specific launch settings for .net apps
launchSettings.json
31 changes: 7 additions & 24 deletions docs/examples/201/key-vault-secret-create/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -116,29 +116,12 @@ resource vault 'Microsoft.KeyVault/vaults@2019-09-01' = {
}
}

// workaround for missing loop support - just using the first secret for now
var firstSecretName = first(secretsObject.secrets).secretName
var firstSecretValue = first(secretsObject.secrets).secretValue

resource secret 'Microsoft.KeyVault/vaults/secrets@2019-09-01' = {
name: '${vault.name}/${firstSecretName}'
resource secrets 'Microsoft.KeyVault/vaults/secrets@2018-02-14' = [for secret in secretsObject.secrets: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be simplified to:

resource secrets 'Microsoft.KeyVault/vaults/secrets@2018-02-14' = [for secret in secretsObject.secrets: {
  name: '${vault.name}/${secret.secretName}'
  properties: {
    value: secret.secretValue
  }
}]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will take a look in the next one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a look - yeah can totally be simplified.

name: '${keyVaultName}/${secret.secretName}'
properties: {
value: firstSecretValue
}
}
/*
TODO: Replace the first secret workaround above with this once we have loops

resource[] secrets 'Microsoft.KeyVault/vaults/secrets@2018-02-14' = [
for secret in secretsObject.secrets: {
dependsOn: [
vault
]
name: '${keyVaultName}/${secret.secretName}'
properties: {
value: secret.secretValue
}
value: secret.secretValue
}
]

*/
dependsOn: [
vault
]
}]
16 changes: 8 additions & 8 deletions docs/examples/201/key-vault-secret-create/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@
}
},
"functions": [],
"variables": {
"firstSecretName": "[first(parameters('secretsObject').secrets).secretName]",
"firstSecretValue": "[first(parameters('secretsObject').secrets).secretValue]"
},
"resources": [
{
"type": "Microsoft.KeyVault/vaults",
Expand Down Expand Up @@ -128,11 +124,15 @@
}
},
{
"copy": {
"name": "secrets",
"count": "[length(parameters('secretsObject').secrets)]"
},
"type": "Microsoft.KeyVault/vaults/secrets",
"apiVersion": "2019-09-01",
"name": "[format('{0}/{1}', parameters('keyVaultName'), variables('firstSecretName'))]",
"apiVersion": "2018-02-14",
"name": "[format('{0}/{1}', parameters('keyVaultName'), parameters('secretsObject').secrets[copyIndex()].secretName)]",
"properties": {
"value": "[variables('firstSecretValue')]"
"value": "[parameters('secretsObject').secrets[copyIndex()].secretValue]"
},
"dependsOn": [
"[resourceId('Microsoft.KeyVault/vaults', parameters('keyVaultName'))]"
Expand All @@ -143,7 +143,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "11344596542059036316"
"templateHash": "3958365733885473830"
}
}
}
6 changes: 3 additions & 3 deletions docs/spec/loops.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ In the below example, we are looping over `storageAccounts` array. For each loop
// array of storage account names
param storageAccounts array

resource[] storageAccountResources 'Microsoft.Storage/storageAccounts@2019-06-01' = [for storageName in storageAccounts: {
resource storageAccountResources 'Microsoft.Storage/storageAccounts@2019-06-01' = [for storageName in storageAccounts: {
name: storageName
location: resourceGroup().location
properties: {
Expand Down Expand Up @@ -57,7 +57,7 @@ var storageConfigurations = [
}
]

resource[] storageAccountResources 'Microsoft.Storage/storageAccounts@2019-06-01' = [for (config, i) in storageConfigurations: {
resource storageAccountResources 'Microsoft.Storage/storageAccounts@2019-06-01' = [for (config, i) in storageConfigurations: {
name: storageAccountNamePrefix + config.suffix + i
location: resourceGroup().location
properties: {
Expand Down Expand Up @@ -121,7 +121,7 @@ resource vnet 'Microsoft.Network/virtualNetworks@2018-11-01' = {
The example below demonstrates a nested loop combined with filters at each loop. Filters must be expressions that evaluate to a boolean value.

```
resource[] parentResources 'Microsoft.Example/examples@2020-06-06' = [for parent in parents where parent.enabled: {
resource parentResources 'Microsoft.Example/examples@2020-06-06' = [for parent in parents where parent.enabled: {
name: parent.name
properties: {
children: [for child in parent.children where parent.includeChildren && child.enabled: {
Expand Down
9 changes: 0 additions & 9 deletions src/Bicep.Cli/Properties/launchSettings.json

This file was deleted.

8 changes: 8 additions & 0 deletions src/Bicep.Core.Samples/DataSets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public static class DataSets

public static DataSet InvalidVariables_LF => CreateDataSet();

public static DataSet Loops_LF => CreateDataSet();

public static DataSet Outputs_CRLF => CreateDataSet();

public static DataSet Parameters_CRLF => CreateDataSet();
Expand All @@ -40,6 +42,12 @@ public static class DataSets

public static DataSet Resources_CRLF => CreateDataSet();

public static DataSet ResourcesSubscription_CRLF => CreateDataSet();

public static DataSet ResourcesManagementGroup_CRLF => CreateDataSet();

public static DataSet ResourcesTenant_CRLF => CreateDataSet();

public static DataSet Unicode_LF => CreateDataSet();

public static DataSet Variables_LF => CreateDataSet();
Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Core.Samples/Files/Functions/sys.json
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@
"minimumArgumentCount": 2,
"maximumArgumentCount": 2,
"flags": "default",
"typeSignature": "(startIndex: int, count: int): array",
"typeSignature": "(startIndex: int, count: int): int[]",
"parameterTypeSignatures": [
"startIndex: int",
"count: int"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"detail": "dependsOn",
"documentation": {
"kind": "markdown",
"value": "Type: `resource | module[]` \nWrite-only property \n"
"value": "Type: `(module[] | (resource | module) | resource[])[]` \nWrite-only property \n"
},
"deprecated": false,
"preselect": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"detail": "dependsOn",
"documentation": {
"kind": "markdown",
"value": "Type: `resource | module[]` \nWrite-only property \n"
"value": "Type: `(module[] | (resource | module) | resource[])[]` \nWrite-only property \n"
},
"deprecated": false,
"preselect": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"detail": "dependsOn",
"documentation": {
"kind": "markdown",
"value": "Type: `resource | module[]` \nWrite-only property \n"
"value": "Type: `(module[] | (resource | module) | resource[])[]` \nWrite-only property \n"
},
"deprecated": false,
"preselect": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"detail": "dependsOn",
"documentation": {
"kind": "markdown",
"value": "Type: `resource | module[]` \nWrite-only property \n"
"value": "Type: `(module[] | (resource | module) | resource[])[]` \nWrite-only property \n"
},
"deprecated": false,
"preselect": false,
Expand Down
Loading