Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feature/params-key-…
Browse files Browse the repository at this point in the history
…vault-reference-1028
  • Loading branch information
miqm committed Feb 27, 2021
2 parents d6bf430 + 2eecc00 commit e744ca2
Show file tree
Hide file tree
Showing 188 changed files with 42,147 additions and 5,334 deletions.
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ az deployment group create -f ./main.json -g my-rg
* Previously all parameters had to be declared together in one `"parameters": {}` object, variables had to be declared together in one `"variables": {}` object, etc.
* Automatic dependency management in certain scenarios. Bicep will automatically add `dependsOn` in the compiled ARM Template if the symbolic name is used in another resource declaration.
* Richer validation and intellisense than what is available in the ARM Tools VS Code extension. For example, in bicep we have intellisense on GET properties (`output sample string = resource.properties.*`)
* All resource type properties that exist via Azure Resource Manager are available in bicep. Since bicep produces ARM template `.json` files there are no discrepancies of what properties and settings are available.

For more detail on taking advantage of new bicep constructs that replace an equivalent from ARM Templates, you can read the [moving from ARM => Bicep](./docs/arm2bicep.md) doc.

Expand Down Expand Up @@ -93,7 +94,7 @@ Not yet. We wanted to get the 0.1 release out quickly and get feedback while we
The language syntax and the tooling. Now is the best time to make breaking changes, so syntax feedback is very appreciated.

**Is this only for Azure?**
Bicep is a DSL focused on deploying end-to-end solutions in Azure. In practice, that usually means working with some non-Azure APIs (i.e. creating kubernetes deployments or users in a database), so we expect to provide some extensibility points. That being said, in the 0.1 release, you can only create Azure resources that are exposed through the ARM API.
Bicep is a DSL focused on deploying end-to-end solutions in Azure. In practice, that usually means working with some non-Azure APIs (i.e. creating Kubernetes deployments or users in a database), so we expect to provide some extensibility points. That being said, in the 0.1 release, you can only create Azure resources that are exposed through the ARM API.

**What happens to my existing ARM Template investments?**
One of our goals is to make the transition from ARM Templates to Bicep as easy as possible. The Bicep CLI supports a `decompile` command to generate Bicep code from an ARM template. Please see [Decompiling an ARM Template](https://github.com/Azure/bicep/blob/main/docs/decompiling.md) for usage information.
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ steps:
scanType: 'Register'
verbosity: 'Verbose'
alertWarningLevel: 'High'
failOnAlert: true
failOnAlert: false
2 changes: 1 addition & 1 deletion docs/decompiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ See [Export Template](https://aka.ms/armexport) for guidance. Use `bicep decompi


## Current Limitations
The following are temporary limiations on the `bicep decompile` command:
The following are temporary limitations on the `bicep decompile` command:
* Templates using copy loops cannot be decompiled.
* Nested templates can only be decompiled if they are using ['inner' expression evaluation scope](https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/linked-templates#expression-evaluation-scope-in-nested-templates).
28 changes: 4 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,9 @@ 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: {
name: '${vault.name}/${secret.secretName}'
properties: {
value: firstSecretValue
value: secret.secretValue
}
}
/*
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
}
}
]
*/
}]
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"
}
}
}
2 changes: 1 addition & 1 deletion docs/installing.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ bicep --help
>**Note**: The Bicep VS code extension versions older than 0.2 must be uninstalled before or after the installation of the new version. Otherwise, both extension versions will run side by side and you will see duplicated and/or inconsistent errors. Versions 0.2 or newer do not require uninstallation and will upgrade correctly.
### Installing via the Visual Studio Marketplace
* Open your brownser and navigate to https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-bicep
* Open your browser and navigate to https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-bicep
* Click "Install" which should open VS code extension installation page
* Click "Install" in VS Code.

