Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ResourceGroup and SubscriptionId fields #1433

Merged
merged 6 commits into from Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/Bicep.Core.IntegrationTests/ScenarioTests.cs
Expand Up @@ -474,5 +474,29 @@ public void Test_Issue1402()
template.SelectToken("$.resources[?(@.name == 'subDeploy')].location")!.Should().BeNull();
}
}

[TestMethod]
public void Test_Issue1391()
{
var (template, diags, _) = CompilationHelper.Compile(
("main.bicep", @"
resource dep 'Microsoft.Resources/deployments@2020-06-01' = {
name: 'nestedDeployment'
resourceGroup: 'bicep-rg'
subscriptionId: 'abcd-efgh'
location: 'westus'
properties: {
mode: 'Incremental'
}
}
"));
template!.Should().NotBeNull();
diags.Should().BeEmpty();
using (new AssertionScope())
{
template!.SelectToken("$.resources[?(@.name == 'nestedDeployment')].subscriptionId")!.Should().DeepEqual("abcd-efgh");
template.SelectToken("$.resources[?(@.name == 'nestedDeployment')].resourceGroup")!.Should().DeepEqual("bicep-rg");
}
}
}
}
1 change: 0 additions & 1 deletion src/Bicep.Core/TypeSystem/Az/AzResourceTypeFactory.cs
Expand Up @@ -97,7 +97,6 @@ private TypeSymbol ToTypeSymbol(Azure.Bicep.Types.Concrete.TypeBase typeBase, bo
{
var resourceTypeReference = ResourceTypeReference.Parse(resourceType.Name);
var bodyType = GetTypeSymbol(resourceType.Body.Type, true);

return new ResourceType(resourceTypeReference, ToResourceScope(resourceType.ScopeType), bodyType);
}
case Azure.Bicep.Types.Concrete.UnionType unionType:
Expand Down
33 changes: 16 additions & 17 deletions src/Bicep.Core/TypeSystem/Az/AzResourceTypeProvider.cs
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using Azure.Bicep.Types.Az;
using Bicep.Core.Resources;
using Bicep.Core.Emit;

namespace Bicep.Core.TypeSystem.Az
{
Expand Down Expand Up @@ -114,33 +115,31 @@ private static ObjectType SetBicepResourceProperties(ObjectType objectType, Reso
// we can refer to a resource at any scope if it is an existing resource not being deployed by this file
var scopeReference = LanguageConstants.CreateResourceScopeReference(validParentScopes);
properties = properties.SetItem(LanguageConstants.ResourceScopePropertyName, new TypeProperty(LanguageConstants.ResourceScopePropertyName, scopeReference, scopeRequiredFlag));

return new NamedObjectType(
objectType.Name,
objectType.ValidationFlags,
ConvertToReadOnly(properties.Values),
objectType.AdditionalPropertiesType,
ConvertToReadOnly(objectType.AdditionalPropertiesFlags));
}
else
{
// TODO: remove 'dependsOn' from the type library
properties = properties.SetItem(LanguageConstants.ResourceDependsOnPropertyName, new TypeProperty(LanguageConstants.ResourceDependsOnPropertyName, LanguageConstants.ResourceRefArray, TypePropertyFlags.WriteOnly));

// we only support scope for extension resources (or resources where the scope is unknown and thus may be an extension resource)
if (validParentScopes.HasFlag(ResourceScope.Resource))
{
var scopeReference = LanguageConstants.CreateResourceScopeReference(ResourceScope.Resource);
properties = properties.SetItem(LanguageConstants.ResourceScopePropertyName, new TypeProperty(LanguageConstants.ResourceScopePropertyName, scopeReference, scopeRequiredFlag));
}

// TODO: remove 'dependsOn' from the type library
properties = properties.SetItem(LanguageConstants.ResourceDependsOnPropertyName, new TypeProperty(LanguageConstants.ResourceDependsOnPropertyName, LanguageConstants.ResourceRefArray, TypePropertyFlags.WriteOnly));

return new NamedObjectType(
objectType.Name,
objectType.ValidationFlags,
properties.Values,
objectType.AdditionalPropertiesType,
objectType.AdditionalPropertiesFlags);
}
// Deployments RP
if (StringComparer.OrdinalIgnoreCase.Equals(objectType.Name, TemplateWriter.NestedDeploymentResourceType))
{
properties = properties.SetItem("resourceGroup", new TypeProperty("resourceGroup", LanguageConstants.String));
properties = properties.SetItem("subscriptionId", new TypeProperty("subscriptionId", LanguageConstants.String));
}
return new NamedObjectType(
objectType.Name,
objectType.ValidationFlags,
isExistingResource ? ConvertToReadOnly(properties.Values) : properties.Values,
objectType.AdditionalPropertiesType,
isExistingResource ? ConvertToReadOnly(objectType.AdditionalPropertiesFlags) : objectType.AdditionalPropertiesFlags);
}

private static IEnumerable<TypeProperty> ConvertToReadOnly(IEnumerable<TypeProperty> properties)
Expand Down