Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into antmarti/external_res…
Browse files Browse the repository at this point in the history
…ources
  • Loading branch information
anthony-c-martin committed Jan 28, 2021
2 parents d7370cc + 3c12faa commit 54b749b
Show file tree
Hide file tree
Showing 144 changed files with 37,217 additions and 27,860 deletions.
71 changes: 71 additions & 0 deletions docs/examples/201/policy-definition-with-assignment/main.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
targetScope = 'subscription'

param listOfAllowedLocations array = [
'norwayeast'
'westeurope'
]

param policyEffect string {
allowed: [
'Audit'
'Deny'
]
}

resource locationPolicyDefinition 'Microsoft.Authorization/policyDefinitions@2020-09-01' = {
name: 'custom-allowed-location'
properties: {
displayName: 'Custom - allowed location for resources'
policyType: 'Custom'
description: 'Use policy to restrict where resources can be deployed'
parameters: {
allowedLocations: {
type: 'Array'
}
effect: {
type: 'String'
}
}
metadata: {
category: 'Locations'
}
policyRule: {
if: {
allOf: [
{
field: 'location'
notIn: '[parameters(\'allowedLocations\')]'
}
{
field: 'location'
notEquals: 'global'
}
{
field: 'type'
notEquals: 'Microsoft.AzureActiveDirectory/b2cDirectories'
}
]
}
then: {
effect: '[parameters(\'effect\')]'
}
}
}
}

resource locationPolicy 'Microsoft.Authorization/policyAssignments@2020-09-01' = {
name: 'Resource-location-restriction'
properties: {
policyDefinitionId: locationPolicyDefinition.id
displayName: 'Restrict location for Azure resources'
description: 'Policy will either Audit or Deny resources being deployed in other locations'
parameters: {
allowedLocations: {
value: listOfAllowedLocations
}
Effect: {
value: policyEffect
}
}
}
}
86 changes: 86 additions & 0 deletions docs/examples/201/policy-definition-with-assignment/main.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"listOfAllowedLocations": {
"type": "array",
"defaultValue": [
"norwayeast",
"westeurope"
]
},
"policyEffect": {
"type": "string",
"allowedValues": [
"Audit",
"Deny"
]
}
},
"functions": [],
"resources": [
{
"type": "Microsoft.Authorization/policyDefinitions",
"apiVersion": "2020-09-01",
"name": "custom-allowed-location",
"properties": {
"displayName": "Custom - allowed location for resources",
"policyType": "Custom",
"description": "Use policy to restrict where resources can be deployed",
"parameters": {
"allowedLocations": {
"type": "Array"
},
"effect": {
"type": "String"
}
},
"metadata": {
"category": "Locations"
},
"policyRule": {
"if": {
"allOf": [
{
"field": "location",
"notIn": "[[parameters('allowedLocations')]"
},
{
"field": "location",
"notEquals": "global"
},
{
"field": "type",
"notEquals": "Microsoft.AzureActiveDirectory/b2cDirectories"
}
]
},
"then": {
"effect": "[[parameters('effect')]"
}
}
}
},
{
"type": "Microsoft.Authorization/policyAssignments",
"apiVersion": "2020-09-01",
"name": "Resource-location-restriction",
"properties": {
"policyDefinitionId": "[subscriptionResourceId('Microsoft.Authorization/policyDefinitions', 'custom-allowed-location')]",
"displayName": "Restrict location for Azure resources",
"description": "Policy will either Audit or Deny resources being deployed in other locations",
"parameters": {
"allowedLocations": {
"value": "[parameters('listOfAllowedLocations')]"
},
"Effect": {
"value": "[parameters('policyEffect')]"
}
}
},
"dependsOn": [
"[subscriptionResourceId('Microsoft.Authorization/policyDefinitions', 'custom-allowed-location')]"
]
}
]
}
4 changes: 4 additions & 0 deletions docs/examples/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@
"filePath": "201/log-analytics-with-solutions-and-diagnostics/main.bicep",
"description": "201/log-analytics-with-solutions-and-diagnostics"
},
{
"filePath": "201/policy-definition-with-assignment/main.bicep",
"description": "201/policy-definition-with-assignment"
},
{
"filePath": "201/policy-with-initiative-definition-and-assignment/main.bicep",
"description": "201/policy-with-initiative-definition-and-assignment"
Expand Down
14 changes: 9 additions & 5 deletions docs/grammar.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ statement ->
targetScopeDecl -> "targetScope" "=" expression
parameterDecl -> "parameter" IDENTIFIER(name) IDENTIFIER(type) (parameterDefaultValue | object(modifier))? NL
parameterDecl -> decorator* "parameter" IDENTIFIER(name) IDENTIFIER(type) parameterDefaultValue? NL
parameterDefaultValue -> "=" expression
variableDecl -> "variable" IDENTIFIER(name) "=" expression NL
variableDecl -> decorator* "variable" IDENTIFIER(name) "=" expression NL
resourceDecl -> "resource" IDENTIFIER(name) interpString(type) "existing"? "=" ifCondition? object NL
resourceDecl -> decorator* "resource" IDENTIFIER(name) interpString(type) "existing"? "=" ifCondition? object NL
moduleDecl -> "module" IDENTIFIER(name) interpString(type) "=" object NL
moduleDecl -> decorator* "module" IDENTIFIER(name) interpString(type) "=" object NL
outputDecl -> "output" IDENTIFIER(name) IDENTIFIER(type) "=" expression NL
outputDecl -> decorator* "output" IDENTIFIER(name) IDENTIFIER(type) "=" expression NL
NL -> ("\n" | "\r")+
decorator -> "@" decoratorExpression NL
expression ->
binaryExpression |
binaryExpression "?" expression ":" expression
Expand Down Expand Up @@ -79,6 +81,8 @@ primaryExpression ->
object |
parenthesizedExpression
decoratorExpression -> functionCall | memberExpression "." functionCall
functionCall -> IDENTIFIER "(" argumentList? ")"
argumentList -> expression ("," expression)*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void ValidBicep_TemplateEmiterShouldProduceExpectedTemplate(DataSet dataS
[TestMethod]
public void TemplateEmitter_output_should_not_include_UTF8_BOM()
{
var syntaxTreeGrouping = SyntaxFactory.CreateFromText("");
var syntaxTreeGrouping = SyntaxTreeGroupingFactory.CreateFromText("");
var compiledFilePath = FileHelper.GetResultFilePath(this.TestContext, "main.json");

// emitting the template should be successful
Expand Down
6 changes: 3 additions & 3 deletions src/Bicep.Core.IntegrationTests/ModuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ param inputb string
};


var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxFactory.CreateForFiles(files, mainUri));
var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateForFiles(files, mainUri));