Expand Down
2 changes: 1 addition & 1 deletion docs/spec/bicep.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ is ${blocked}'''
```

### Numbers
Number literals are formatted as integers - a list of digits optionally preceeded by a `-`. Floating point, decimal or binary formats are not currently supported.
Number literals are formatted as integers - a list of digits optionally preceded by a `-`. Floating point, decimal or binary formats are not currently supported.

#### Examples
```bicep
Expand Down
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
2 changes: 1 addition & 1 deletion docs/workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Example syntax uses.
4. Move the issue into "In review" and request reviews from the relevant team members.
5. Address comments either by amending the issue or justifying why you don't think it should be adopted.
6. If you're unable to reach a conclusion, reach out to the [Benevolant Dictator](https://github.com/marcre) to make a decision.
6. If you're unable to reach a conclusion, reach out to the [Benevolent Dictator](https://github.com/marcre) to make a decision.
7. Move your card to "Done" and start work on the PR to incorporate your proposal.

## Making spec changes
Expand Down
9 changes: 0 additions & 9 deletions src/Bicep.Cli/Properties/launchSettings.json

This file was deleted.

177 changes: 177 additions & 0 deletions src/Bicep.Core.IntegrationTests/DecoratorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Linq;
using Bicep.Core.Diagnostics;
using Bicep.Core.Semantics;
using Bicep.Core.UnitTests.Assertions;
using Bicep.Core.UnitTests.Utils;
using FluentAssertions;
using FluentAssertions.Execution;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Bicep.Core.IntegrationTests
{
[TestClass]
public class DecoratorTests
{
[TestMethod]
public void ParameterDecorator_MissingDeclaration_ExpectedParameterDeclaration()
{
var (template, diagnostics, _) = CompilationHelper.Compile(@"
@secure()
");
using (new AssertionScope())
{
template!.Should().BeNull();
diagnostics.Should().HaveDiagnostics(new[] {
("BCP147", DiagnosticLevel.Error, "Expected a parameter declaration after the decorator."),
});
}
}

[TestMethod]
public void ParameterDecorator_AttachedToOtherKindsOfDeclarations_CannotBeUsedAsDecoratorSpecificToTheDeclarations()
{
var mainUri = new Uri("file:///main.bicep");
var moduleUri = new Uri("file:///module.bicep");

var files = new Dictionary<Uri, string>
{
[mainUri] = @"
@maxLength(1)
var foo = true
@allowed([
true
])
resource vnet 'Microsoft.Network/virtualNetworks@2020-06-01' = {
location: 'westus'
name: 'myVNet'
properties:{
addressSpace: {
addressPrefixes: [
'10.0.0.0/20'
]
}
}
}
@secure()
module myModule 'module.bicep' = {
name: 'moduleb'
params: {
inputa: 'foo'
inputb: 'bar'
}
}
@minValue(2)
output bar bool = false
",
[moduleUri] = @"
param inputa string
param inputb string
",
};

var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateForFiles(files, mainUri));
var diagnosticsByFile = compilation.GetAllDiagnosticsBySyntaxTree().ToDictionary(kvp => kvp.Key.FileUri, kvp => kvp.Value);
var success = diagnosticsByFile.Values.SelectMany(x => x).All(d => d.Level != DiagnosticLevel.Error);

using (new AssertionScope())
{
diagnosticsByFile[mainUri].Should().HaveDiagnostics(new[] {
("BCP126", DiagnosticLevel.Error, "Function \"maxLength\" cannot be used as a variable decorator."),
("BCP127", DiagnosticLevel.Error, "Function \"allowed\" cannot be used as a resource decorator."),
("BCP128", DiagnosticLevel.Error, "Function \"secure\" cannot be used as a module decorator."),
("BCP129", DiagnosticLevel.Error, "Function \"minValue\" cannot be used as an output decorator."),
});
success.Should().BeFalse();
}
}

[TestMethod]
public void NonDecoratorFunction_MissingDeclaration_CannotBeUsedAsDecorator()
{
var (template, diagnostics, _) = CompilationHelper.Compile(@"
@concat()
@resourceId()
");
using (new AssertionScope())
{
template!.Should().BeNull();
diagnostics.Should().HaveDiagnostics(new[] {
("BCP152", DiagnosticLevel.Error, "Function \"concat\" cannot be used as a decorator."),
("BCP152", DiagnosticLevel.Error, "Function \"resourceId\" cannot be used as a decorator."),
});
}
}

[TestMethod]
public void NonDecoratorFunction_AttachedToDeclaration_CannotBeUsedAsDecorator()
{
var mainUri = new Uri("file:///main.bicep");
var moduleUri = new Uri("file:///module.bicep");

var files = new Dictionary<Uri, string>
{
[mainUri] = @"
@resourceId()
param foo string
@concat()
var bar = true
@environment()
resource vnet 'Microsoft.Network/virtualNetworks@2020-06-01' = {
location: 'westus'
name: 'myVNet'
properties:{
addressSpace: {
addressPrefixes: [
'10.0.0.0/20'
]
}
}
}
@union()
module myModule 'module.bicep' = {
name: 'moduleb'
params: {
inputa: 'foo'
inputb: 'bar'
}
}
@guid()
output baz bool = false
",
[moduleUri] = @"
param inputa string
param inputb string
",
};

var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateForFiles(files, mainUri));
var diagnosticsByFile = compilation.GetAllDiagnosticsBySyntaxTree().ToDictionary(kvp => kvp.Key.FileUri, kvp => kvp.Value);
var success = diagnosticsByFile.Values.SelectMany(x => x).All(d => d.Level != DiagnosticLevel.Error);

using (new AssertionScope())
{
diagnosticsByFile[mainUri].Should().HaveDiagnostics(new[] {
("BCP152", DiagnosticLevel.Error, "Function \"resourceId\" cannot be used as a decorator."),
("BCP152", DiagnosticLevel.Error, "Function \"concat\" cannot be used as a decorator."),
("BCP152", DiagnosticLevel.Error, "Function \"environment\" cannot be used as a decorator."),
("BCP152", DiagnosticLevel.Error, "Function \"union\" cannot be used as a decorator."),
("BCP152", DiagnosticLevel.Error, "Function \"guid\" cannot be used as a decorator."),
});
success.Should().BeFalse();
}
}
}
}


Loading

0 comments on commit e744ca2

Please sign in to comment.