Skip to content

Commit

Permalink
Add type definition for properties.templateLink.uri to deployments() …
Browse files Browse the repository at this point in the history
…return value (#986)
  • Loading branch information
anthony-c-martin authored Nov 23, 2020
1 parent 5b0314c commit faaa0b6
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ var rgName = resourceGroup().name

// this does not work at the resource group scope
var invalidLocationVar = deployment().location
//@[38:46) [BCP053 (Error)] The type "environment" does not contain property "location". Available properties include "name". |location|
//@[38:46) [BCP053 (Error)] The type "environment" does not contain property "location". Available properties include "name", "properties". |location|

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", "locations", "media", "name", "portal", "resourceManager", "sqlManagement", "suffixes", "vmImageAliasDoc". |aosdufhsad|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1707,6 +1707,20 @@
"newText": "take($0)"
}
},
{
"label": "templateLinkUri",
"kind": "variable",
"detail": "templateLinkUri",
"deprecated": false,
"preselect": false,
"sortText": "2_templateLinkUri",
"insertTextFormat": "plainText",
"insertTextMode": "asIs",
"textEdit": {
"range": {},
"newText": "templateLinkUri"
}
},
{
"label": "tenant",
"kind": "function",
Expand Down
2 changes: 2 additions & 0 deletions src/Bicep.Core.Samples/Files/Variables_LF/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ var expressionIndexOnAny = any({
var anyIndexOnAny = any(true)[any(false)]

var deploymentName = deployment().name
var templateLinkUri = deployment().properties.templateLink.uri

var portalEndpoint = environment().portal
var loginEndpoint = environment().authentication.loginEndpoint
var firstLocation = environment().locations[0].displayName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ var expressionIndexOnAny = any({
var anyIndexOnAny = any(true)[any(false)]

var deploymentName = deployment().name
var templateLinkUri = deployment().properties.templateLink.uri

var portalEndpoint = environment().portal
var loginEndpoint = environment().authentication.loginEndpoint
var firstLocation = environment().locations[0].displayName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ var expressionIndexOnAny = any({})[az.resourceGroup().location]
var anyIndexOnAny = any(true)[any(false)]

var deploymentName = deployment().name
var templateLinkUri = deployment().properties.templateLink.uri

var portalEndpoint = environment().portal
var loginEndpoint = environment().authentication.loginEndpoint
var firstLocation = environment().locations[0].displayName
Expand Down
1 change: 1 addition & 0 deletions src/Bicep.Core.Samples/Files/Variables_LF/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"expressionIndexOnAny": "[createObject()[resourceGroup().location]]",
"anyIndexOnAny": "[true()[false()]]",
"deploymentName": "[deployment().name]",
"templateLinkUri": "[deployment().properties.templateLink.uri]",
"portalEndpoint": "[environment().portal]",
"loginEndpoint": "[environment().authentication.loginEndpoint]",
"firstLocation": "[environment().locations[0].displayName]",
Expand Down
3 changes: 3 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 @@ -113,6 +113,9 @@ var anyIndexOnAny = any(true)[any(false)]

var deploymentName = deployment().name
//@[4:18) Variable deploymentName. Type: string. Declaration start char: 0, length: 38
var templateLinkUri = deployment().properties.templateLink.uri
//@[4:19) Variable templateLinkUri. Type: string. Declaration start char: 0, length: 62

var portalEndpoint = environment().portal
//@[4:18) Variable portalEndpoint. Type: string. Declaration start char: 0, length: 41
var loginEndpoint = environment().authentication.loginEndpoint
Expand Down
25 changes: 25 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 @@ -663,6 +663,31 @@ var deploymentName = deployment().name
//@[34:38) IdentifierSyntax
//@[34:38) Identifier |name|
//@[38:39) NewLine |\n|
var templateLinkUri = deployment().properties.templateLink.uri
//@[0:62) VariableDeclarationSyntax
//@[0:3) Identifier |var|
//@[4:19) IdentifierSyntax
//@[4:19) Identifier |templateLinkUri|
//@[20:21) Assignment |=|
//@[22:62) PropertyAccessSyntax
//@[22:58) PropertyAccessSyntax
//@[22:45) PropertyAccessSyntax
//@[22:34) FunctionCallSyntax
//@[22:32) IdentifierSyntax
//@[22:32) Identifier |deployment|
//@[32:33) LeftParen |(|
//@[33:34) RightParen |)|
//@[34:35) Dot |.|
//@[35:45) IdentifierSyntax
//@[35:45) Identifier |properties|
//@[45:46) Dot |.|
//@[46:58) IdentifierSyntax
//@[46:58) Identifier |templateLink|
//@[58:59) Dot |.|
//@[59:62) IdentifierSyntax
//@[59:62) Identifier |uri|
//@[62:64) NewLine |\n\n|

var portalEndpoint = environment().portal
//@[0:41) VariableDeclarationSyntax
//@[0:3) Identifier |var|
Expand Down
15 changes: 15 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 @@ -435,6 +435,21 @@ var deploymentName = deployment().name
//@[33:34) Dot |.|
//@[34:38) Identifier |name|
//@[38:39) NewLine |\n|
var templateLinkUri = deployment().properties.templateLink.uri
//@[0:3) Identifier |var|
//@[4:19) Identifier |templateLinkUri|
//@[20:21) Assignment |=|
//@[22:32) Identifier |deployment|
//@[32:33) LeftParen |(|
//@[33:34) RightParen |)|
//@[34:35) Dot |.|
//@[35:45) Identifier |properties|
//@[45:46) Dot |.|
//@[46:58) Identifier |templateLink|
//@[58:59) Dot |.|
//@[59:62) Identifier |uri|
//@[62:64) NewLine |\n\n|

var portalEndpoint = environment().portal
//@[0:3) Identifier |var|
//@[4:18) Identifier |portalEndpoint|
Expand Down
30 changes: 20 additions & 10 deletions src/Bicep.Core/Semantics/Namespaces/AzNamespaceSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Immutable;
using System.Linq;
using System.Text.RegularExpressions;
using Bicep.Core.Extensions;
using Bicep.Core.Syntax;
using Bicep.Core.TypeSystem;
using Bicep.Core.TypeSystem.Az;
Expand Down Expand Up @@ -98,20 +99,29 @@ private static NamedObjectType GetEnvironmentReturnType()

private static NamedObjectType GetDeploymentReturnType(ResourceScopeType targetScope)
{
if (targetScope.HasFlag(ResourceScopeType.ResourceGroupScope))
// 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.
IEnumerable<TypeProperty> properties = new []
{
// deployments in the 'resourcegroup' scope do not have the 'location' property. All other scopes do.
return new NamedObjectType("environment", TypeSymbolValidationFlags.Default, new []
new TypeProperty("name", LanguageConstants.String),
new TypeProperty("properties", new NamedObjectType("properties", TypeSymbolValidationFlags.Default, new []
{
new TypeProperty("name", LanguageConstants.String),
}, null);
}
new TypeProperty("templateLink", new NamedObjectType("properties", TypeSymbolValidationFlags.Default, new []
{
new TypeProperty("uri", LanguageConstants.String)
}, null))
}, null)),
};

return new NamedObjectType("environment", TypeSymbolValidationFlags.Default, new []
if (!targetScope.HasFlag(ResourceScopeType.ResourceGroupScope))
{
new TypeProperty("name", LanguageConstants.String),
new TypeProperty("location", LanguageConstants.String),
}, null);
// deployments in the 'resourcegroup' scope do not have the 'location' property. All other scopes do.
var locationProperty = new TypeProperty("location", LanguageConstants.String);
properties = properties.Concat(locationProperty.AsEnumerable());
}

return new NamedObjectType("environment", TypeSymbolValidationFlags.Default, properties, null);
}

private static IEnumerable<(FunctionOverload functionOverload, ResourceScopeType allowedScopes)> GetScopeFunctions()
Expand Down

0 comments on commit faaa0b6

Please sign in to comment.