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

Allow cross-subscription deployments #1165

Merged
merged 1 commit into from
Dec 16, 2020
Merged

Conversation

anthony-c-martin
Copy link
Member

Closes #1046

@@ -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')]")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this also add support for deploying to an RG in a different sub?

  scope: resourceGroup('otherSub', 'otherRg')

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - our docs don't call this out as an option, and when I last tested it, it was not supported by the engine. Has this been implemented?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sub->sub didn't work until very recently, but rg in a different sub has been around for a while I think

https://docs.microsoft.com/azure/azure-resource-manager/templates/deploy-to-subscription?tabs=azure-cli#deployment-scopes

@tfitzmac to confirm

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sub->sub didn't work until very recently, but rg in a different sub has been around for a while I think

  1. Deploying to RG in a different sub works if you're in a RG-scoped template
  2. Deploying to RG in the same sub works if you're in a subscription-scoped template
  3. Deploying to RG in a different sub doesn't work if you're in a subscription-scoped template

At least that was my experience. I can't see any examples of (3) in the docs link you shared.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging this PR, but I'll create a new PR to add support for (3) if we find it's supported in ARM

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree with @anthony-c-martin. I could only get RG in different sub to work when deploying to RG.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah gotcha. So we support 1 in bicep today?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah gotcha. So we support 1 in bicep today?

We support 1 in Bicep, and as of this PR, also support 2.

Copy link
Contributor

@stan-sz stan-sz Jan 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging this PR, but I'll create a new PR to add support for (3) if we find it's supported in ARM

This is supported: https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/deploy-to-subscription?tabs=azure-cli#scope-to-other-subscription

To deploy resources to a subscription that is different than the subscription from the operation, add a nested deployment. Set the subscriptionId property to the ID of the subscription you want to deploy to. Set the location property for the nested deployment.

and it is the first example in the #1046. I've tested it and it works.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stan-sz - with (3), I was referring specifically to:

  • Parent template is a subscription-scoped template targeting subscription A.
  • Nested template is a resourcegroup-scoped template targeting resource group X in subscription B.

Where A != B

I can't find any examples of this in our documentation, and found that it was unsupported when testing with a hand-written template.

@anthony-c-martin anthony-c-martin merged commit 37a18f7 into main Dec 16, 2020
@anthony-c-martin anthony-c-martin deleted the antmarti/allow_cross_sub branch December 16, 2020 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scope to other subscriptions
5 participants