From c9204cfb476aef5187f1ec8ee082b96060be2997 Mon Sep 17 00:00:00 2001 From: Anthony Martin Date: Tue, 15 Dec 2020 21:44:54 -0800 Subject: [PATCH] Allow cross-subscription deployments --- src/Bicep.Core.IntegrationTests/Emit/TemplateEmitterTests.cs | 1 + src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs | 2 +- src/Bicep.Core/Emit/ScopeHelper.cs | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Bicep.Core.IntegrationTests/Emit/TemplateEmitterTests.cs b/src/Bicep.Core.IntegrationTests/Emit/TemplateEmitterTests.cs index b8445adc5ff..90e92b55105 100644 --- a/src/Bicep.Core.IntegrationTests/Emit/TemplateEmitterTests.cs +++ b/src/Bicep.Core.IntegrationTests/Emit/TemplateEmitterTests.cs @@ -117,6 +117,7 @@ public void InvalidBicep_TemplateEmiterShouldNotProduceAnyTemplate(DataSet dataS [DataRow("managementGroup", "managementGroup()", "managementGroup", ExpectedMgSchema, "[reference(format('Microsoft.Resources/deployments/{0}', 'myMod'), '2019-10-01').outputs.hello.value]", "[format('Microsoft.Resources/deployments/{0}', 'myMod')]")] [DataRow("managementGroup", "subscription('abc')", "subscription", ExpectedMgSchema, "[reference(subscriptionResourceId('abc', 'Microsoft.Resources/deployments', 'myMod'), '2019-10-01').outputs.hello.value]", "[subscriptionResourceId('abc', 'Microsoft.Resources/deployments', 'myMod')]")] [DataRow("subscription", "subscription()", "subscription", ExpectedSubSchema, "[reference(subscriptionResourceId('Microsoft.Resources/deployments', 'myMod'), '2019-10-01').outputs.hello.value]", "[subscriptionResourceId('Microsoft.Resources/deployments', 'myMod')]")] + [DataRow("subscription", "subscription('abc')", "subscription", ExpectedSubSchema, "[reference(subscriptionResourceId('abc', 'Microsoft.Resources/deployments', 'myMod'), '2019-10-01').outputs.hello.value]", "[subscriptionResourceId('abc', 'Microsoft.Resources/deployments', 'myMod')]")] [DataRow("subscription", "resourceGroup('abc')", "resourceGroup", ExpectedSubSchema, "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, 'abc'), 'Microsoft.Resources/deployments', 'myMod'), '2019-10-01').outputs.hello.value]", "[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, 'abc'), 'Microsoft.Resources/deployments', 'myMod')]")] [DataRow("subscription", "tenant()", "tenant", ExpectedSubSchema, "[reference(tenantResourceId('Microsoft.Resources/deployments', 'myMod'), '2019-10-01').outputs.hello.value]", "[tenantResourceId('Microsoft.Resources/deployments', 'myMod')]")] [DataRow("resourceGroup", "resourceGroup()", "resourceGroup", ExpectedRgSchema, "[reference(extensionResourceId(resourceGroup().id, 'Microsoft.Resources/deployments', 'myMod'), '2019-10-01').outputs.hello.value]", "[extensionResourceId(resourceGroup().id, 'Microsoft.Resources/deployments', 'myMod')]")] diff --git a/src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs b/src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs index 0d99cc2de60..c1a6b9b345c 100644 --- a/src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs +++ b/src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs @@ -665,7 +665,7 @@ public ErrorDiagnostic ArgumentCountMismatch(int argumentCount, int mininumArgum DiagnosticLevel.Error, "BCP115", $"Unsupported scope for module deployment in a \"{LanguageConstants.TargetScopeTypeSubscription}\" target scope. Omit this property to inherit the current scope, or specify a valid scope. " + - $"Permissible scopes include current subscription: subscription(), named resource group in same subscription: resourceGroup(), or tenant: tenant()."); + $"Permissible scopes include current subscription: subscription(), named subscription: subscription(), named resource group in same subscription: resourceGroup(), or tenant: tenant()."); public Diagnostic InvalidModuleScopeForResourceGroup() => new Diagnostic( TextSpan, diff --git a/src/Bicep.Core/Emit/ScopeHelper.cs b/src/Bicep.Core/Emit/ScopeHelper.cs index 43cbe040ec7..0c79ab56fba 100644 --- a/src/Bicep.Core/Emit/ScopeHelper.cs +++ b/src/Bicep.Core/Emit/ScopeHelper.cs @@ -73,6 +73,10 @@ public class ScopeData case SubscriptionScopeType subscriptionScopeType when subscriptionScopeType.Arguments.Length == 0: return new ScopeData { RequestedScope = ResourceScopeType.SubscriptionScope }; + case SubscriptionScopeType subscriptionScopeType when subscriptionScopeType.Arguments.Length == 1: + return new ScopeData { + RequestedScope = ResourceScopeType.SubscriptionScope, + SubscriptionIdProperty = subscriptionScopeType.Arguments[0].Expression }; case ResourceGroupScopeType resourceGroupScopeType when resourceGroupScopeType.Arguments.Length == 1: return new ScopeData { RequestedScope = ResourceScopeType.ResourceGroupScope,