Skip to content

Commit ea3507c

Browse files
Support using generic subscription reference (#42179)
* Support using generic subscription reference * api
1 parent 40d9913 commit ea3507c

File tree

25 files changed

+471
-155
lines changed

25 files changed

+471
-155
lines changed

sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public static partial class ResourceManagerExtensions
182182
public partial class Subscription : Azure.Provisioning.Resource<Azure.ResourceManager.Resources.SubscriptionData>
183183
{
184184
public Subscription(Azure.Provisioning.IConstruct scope, System.Guid? guid = default(System.Guid?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func<string, Azure.ResourceManager.Resources.SubscriptionData>)) { }
185-
protected override string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; }
185+
protected override string GetAzureName(Azure.Provisioning.IConstruct scope, string? resourceName) { throw null; }
186186
}
187187
public partial class Tenant : Azure.Provisioning.Resource<Azure.ResourceManager.Resources.TenantData>
188188
{

sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public static partial class ResourceManagerExtensions
182182
public partial class Subscription : Azure.Provisioning.Resource<Azure.ResourceManager.Resources.SubscriptionData>
183183
{
184184
public Subscription(Azure.Provisioning.IConstruct scope, System.Guid? guid = default(System.Guid?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func<string, Azure.ResourceManager.Resources.SubscriptionData>)) { }
185-
protected override string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; }
185+
protected override string GetAzureName(Azure.Provisioning.IConstruct scope, string? resourceName) { throw null; }
186186
}
187187
public partial class Tenant : Azure.Provisioning.Resource<Azure.ResourceManager.Resources.TenantData>
188188
{

sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceManagerExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ public static ResourceGroup GetOrAddResourceGroup(this IConstruct construct)
4444
/// <returns>The see <see cref="Subscription"/>.</returns>
4545
public static Subscription GetOrCreateSubscription(this IConstruct construct, Guid? subscriptionId = null)
4646
{
47-
return construct.Subscription ?? (subscriptionId != null ? new Subscription(construct, subscriptionId) : construct.GetSingleResource<Subscription>())!;
47+
return construct.Subscription ??
48+
(subscriptionId != null
49+
? new Subscription(construct, subscriptionId)
50+
: construct.GetSingleResource<Subscription>() ?? new Subscription(construct));
4851
}
4952
}
5053
}

sdk/provisioning/Azure.Provisioning/src/resourcemanager/Subscription.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ public Subscription(IConstruct scope, Guid? guid = default)
3737
}
3838

3939
/// <inheritdoc/>
40-
protected override string GetAzureName(IConstruct scope, string resourceName)
40+
protected override string GetAzureName(IConstruct scope, string? resourceName)
4141
{
42-
return resourceName is not null ? resourceName : Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID") ?? throw new InvalidOperationException("No environment variable named 'AZURE_SUBSCRIPTION_ID' found");
42+
return resourceName is not null
43+
? resourceName
44+
: Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID") ?? "subscription()";
4345
}
4446
}
4547
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
targetScope = 'subscription'
22

33

