Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into antmarti/parent_property
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-c-martin committed Mar 17, 2021
2 parents 54466fd + 1bd5ffc commit 709a41f
Show file tree
Hide file tree
Showing 145 changed files with 47,416 additions and 497 deletions.
13 changes: 12 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,23 @@ The Bicep solution is comprised of the following main components:
* `dotnet test`

### Updating test baselines
* Many of the bicep integration tests rely on baseline test assertion files that are checked into the repo. Code changes in some areas will require updates to the baseline assertions.
Many of the bicep integration tests rely on baseline test assertion files that are checked into the repo. Code changes in some areas will require updates to the baseline assertions.

#### Manually
* If you see a test failure with a message containing Windows and *nix copy commands, you have encountered such a test. You have the following options to fix the test:
1. Manually execute the provided command in a shell. This makes sense for a single test, but is extremely tedious otherwise.
1. Run the `SetBaseline.ps1` script at the repo root to execute the tests in `SetBaseLine` mode, which causes the baselines to be automatically updated in bulk for failing tests. You should see baseline file modifications in Git pending changes. (Make sure your Git pending changes are empty before doing so - your changes could get overwritten!).
* Inspect the baseline assertion diffs to ensure changes are expected and match the code changes you have made. (If a pull request contains changes to baseline files that can't be explained, it will not be merged.)

#### Via GitHub Action
If you have an active branch pushed to your GitHub fork, you can use the "Update Baselines" GitHub action to automatically update any broken baselines:
1. Under your fork of the repo, navigate to "Actions" -> "Update Baselines".
1. Press "Run workflow", and select your branch name under the "Use work flow from" dropdown.
1. If any baseline changes are detected, the action will create a commit with the diffs, and push it to your branch.
1. Because of [this limitation](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token), you will need to manually re-run the CI action once the commit has been made:
1. Under your fork of the repo, navigate to "Actions" -> "Build".
1. Press "Run workflow", and select your branch name under the "Use work flow from" dropdown.

### Creating new integration tests dataset
* To Add new integration tests dataset you need to:
1. Add a entry to src/Bicep.Core.Samples/DataSets.cs
Expand Down
18 changes: 11 additions & 7 deletions docs/cicd-with-bicep.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ name: bicep build and deploy

on: push

env:
# Common variables
AZURE_RESOURCE_GROUP: 'myResourceGroupName'

jobs:
bicep-build-and-deploy:
name: bicep build and deploy
Expand All @@ -28,12 +32,12 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

# Install the latest release of the bicep CLI
- name: Install bicep CLI
# Install the latest release of the bicep CLI binaries
- name: Install bicep CLI Binaries
run: |
curl -Lo bicep https://github.com/Azure/bicep/releases/latest/download/bicep-linux-x64
chmod +x ./bicep
sudo mv ./bicep /usr/local/bin/bicep
curl -Lo bicep.bin https://github.com/Azure/bicep/releases/latest/download/bicep-linux-x64
chmod +x ./bicep.bin
sudo mv ./bicep.bin /usr/local/bin/bicep
bicep --help
# Transpile bicep file into ARM template
Expand All @@ -56,7 +60,7 @@ jobs:
with:
inlineScript: |
az account show
az deployment group what-if -f ./main.json -p ./parameters.json -g my-rg
az deployment group what-if -f ./main.json -p ./parameters.json -g ${{ env.AZURE_RESOURCE_GROUP }}
# You may want a human approval in between the what-if step
# and the deploy step to evaluate output before deployment
Expand All @@ -67,7 +71,7 @@ jobs:
with:
inlineScript: |
az account show
az deployment group create -f ./main.json -g my-rg
az deployment group create -f ./main.json -g ${{ env.AZURE_RESOURCE_GROUP }}
```
Instead of installing the Bicep CLI manually, you may instead want to use the [community-maintained github action](https://github.com/marketplace/actions/bicep-build) from [@justinyoo](https://github.com/justinyoo) that can run `bicep build` on your behalf.
3 changes: 2 additions & 1 deletion docs/grammar.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ parenthesizedExpression -> "(" expression ")"
ifCondition -> "if" parenthesizedExpression object
forExpression -> "[" "for" (IDENTIFIER(item) | forVariableBlock) "in" expression ":" expression(body) "]"
forExpression -> "[" "for" (IDENTIFIER(item) | forVariableBlock) "in" expression ":" forBody "]"
forVariableBlock -> "(" IDENTIFIER(item) "," IDENTIFIER(index) ")"
forBody -> expression(body) | ifCondition
interpString -> stringLeftPiece ( expression stringMiddlePiece )* expression stringRightPiece | stringComplete
stringLeftPiece -> "'" STRINGCHAR* "${"
Expand Down
12 changes: 7 additions & 5 deletions docs/spec/loops.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Loops may be used to iterate over an array to declare multiple resources or to s

A new scope is created inside the loop body. Identifiers declared in the outer scope may be accessed inside the inner scope, but identifiers declared in the inner scope will not be added to the outer scope. [Resources](./resources.md), [variables](./variables.md), and [parameters](./parameters.md) declared at the scope of the file may be referenced within the loop body. Multiple loops may be nested inside each other.

Filtering the loop is also allowed via the `where` keyword. (See the examples below for more details.)
Filtering the loop is also allowed via the `if` keyword in the loop body. (See the examples below for more details.)

## Examples

Expand Down Expand Up @@ -127,20 +127,22 @@ resource vnet 'Microsoft.Network/virtualNetworks@2018-11-01' = {
```

### Nested loops and filtering.
The example below demonstrates a nested loop combined with filters at each loop. Filters must be expressions that evaluate to a boolean value.
The example below demonstrates a nested loop combined with a filtered resource loop. Filters must be expressions that evaluate to a boolean value.

```bicep
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: if(parent.enabled) {
name: parent.name
properties: {
children: [for child in parent.children where parent.includeChildren && child.enabled: {
children: [for child in parent.children: {
name: child.name
setting: child.settingValue
}]
}
}]
```

Filters are also supported with module loops.

### Batch size decorator
By default for-expressions used in values of module or resource declarations will be deployed concurrently in a non-deterministic order at runtime. This behavior can be changed with the `@batchSize` decorator. The decorator is allowed on resource or module declarations whose values are a for-expression. The decorator accepts one integer literal parameter with value equal or greater than 1.

Expand Down Expand Up @@ -171,7 +173,7 @@ var nsgNames = [
resource nsg 'Microsoft.Network/networkSecurityGroups@2020-06-01' = [for name in nsgNames: {
name: name
location: resourceGroup().location
location: resourceGroup().location
}]
output nsgs array = [for i in range(0, length(nsgNames)): {
Expand Down
10 changes: 5 additions & 5 deletions docs/tutorial/01-simple-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ In most cases, I want to expose the resource name and the resource location via

```
param location string = 'eastus'
param name string = 'uniquestorage001' // must be globally unique
param storageAccountName string = 'uniquestorage001' // must be globally unique
resource stg 'Microsoft.Storage/storageAccounts@2019-06-01' = {
name: name
name: storageAccountName
location: location
kind: 'Storage'
sku: {
Expand All @@ -59,7 +59,7 @@ Storage account names must be between 3 and 24 characters, so let's add those re
```bicep
@minLength(3)
@maxLength(24)
param name string = 'uniquestorage001' // must be globally unique
param storageAccountName string = 'uniquestorage001' // must be globally unique
```

## Add variables and outputs
Expand All @@ -71,12 +71,12 @@ param location string = 'eastus'
@minLength(3)
@maxLength(24)
param name string = 'uniquestorage001' // must be globally unique
param storageAccountName string = 'uniquestorage001' // must be globally unique
var storageSku = 'Standard_LRS' // declare variable and assign value
resource stg 'Microsoft.Storage/storageAccounts@2019-06-01' = {
name: name
name: storageAccountName
location: location
kind: 'Storage'
sku: {
Expand Down
8 changes: 4 additions & 4 deletions docs/tutorial/02-deploying-a-bicep-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ az deployment group create -f ./main.bicep -g my-rg
New-AzResourceGroupDeployment -TemplateFile ./main.bicep -ResourceGroupName my-rg
```

>**Note:** make sure you update the default value of the `name` parameter to be globally unique before deploying.
>**Note:** make sure you update the default value of the `storageAccountName` parameter to be globally unique before deploying.
## Deploy with parameters

Our Bicep file exposed two parameters that we can be optionally overridden (`location` and `name`) by passing new values at deployment time.
Our Bicep file exposed two parameters that we can be optionally overridden (`location` and `storageAccountName`) by passing new values at deployment time.

### Pass parameters on the command line

**Az CLI**:

```bash
az deployment group create -f ./main.bicep -g my-rg --parameters location=westus name=uniquelogstorage001
az deployment group create -f ./main.bicep -g my-rg --parameters location=westus storageAccountName=uniquelogstorage001
```

**Azure PowerShell**:

```powershell
New-AzResourceGroupDeployment -TemplateFile ./main.bicep -ResourceGroupName my-rg -location westus -name uniquelogstorage001
New-AzResourceGroupDeployment -TemplateFile ./main.bicep -ResourceGroupName my-rg -location westus -storageAccountName uniquelogstorage001
```

### Use a local parameters JSON file
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/03-using-expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var location = resourceGroup().location
output makeCapital string = toUpper('all lowercase')
```

In our `main.bicep` file, instead of forcing users to guess a unique storage account name, let's get rid of our `name` parameter and use the `uniqueString()` and `resourceGroup()` functions to calculate a unique name. We'll also use the `resourceGroup().location` property instead of hardcoding a default location.
In our `main.bicep` file, instead of forcing users to guess a unique storage account name, let's get rid of our `storageAccountName` parameter and use the `uniqueString()` and `resourceGroup()` functions to calculate a unique name. We'll also use the `resourceGroup().location` property instead of hardcoding a default location.

```bicep
param location string = resourceGroup().location
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorial/complete-bicep-files/01.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ param location string = 'eastus'

@minLength(3)
@maxLength(24)
param name string = 'uniquestorage001' // must be globally unique
param storageAccountName string = 'uniquestorage001' // must be globally unique

var storageSku = 'Standard_LRS' // declare variable and assign value

resource stg 'Microsoft.Storage/storageAccounts@2019-06-01' = {
name: name
name: storageAccountName
location: location
kind: 'Storage'
sku: {
Expand Down
6 changes: 3 additions & 3 deletions docs/tutorial/complete-bicep-files/01.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "string",
"defaultValue": "eastus"
},
"name": {
"storageAccountName": {
"type": "string",
"defaultValue": "uniquestorage001",
"maxLength": 24,
Expand All @@ -21,7 +21,7 @@
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2019-06-01",
"name": "[parameters('name')]",
"name": "[parameters('storageAccountName')]",
"location": "[parameters('location')]",
"kind": "Storage",
"sku": {
Expand All @@ -32,7 +32,7 @@
"outputs": {
"storageId": {
"type": "string",
"value": "[resourceId('Microsoft.Storage/storageAccounts', parameters('name'))]"
"value": "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
}
},
"metadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
</PackageReference>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Bicep.Cli.UnitTests/Bicep.Cli.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
</PackageReference>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.Deployments.Templates" Version="1.0.162" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="coverlet.collector" Version="3.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Loading

0 comments on commit 709a41f

Please sign in to comment.