var (success, diagnosticsByFile) = GetSuccessAndDiagnosticsByFile(compilation);
diagnosticsByFile.Values.SelectMany(x => x).Should().BeEmpty();
Expand Down Expand Up @@ -102,7 +102,7 @@ param inputb string
};


var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxFactory.CreateForFiles(files, mainUri));
var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateForFiles(files, mainUri));

var (success, diagnosticsByFile) = GetSuccessAndDiagnosticsByFile(compilation);
diagnosticsByFile[mainUri].Should().HaveDiagnostics(new[] {
Expand Down Expand Up @@ -157,7 +157,7 @@ param inputb string
};


var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxFactory.CreateForFiles(files, mainUri));
var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateForFiles(files, mainUri));

var (success, diagnosticsByFile) = GetSuccessAndDiagnosticsByFile(compilation);
diagnosticsByFile[mainUri].Should().HaveDiagnostics(new[] {
Expand Down
4 changes: 2 additions & 2 deletions src/Bicep.Core.IntegrationTests/ScopeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public void Errors_are_raised_for_existing_resources_at_invalid_scopes()
"));

diags.Should().HaveDiagnostics(new[] {
("BCP124", DiagnosticLevel.Error, "Scope \"subscription\" is not valid for this resource type. Permitted scopes: \"resourceGroup\"."),
("BCP134", DiagnosticLevel.Error, "Scope \"subscription\" is not valid for this resource type. Permitted scopes: \"resourceGroup\"."),
});

// use an invalid targetScope without setting the scope property
Expand All @@ -261,7 +261,7 @@ public void Errors_are_raised_for_existing_resources_at_invalid_scopes()
"));

diags.Should().HaveDiagnostics(new[] {
("BCP124", DiagnosticLevel.Error, "Scope \"subscription\" is not valid for this resource type. Permitted scopes: \"resourceGroup\"."),
("BCP134", DiagnosticLevel.Error, "Scope \"subscription\" is not valid for this resource type. Permitted scopes: \"resourceGroup\"."),
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class CompilationTests
[TestMethod]
public void EmptyProgram_SyntaxTreeGrouping_should_be_persisted()
{
var program = SyntaxFactory.CreateFromText(DataSets.Empty.Bicep);
var program = SyntaxTreeGroupingFactory.CreateFromText(DataSets.Empty.Bicep);
var compilation = new Compilation(TestResourceTypeProvider.Create(), program);

compilation.SyntaxTreeGrouping.Should().BeSameAs(program);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void ProgramsShouldProduceExpectedDiagnostics(DataSet dataSet)
[TestMethod]
public void EndOfFileFollowingSpaceAfterParameterKeyWordShouldNotThrow()
{
var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxFactory.CreateFromText("parameter "));
var compilation = new Compilation(TestResourceTypeProvider.Create(), SyntaxTreeGroupingFactory.CreateFromText("parameter "));
compilation.GetEntrypointSemanticModel().GetParseDiagnostics();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private static SemanticModel GetSemanticModelForTest(string programText, IEnumer
{
var typeProvider = ResourceTypeProviderHelper.CreateMockTypeProvider(definedTypes);

var compilation = new Compilation(typeProvider, SyntaxFactory.CreateFromText(programText));
var compilation = new Compilation(typeProvider, SyntaxTreeGroupingFactory.CreateFromText(programText));
return compilation.GetEntrypointSemanticModel();
}

Expand Down
3 changes: 2 additions & 1 deletion src/Bicep.Core.Samples/ExamplesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ private static bool IsPermittedMissingTypeDiagnostic(Diagnostic diagnostic)
"Resource type \"microsoft.web/serverFarms@2018-11-01\" does not have types available.",
"Resource type \"Microsoft.Web/sites/config@2018-11-01\" does not have types available.",
"Resource type \"Microsoft.Web/sites/config@2020-06-01\" does not have types available.",
"Resource type \"Microsoft.Web/sites/siteextensions@2020-06-01\" does not have types available."
"Resource type \"Microsoft.Web/sites/siteextensions@2020-06-01\" does not have types available.",
"Resource type \"Microsoft.Authorization/policyDefinitions@2020-09-01\" does not have types available."
};

return permittedMissingTypeDiagnostics.Contains(diagnostic.Message);
Expand Down
44 changes: 44 additions & 0 deletions src/Bicep.Core.Samples/Files/Completions/childCompletions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[
{
"label": "empty.bicep",
"kind": "file",
"deprecated": false,
"preselect": false,
"sortText": "1_empty.bicep",
"filterText": "'ChildModules/empty.bicep'",
"insertTextFormat": "plainText",
"insertTextMode": "asIs",
"textEdit": {
"range": {},
"newText": "'ChildModules/empty.bicep'"
}
},
{
"label": "main.bicep",
"kind": "file",
"deprecated": false,
"preselect": false,
"sortText": "1_main.bicep",
"filterText": "'ChildModules/main.bicep'",
"insertTextFormat": "plainText",
"insertTextMode": "asIs",
"textEdit": {
"range": {},
"newText": "'ChildModules/main.bicep'"
}
},
{
"label": "modulea.bicep",
"kind": "file",
"deprecated": false,
"preselect": false,
"sortText": "1_modulea.bicep",
"filterText": "'ChildModules/modulea.bicep'",
"insertTextFormat": "plainText",
"insertTextMode": "asIs",
"textEdit": {
"range": {},
"newText": "'ChildModules/modulea.bicep'"
}
}
]
44 changes: 44 additions & 0 deletions src/Bicep.Core.Samples/Files/Completions/childDotCompletions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[
{
"label": "empty.bicep",
"kind": "file",
"deprecated": false,
"preselect": false,
"sortText": "1_empty.bicep",
"filterText": "'./ChildModules/empty.bicep'",
"insertTextFormat": "plainText",
"insertTextMode": "asIs",
"textEdit": {
"range": {},
"newText": "'./ChildModules/empty.bicep'"
}
},
{
"label": "main.bicep",
"kind": "file",
"deprecated": false,
"preselect": false,
"sortText": "1_main.bicep",
"filterText": "'./ChildModules/main.bicep'",
"insertTextFormat": "plainText",
"insertTextMode": "asIs",
"textEdit": {
"range": {},
"newText": "'./ChildModules/main.bicep'"
}
},
{
"label": "modulea.bicep",
"kind": "file",
"deprecated": false,
"preselect": false,
"sortText": "1_modulea.bicep",
"filterText": "'./ChildModules/modulea.bicep'",
"insertTextFormat": "plainText",
"insertTextMode": "asIs",
"textEdit": {
"range": {},
"newText": "'./ChildModules/modulea.bicep'"
}
}
]
Loading

0 comments on commit 54b749b

Please sign in to comment.