4-
resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = {
4+
resource resourceGroup_RKFHPNHNS 'Microsoft.Resources/resourceGroups@2023-07-01' = {
55
name: 'rg-TEST'
66
location: 'westus'
77
tags: {
@@ -11,7 +11,7 @@ resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01'
1111

1212
module rg_TEST_module './resources/rg_TEST_module/rg_TEST_module.bicep' = {
1313
name: 'rg_TEST_module'
14-
scope: resourceGroup_I6QNkoPsb
14+
scope: resourceGroup_RKFHPNHNS
1515
}
1616

17-
output appConfigurationStore_sgecYnln3_endpoint string = rg_TEST_module.outputs.appConfigurationStore_sgecYnln3_endpoint
17+
output appConfigurationStore_kRqdpAmmZ_endpoint string = rg_TEST_module.outputs.appConfigurationStore_kRqdpAmmZ_endpoint
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
resource appConfigurationStore_sgecYnln3 'Microsoft.AppConfiguration/configurationStores@2023-03-01' = {
2+
resource appConfigurationStore_kRqdpAmmZ 'Microsoft.AppConfiguration/configurationStores@2023-03-01' = {
33
name: 'store-TEST'
44
location: 'westus'
55
sku: {
@@ -9,4 +9,4 @@ resource appConfigurationStore_sgecYnln3 'Microsoft.AppConfiguration/configurati
99
}
1010
}
1111

12-
output appConfigurationStore_sgecYnln3_endpoint string = appConfigurationStore_sgecYnln3.properties.endpoint
12+
output appConfigurationStore_kRqdpAmmZ_endpoint string = appConfigurationStore_kRqdpAmmZ.properties.endpoint

sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ targetScope = 'subscription'
44
param enableSoftDelete string = 'True'
55

66

7-
resource resourceGroup_AVG5HpqPz 'Microsoft.Resources/resourceGroups@2023-07-01' = {
7+
resource resourceGroup_g8nI7jPJ2 'Microsoft.Resources/resourceGroups@2023-07-01' = {
88
name: 'rg1-TEST'
99
location: 'westus'
1010
tags: {
1111
'azd-env-name': 'TEST'
1212
}
1313
}
1414

15-
resource resourceGroup_hu2r8JaSi 'Microsoft.Resources/resourceGroups@2023-07-01' = {
15+
resource resourceGroup_azggXhH7X 'Microsoft.Resources/resourceGroups@2023-07-01' = {
1616
name: 'rg2-TEST'
1717
location: 'westus'
1818
tags: {
1919
'azd-env-name': 'TEST'
2020
}
2121
}
2222

23-
resource resourceGroup_Q4i0lpa1h 'Microsoft.Resources/resourceGroups@2023-07-01' = {
23+
resource resourceGroup_9Y3rUN36f 'Microsoft.Resources/resourceGroups@2023-07-01' = {
2424
name: 'rg3-TEST'
2525
location: 'westus'
2626
tags: {
@@ -30,7 +30,7 @@ resource resourceGroup_Q4i0lpa1h 'Microsoft.Resources/resourceGroups@2023-07-01'
3030

3131
module rg1_TEST_module './resources/rg1_TEST_module/rg1_TEST_module.bicep' = {
3232
name: 'rg1_TEST_module'
33-
scope: resourceGroup_AVG5HpqPz
33+
scope: resourceGroup_g8nI7jPJ2
3434
params: {
3535
enableSoftDelete: enableSoftDelete
3636
SERVICE_API_IDENTITY_PRINCIPAL_ID: rg3_TEST_module.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID
@@ -39,15 +39,15 @@ module rg1_TEST_module './resources/rg1_TEST_module/rg1_TEST_module.bicep' = {
3939

4040
module rg2_TEST_module './resources/rg2_TEST_module/rg2_TEST_module.bicep' = {
4141
name: 'rg2_TEST_module'
42-
scope: resourceGroup_hu2r8JaSi
42+
scope: resourceGroup_azggXhH7X
4343
params: {
4444
STORAGE_PRINCIPAL_ID: rg1_TEST_module.outputs.STORAGE_PRINCIPAL_ID
4545
}
4646
}
4747

4848
module rg3_TEST_module './resources/rg3_TEST_module/rg3_TEST_module.bicep' = {
4949
name: 'rg3_TEST_module'
50-
scope: resourceGroup_Q4i0lpa1h
50+
scope: resourceGroup_9Y3rUN36f
5151
}
5252

5353
output STORAGE_PRINCIPAL_ID string = rg1_TEST_module.outputs.STORAGE_PRINCIPAL_ID

sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST_module/rg1_TEST_module.bicep

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ param enableSoftDelete string = 'True'
66
param SERVICE_API_IDENTITY_PRINCIPAL_ID string
77

88

9-
resource appServicePlan_viooTTlOI 'Microsoft.Web/serverfarms@2021-02-01' = {
9+
resource appServicePlan_7ufAVFULu 'Microsoft.Web/serverfarms@2021-02-01' = {
1010
name: 'appServicePlan-TEST'
1111
location: 'westus'
1212
sku: {
@@ -17,12 +17,12 @@ resource appServicePlan_viooTTlOI 'Microsoft.Web/serverfarms@2021-02-01' = {
1717
}
1818
}
1919

20-
resource webSite_dOTaZfna6 'Microsoft.Web/sites@2021-02-01' = {
20+
resource webSite_7VDxFxfHl 'Microsoft.Web/sites@2021-02-01' = {
2121
name: 'frontEnd-TEST'
2222
location: 'westus'
2323
kind: 'app,linux'
2424
properties: {
25-
serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST'
25+
serverFarmId: '/subscriptions/subscription()/resourceGroups/rg1-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST'
2626
siteConfig: {
2727
linuxFxVersion: 'node|18-lts'
2828
alwaysOn: true
@@ -40,12 +40,12 @@ resource webSite_dOTaZfna6 'Microsoft.Web/sites@2021-02-01' = {
4040
}
4141
}
4242

43-
resource applicationSettingsResource_MAMFSSuFs 'Microsoft.Web/sites/config@2021-02-01' = {
44-
parent: webSite_dOTaZfna6
43+
resource applicationSettingsResource_MbDOVsFgO 'Microsoft.Web/sites/config@2021-02-01' = {
44+
parent: webSite_7VDxFxfHl
4545
name: 'appsettings'
4646
}
4747

48-
resource keyVault_BRsYQF4qT 'Microsoft.KeyVault/vaults@2023-02-01' = {
48+
resource keyVault_j1ww9730M 'Microsoft.KeyVault/vaults@2023-02-01' = {
4949
name: 'kv-TEST'
5050
location: 'westus'
5151
properties: {
@@ -59,8 +59,8 @@ resource keyVault_BRsYQF4qT 'Microsoft.KeyVault/vaults@2023-02-01' = {
5959
}
6060
}
6161

62-
resource keyVaultAddAccessPolicy_lQ2z7dHpX 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = {
63-
parent: keyVault_BRsYQF4qT
62+
resource keyVaultAddAccessPolicy_Jv1vsDkxL 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = {
63+
parent: keyVault_j1ww9730M
6464
name: 'add'
6565
properties: {
6666
accessPolicies: [
@@ -78,6 +78,6 @@ resource keyVaultAddAccessPolicy_lQ2z7dHpX 'Microsoft.KeyVault/vaults/accessPoli
7878
}
7979
}
8080

81-
output STORAGE_PRINCIPAL_ID string = webSite_dOTaZfna6.identity.principalId
82-
output LOCATION string = webSite_dOTaZfna6.location
83-
output vaultUri string = keyVault_BRsYQF4qT.properties.vaultUri
81+
output STORAGE_PRINCIPAL_ID string = webSite_7VDxFxfHl.identity.principalId
82+
output LOCATION string = webSite_7VDxFxfHl.location
83+
output vaultUri string = keyVault_j1ww9730M.properties.vaultUri

sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg2_TEST_module/rg2_TEST_module.bicep

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
param STORAGE_PRINCIPAL_ID string
33

44

5-
resource webSite_80I4ejz5T 'Microsoft.Web/sites@2021-02-01' = {
5+
resource webSite_otUunDMEJ 'Microsoft.Web/sites@2021-02-01' = {
66
name: 'frontEnd-TEST'
77
location: 'westus'
88
identity: {
99
principalId: STORAGE_PRINCIPAL_ID
1010
}
1111
kind: 'app,linux'
1212
properties: {
13-
serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST'
13+
serverFarmId: '/subscriptions/subscription()/resourceGroups/rg1-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST'
1414
siteConfig: {
1515
linuxFxVersion: 'node|18-lts'
1616
alwaysOn: true
@@ -28,7 +28,7 @@ resource webSite_80I4ejz5T 'Microsoft.Web/sites@2021-02-01' = {
2828
}
2929
}
3030

31-
resource applicationSettingsResource_eTrLWYWog 'Microsoft.Web/sites/config@2021-02-01' = {
32-
parent: webSite_80I4ejz5T
31+
resource applicationSettingsResource_ou87c8ivP 'Microsoft.Web/sites/config@2021-02-01' = {
32+
parent: webSite_otUunDMEJ
3333
name: 'appsettings'
3434
}

sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg3_TEST_module/rg3_TEST_module.bicep

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

2-
resource webSite_Y34mQ7HgU 'Microsoft.Web/sites@2021-02-01' = {
2+
resource webSite_ERn8dnbTV 'Microsoft.Web/sites@2021-02-01' = {
33
name: 'frontEnd-TEST'
44
location: 'westus'
55
kind: 'app,linux'
66
properties: {
7-
serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST'
7+
serverFarmId: '/subscriptions/subscription()/resourceGroups/rg1-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST'
88
siteConfig: {
99
linuxFxVersion: 'node|18-lts'
1010
alwaysOn: true
@@ -22,13 +22,13 @@ resource webSite_Y34mQ7HgU 'Microsoft.Web/sites@2021-02-01' = {
2222
}
2323
}
2424

25-
resource applicationSettingsResource_1XX3wQExf 'Microsoft.Web/sites/config@2021-02-01' = {
26-
parent: webSite_Y34mQ7HgU
25+
resource applicationSettingsResource_wmfJEHJsI 'Microsoft.Web/sites/config@2021-02-01' = {
26+
parent: webSite_ERn8dnbTV
2727
name: 'appsettings'
2828
}
2929

30-
resource webSiteConfigLogs_vhJa9LaNc 'Microsoft.Web/sites/config@2021-02-01' = {
31-
parent: webSite_Y34mQ7HgU
30+
resource webSiteConfigLogs_OF3i4zuus 'Microsoft.Web/sites/config@2021-02-01' = {
31+
parent: webSite_ERn8dnbTV
3232
name: 'logs'
3333
properties: {
3434
applicationLogs: {
@@ -52,4 +52,4 @@ resource webSiteConfigLogs_vhJa9LaNc 'Microsoft.Web/sites/config@2021-02-01' = {
5252
}
5353
}
5454

55-
output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_Y34mQ7HgU.identity.principalId
55+
output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_ERn8dnbTV.identity.principalId

0 commit comments

Comments
 (0)