Skip to content

Commit

Permalink
Added deployment().properties.template.contentVersion property (#5727)
Browse files Browse the repository at this point in the history
* Added deployment().properties.template.contentVersion

* Changed some name references as agreed in PR.

Co-authored-by: Stephane Lapointe <stephane.lap@outlook.com>
  • Loading branch information
slapointe and Stephane Lapointe authored Feb 3, 2022
1 parent 1026291 commit d4063da
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 8 deletions.
14 changes: 14 additions & 0 deletions src/Bicep.Core.IntegrationTests/ScenarioTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2849,6 +2849,7 @@ public void Test_Issue5456_1()
("BCP073", DiagnosticLevel.Warning, "The property \"properties\" is read-only. Expressions cannot be assigned to read-only properties. If this is an inaccuracy in the documentation, please report it to the Bicep Team.")
});
}

/// <summary>
/// https://github.com/Azure/bicep/issues/5456
/// </summary>
Expand All @@ -2868,5 +2869,18 @@ public void Test_Issue5456_2()
("BCP073", DiagnosticLevel.Error, "The property \"outputs\" is read-only. Expressions cannot be assigned to read-only properties.")
});
}

/// <summary>
/// https://github.com/Azure/bicep/issues/3114
/// </summary>
[TestMethod]
public void Test_Issue3114()
{
var result = CompilationHelper.Compile(@"
output contentVersion string = deployment().properties.template.contentVersion
");
result.Template.Should().NotBeNull();
result.Template.Should().HaveValueAtPath("$.outputs['contentVersion'].value", "[deployment().properties.template.contentVersion]");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ var invalidEnvironmentVar = environment().aosdufhsad
//@[42:52) [BCP053 (Error)] The type "environment" does not contain property "aosdufhsad". Available properties include "activeDirectoryDataLake", "authentication", "batch", "gallery", "graph", "graphAudience", "media", "name", "portal", "resourceManager", "sqlManagement", "suffixes", "vmImageAliasDoc". (CodeDescription: none) |aosdufhsad|
var invalidEnvAuthVar = environment().authentication.asdgdsag
//@[4:21) [no-unused-vars (Warning)] Variable "invalidEnvAuthVar" is declared but never used. (CodeDescription: bicep core(https://aka.ms/bicep/linter/no-unused-vars)) |invalidEnvAuthVar|
//@[53:61) [BCP053 (Error)] The type "authentication" does not contain property "asdgdsag". Available properties include "audiences", "identityProvider", "loginEndpoint", "tenant". (CodeDescription: none) |asdgdsag|
//@[53:61) [BCP053 (Error)] The type "authenticationProperties" does not contain property "asdgdsag". Available properties include "audiences", "identityProvider", "loginEndpoint", "tenant". (CodeDescription: none) |asdgdsag|

// invalid use of reserved namespace
var az = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2429,6 +2429,20 @@
"command": "editor.action.triggerParameterHints"
}
},
{
"label": "templateContentVersion",
"kind": "variable",
"detail": "templateContentVersion",
"deprecated": false,
"preselect": false,
"sortText": "2_templateContentVersion",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "templateContentVersion"
}
},
{
"label": "templateLinkId",
"kind": "variable",
Expand Down
1 change: 1 addition & 0 deletions src/Bicep.Core.Samples/Files/Variables_LF/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ var expressionIndexOnAny = any({
var anyIndexOnAny = any(true)[any(false)]

var deploymentName = deployment().name
var templateContentVersion = deployment().properties.template.contentVersion
var templateLinkUri = deployment().properties.templateLink.uri
var templateLinkId = deployment().properties.templateLink.id

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ var anyIndexOnAny = any(true)[any(false)]

var deploymentName = deployment().name
//@[4:18) [no-unused-vars (Warning)] Variable "deploymentName" is declared but never used. (CodeDescription: bicep core(https://aka.ms/bicep/linter/no-unused-vars)) |deploymentName|
var templateContentVersion = deployment().properties.template.contentVersion
//@[4:26) [no-unused-vars (Warning)] Variable "templateContentVersion" is declared but never used. (CodeDescription: bicep core(https://aka.ms/bicep/linter/no-unused-vars)) |templateContentVersion|
var templateLinkUri = deployment().properties.templateLink.uri
//@[4:19) [no-unused-vars (Warning)] Variable "templateLinkUri" is declared but never used. (CodeDescription: bicep core(https://aka.ms/bicep/linter/no-unused-vars)) |templateLinkUri|
var templateLinkId = deployment().properties.templateLink.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ var expressionIndexOnAny = any({})[az.resourceGroup().location]
var anyIndexOnAny = any(true)[any(false)]

var deploymentName = deployment().name
var templateContentVersion = deployment().properties.template.contentVersion
var templateLinkUri = deployment().properties.templateLink.uri
var templateLinkId = deployment().properties.templateLink.id

Expand Down
3 changes: 2 additions & 1 deletion src/Bicep.Core.Samples/Files/Variables_LF/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "15538951648763968076"
"templateHash": "5474777074424075084"
}
},
"parameters": {
Expand Down Expand Up @@ -138,6 +138,7 @@
"expressionIndexOnAny": "[createObject()[resourceGroup().location]]",
"anyIndexOnAny": "[true()[false()]]",
"deploymentName": "[deployment().name]",
"templateContentVersion": "[deployment().properties.template.contentVersion]",
"templateLinkUri": "[deployment().properties.templateLink.uri]",
"templateLinkId": "[deployment().properties.templateLink.id]",
"portalEndpoint": "[environment().portal]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "6079751447973968942"
"templateHash": "12480395712152468332"
}
},
"parameters": {
Expand Down Expand Up @@ -140,6 +140,7 @@
"expressionIndexOnAny": "[createObject()[resourceGroup().location]]",
"anyIndexOnAny": "[true()[false()]]",
"deploymentName": "[deployment().name]",
"templateContentVersion": "[deployment().properties.template.contentVersion]",
"templateLinkUri": "[deployment().properties.templateLink.uri]",
"templateLinkId": "[deployment().properties.templateLink.id]",
"portalEndpoint": "[environment().portal]",
Expand Down
2 changes: 2 additions & 0 deletions src/Bicep.Core.Samples/Files/Variables_LF/main.symbols.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ var anyIndexOnAny = any(true)[any(false)]

var deploymentName = deployment().name
//@[4:18) Variable deploymentName. Type: string. Declaration start char: 0, length: 38
var templateContentVersion = deployment().properties.template.contentVersion
//@[4:26) Variable templateContentVersion. Type: string. Declaration start char: 0, length: 76
var templateLinkUri = deployment().properties.templateLink.uri
//@[4:19) Variable templateLinkUri. Type: string. Declaration start char: 0, length: 62
var templateLinkId = deployment().properties.templateLink.id
Expand Down
24 changes: 24 additions & 0 deletions src/Bicep.Core.Samples/Files/Variables_LF/main.syntax.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,30 @@ var deploymentName = deployment().name
//@[34:38) IdentifierSyntax
//@[34:38) Identifier |name|
//@[38:39) NewLine |\n|
var templateContentVersion = deployment().properties.template.contentVersion
//@[0:76) VariableDeclarationSyntax
//@[0:3) Identifier |var|
//@[4:26) IdentifierSyntax
//@[4:26) Identifier |templateContentVersion|
//@[27:28) Assignment |=|
//@[29:76) PropertyAccessSyntax
//@[29:61) PropertyAccessSyntax
//@[29:52) PropertyAccessSyntax
//@[29:41) FunctionCallSyntax
//@[29:39) IdentifierSyntax
//@[29:39) Identifier |deployment|
//@[39:40) LeftParen |(|
//@[40:41) RightParen |)|
//@[41:42) Dot |.|
//@[42:52) IdentifierSyntax
//@[42:52) Identifier |properties|
//@[52:53) Dot |.|
//@[53:61) IdentifierSyntax
//@[53:61) Identifier |template|
//@[61:62) Dot |.|
//@[62:76) IdentifierSyntax
//@[62:76) Identifier |contentVersion|
//@[76:77) NewLine |\n|
var templateLinkUri = deployment().properties.templateLink.uri
//@[0:62) VariableDeclarationSyntax
//@[0:3) Identifier |var|
Expand Down
14 changes: 14 additions & 0 deletions src/Bicep.Core.Samples/Files/Variables_LF/main.tokens.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,20 @@ var deploymentName = deployment().name
//@[33:34) Dot |.|
//@[34:38) Identifier |name|
//@[38:39) NewLine |\n|
var templateContentVersion = deployment().properties.template.contentVersion
//@[0:3) Identifier |var|
//@[4:26) Identifier |templateContentVersion|
//@[27:28) Assignment |=|
//@[29:39) Identifier |deployment|
//@[39:40) LeftParen |(|
//@[40:41) RightParen |)|
//@[41:42) Dot |.|
//@[42:52) Identifier |properties|
//@[52:53) Dot |.|
//@[53:61) Identifier |template|
//@[61:62) Dot |.|
//@[62:76) Identifier |contentVersion|
//@[76:77) NewLine |\n|
var templateLinkUri = deployment().properties.templateLink.uri
//@[0:3) Identifier |var|
//@[4:19) Identifier |templateLinkUri|
Expand Down
15 changes: 10 additions & 5 deletions src/Bicep.Core/Semantics/Namespaces/AzNamespaceType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ private static ObjectType GetTenantReturnType(IBinder binder, IFileResolver file

private static ObjectType GetManagementGroupReturnType(IBinder binder, IFileResolver fileResolver, IDiagnosticWriter diagnostics, ImmutableArray<FunctionArgumentSyntax> arguments, ImmutableArray<TypeSymbol> argumentTypes)
{
var summary = new ObjectType("summary", TypeSymbolValidationFlags.Default, new[]
var summary = new ObjectType("summaryProperties", TypeSymbolValidationFlags.Default, new[]
{
new TypeProperty("id", LanguageConstants.String),
new TypeProperty("name", LanguageConstants.String),
new TypeProperty("type", LanguageConstants.String),
}, null);

var details = new ObjectType("details", TypeSymbolValidationFlags.Default, new[]
var details = new ObjectType("detailsProperties", TypeSymbolValidationFlags.Default, new[]
{
new TypeProperty("version", LanguageConstants.String),
new TypeProperty("updatedTime", LanguageConstants.String),
Expand Down Expand Up @@ -137,7 +137,7 @@ private static ObjectType GetEnvironmentReturnType()
return new ObjectType("environment", TypeSymbolValidationFlags.Default, new[]
{
new TypeProperty("activeDirectoryDataLake", LanguageConstants.String),
new TypeProperty("authentication", new ObjectType("authentication", TypeSymbolValidationFlags.Default, new []
new TypeProperty("authentication", new ObjectType("authenticationProperties", TypeSymbolValidationFlags.Default, new []
{
new TypeProperty("audiences", new TypedArrayType(LanguageConstants.String, TypeSymbolValidationFlags.Default)),
new TypeProperty("identityProvider", LanguageConstants.String),
Expand All @@ -153,7 +153,7 @@ private static ObjectType GetEnvironmentReturnType()
new TypeProperty("portal", LanguageConstants.String),
new TypeProperty("resourceManager", LanguageConstants.String),
new TypeProperty("sqlManagement", LanguageConstants.String),
new TypeProperty("suffixes", new ObjectType("suffixes", TypeSymbolValidationFlags.Default, new []
new TypeProperty("suffixes", new ObjectType("suffixesProperties", TypeSymbolValidationFlags.Default, new []
{
new TypeProperty("acrLoginServer", LanguageConstants.String),
new TypeProperty("azureDatalakeAnalyticsCatalogAndJob", LanguageConstants.String),
Expand All @@ -172,12 +172,17 @@ private static ObjectType GetDeploymentReturnType(ResourceScope targetScope)
// Note: there are other properties which could be included here, but they allow you to break out of the bicep world.
// We're going to omit them and only include what is truly necessary. If we get feature requests to expose more properties, we should discuss this further.
// Properties such as 'template', 'templateHash', 'parameters' depend on the codegen, and feel like they could be fragile.
// template.contentVersion was requested in issue #3114
IEnumerable<TypeProperty> properties = new[]
{
new TypeProperty("name", LanguageConstants.String),
new TypeProperty("properties", new ObjectType("properties", TypeSymbolValidationFlags.Default, new []
{
new TypeProperty("templateLink", new ObjectType("properties", TypeSymbolValidationFlags.Default, new []
new TypeProperty("template", new ObjectType("templateProperties", TypeSymbolValidationFlags.Default, new []
{
new TypeProperty("contentVersion", LanguageConstants.String)
}, null)),
new TypeProperty("templateLink", new ObjectType("templateLinkProperties", TypeSymbolValidationFlags.Default, new []
{
new TypeProperty("id", LanguageConstants.String),
new TypeProperty("uri", LanguageConstants.String),
Expand Down

0 comments on commit d4063da

Please sign in to comment.