From e7989a441d716eb081209e8bf39730c3c14f72f9 Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Wed, 28 Feb 2024 12:43:46 -0800 Subject: [PATCH] Use tenant function and resourceGroup().location (#42257) * Use tenant function and resourceGroup().location * PR fb * remove find infra --- .../api/Azure.Provisioning.net6.0.cs | 10 +++++- .../api/Azure.Provisioning.netstandard2.0.cs | 10 +++++- .../Azure.Provisioning/src/Configuration.cs | 18 ++++++++++ .../Azure.Provisioning/src/Construct.cs | 13 +++++++ .../Azure.Provisioning/src/IConstruct.cs | 5 +++ .../Azure.Provisioning/src/Infrastructure.cs | 8 ++--- .../Azure.Provisioning/src/ModuleConstruct.cs | 12 ------- .../Azure.Provisioning/src/Resource.cs | 28 +++++++++++++++ .../Azure.Provisioning/src/ResourceOfT.cs | 34 +++++++++++++++++-- .../src/keyvault/KeyVault.cs | 5 ++- .../ResourceManagerExtensions.cs | 2 +- .../src/sqlmanagement/SqlDatabase.cs | 3 +- .../rg1_TEST_module/rg1_TEST_module.bicep | 2 +- .../rg_TEST_module/rg_TEST_module.bicep | 8 ++--- .../rg_TEST_module/rg_TEST_module.bicep | 8 ++--- .../rg_TEST_module/rg_TEST_module.bicep | 2 +- .../rg_TEST_module/rg_TEST_module.bicep | 2 +- .../rg_TEST_module/rg_TEST_module.bicep | 2 +- .../main.bicep | 15 ++++---- .../rg_TEST_module/rg_TEST_module.bicep | 2 +- .../tests/ProvisioningTests.cs | 2 +- .../tests/TestInfrastructure.cs | 4 +-- 22 files changed, 146 insertions(+), 49 deletions(-) create mode 100644 sdk/provisioning/Azure.Provisioning/src/Configuration.cs diff --git a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs index 17e27d68c9cdc..878a7cb5a803f 100644 --- a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs +++ b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs @@ -5,9 +5,15 @@ public static partial class CdkExtensions public static T? GetSingleResourceInScope(this Azure.Provisioning.IConstruct construct) where T : Azure.Provisioning.Resource { throw null; } public static T? GetSingleResource(this Azure.Provisioning.IConstruct construct) where T : Azure.Provisioning.Resource { throw null; } } + public partial class Configuration + { + public Configuration() { } + public bool UsePromptMode { get { throw null; } set { } } + } public abstract partial class Construct : Azure.Provisioning.IConstruct { protected Construct(Azure.Provisioning.IConstruct? scope, string name, Azure.Provisioning.ConstructScope constructScope = Azure.Provisioning.ConstructScope.ResourceGroup, System.Guid? tenantId = default(System.Guid?), System.Guid? subscriptionId = default(System.Guid?), string? envName = null, Azure.Provisioning.ResourceManager.ResourceGroup? resourceGroup = null) { } + public Azure.Provisioning.Configuration? Configuration { get { throw null; } } public Azure.Provisioning.ConstructScope ConstructScope { get { throw null; } } public string EnvironmentName { get { throw null; } } public string Name { get { throw null; } } @@ -34,6 +40,7 @@ public enum ConstructScope } public partial interface IConstruct { + Azure.Provisioning.Configuration? Configuration { get; } Azure.Provisioning.ConstructScope ConstructScope { get; } string EnvironmentName { get; } string Name { get; } @@ -52,7 +59,7 @@ public partial interface IConstruct } public abstract partial class Infrastructure : Azure.Provisioning.Construct { - public Infrastructure(Azure.Provisioning.ConstructScope constructScope = Azure.Provisioning.ConstructScope.Subscription, System.Guid? tenantId = default(System.Guid?), System.Guid? subscriptionId = default(System.Guid?), string? envName = null, bool useAnonymousResourceGroup = false) : base (default(Azure.Provisioning.IConstruct), default(string), default(Azure.Provisioning.ConstructScope), default(System.Guid?), default(System.Guid?), default(string), default(Azure.Provisioning.ResourceManager.ResourceGroup)) { } + public Infrastructure(Azure.Provisioning.ConstructScope constructScope = Azure.Provisioning.ConstructScope.Subscription, System.Guid? tenantId = default(System.Guid?), System.Guid? subscriptionId = default(System.Guid?), string? envName = null, Azure.Provisioning.Configuration? configuration = null) : base (default(Azure.Provisioning.IConstruct), default(string), default(Azure.Provisioning.ConstructScope), default(System.Guid?), default(System.Guid?), default(string), default(Azure.Provisioning.ResourceManager.ResourceGroup)) { } public void Build(string? outputPath = null) { } } public partial class Output @@ -95,6 +102,7 @@ public abstract partial class Resource : Azure.Provisioning.Resource where T public T Properties { get { throw null; } } public Azure.Provisioning.Output AddOutput(System.Linq.Expressions.Expression> propertySelector, string outputName, bool isLiteral = false, bool isSecure = false) { throw null; } public void AssignParameter(System.Linq.Expressions.Expression> propertySelector, Azure.Provisioning.Parameter parameter) { } + public void AssignProperty(System.Linq.Expressions.Expression> propertySelector, string propertyValue) { } } } namespace Azure.Provisioning.AppConfiguration diff --git a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs index 17e27d68c9cdc..878a7cb5a803f 100644 --- a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs +++ b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs @@ -5,9 +5,15 @@ public static partial class CdkExtensions public static T? GetSingleResourceInScope(this Azure.Provisioning.IConstruct construct) where T : Azure.Provisioning.Resource { throw null; } public static T? GetSingleResource(this Azure.Provisioning.IConstruct construct) where T : Azure.Provisioning.Resource { throw null; } } + public partial class Configuration + { + public Configuration() { } + public bool UsePromptMode { get { throw null; } set { } } + } public abstract partial class Construct : Azure.Provisioning.IConstruct { protected Construct(Azure.Provisioning.IConstruct? scope, string name, Azure.Provisioning.ConstructScope constructScope = Azure.Provisioning.ConstructScope.ResourceGroup, System.Guid? tenantId = default(System.Guid?), System.Guid? subscriptionId = default(System.Guid?), string? envName = null, Azure.Provisioning.ResourceManager.ResourceGroup? resourceGroup = null) { } + public Azure.Provisioning.Configuration? Configuration { get { throw null; } } public Azure.Provisioning.ConstructScope ConstructScope { get { throw null; } } public string EnvironmentName { get { throw null; } } public string Name { get { throw null; } } @@ -34,6 +40,7 @@ public enum ConstructScope } public partial interface IConstruct { + Azure.Provisioning.Configuration? Configuration { get; } Azure.Provisioning.ConstructScope ConstructScope { get; } string EnvironmentName { get; } string Name { get; } @@ -52,7 +59,7 @@ public partial interface IConstruct } public abstract partial class Infrastructure : Azure.Provisioning.Construct { - public Infrastructure(Azure.Provisioning.ConstructScope constructScope = Azure.Provisioning.ConstructScope.Subscription, System.Guid? tenantId = default(System.Guid?), System.Guid? subscriptionId = default(System.Guid?), string? envName = null, bool useAnonymousResourceGroup = false) : base (default(Azure.Provisioning.IConstruct), default(string), default(Azure.Provisioning.ConstructScope), default(System.Guid?), default(System.Guid?), default(string), default(Azure.Provisioning.ResourceManager.ResourceGroup)) { } + public Infrastructure(Azure.Provisioning.ConstructScope constructScope = Azure.Provisioning.ConstructScope.Subscription, System.Guid? tenantId = default(System.Guid?), System.Guid? subscriptionId = default(System.Guid?), string? envName = null, Azure.Provisioning.Configuration? configuration = null) : base (default(Azure.Provisioning.IConstruct), default(string), default(Azure.Provisioning.ConstructScope), default(System.Guid?), default(System.Guid?), default(string), default(Azure.Provisioning.ResourceManager.ResourceGroup)) { } public void Build(string? outputPath = null) { } } public partial class Output @@ -95,6 +102,7 @@ public abstract partial class Resource : Azure.Provisioning.Resource where T public T Properties { get { throw null; } } public Azure.Provisioning.Output AddOutput(System.Linq.Expressions.Expression> propertySelector, string outputName, bool isLiteral = false, bool isSecure = false) { throw null; } public void AssignParameter(System.Linq.Expressions.Expression> propertySelector, Azure.Provisioning.Parameter parameter) { } + public void AssignProperty(System.Linq.Expressions.Expression> propertySelector, string propertyValue) { } } } namespace Azure.Provisioning.AppConfiguration diff --git a/sdk/provisioning/Azure.Provisioning/src/Configuration.cs b/sdk/provisioning/Azure.Provisioning/src/Configuration.cs new file mode 100644 index 0000000000000..88b8424e60b94 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/src/Configuration.cs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Azure.Provisioning +{ + /// + /// Configuration for the provisioning. + /// +#pragma warning disable AZC0012 // Avoid single word type names + public class Configuration +#pragma warning restore AZC0012 // Avoid single word type names + { + /// + /// Whether to use prompt mode. + /// + public bool UsePromptMode { get; set; } + } +} diff --git a/sdk/provisioning/Azure.Provisioning/src/Construct.cs b/sdk/provisioning/Azure.Provisioning/src/Construct.cs index 935a5a93531ee..fb18e353c363a 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Construct.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Construct.cs @@ -36,6 +36,19 @@ public abstract class Construct : IConstruct public Tenant Root { get; } /// public ConstructScope ConstructScope { get; } + /// + public Configuration? Configuration + { + get + { + return Scope == null ? _configuration : Scope.Configuration; + } + internal set + { + _configuration = value; + } + } + private Configuration? _configuration; /// /// Initializes a new instance of the class. diff --git a/sdk/provisioning/Azure.Provisioning/src/IConstruct.cs b/sdk/provisioning/Azure.Provisioning/src/IConstruct.cs index 1aac6f267bd77..540cd59eaec86 100644 --- a/sdk/provisioning/Azure.Provisioning/src/IConstruct.cs +++ b/sdk/provisioning/Azure.Provisioning/src/IConstruct.cs @@ -40,6 +40,11 @@ public interface IConstruct /// public Subscription? Subscription { get; } + /// + /// Gets the configuration for the construct. + /// + public Configuration? Configuration { get; } + /// /// Gets the parent of the construct. /// diff --git a/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs b/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs index c17abd6c0caaf..92cf0c8f6f9b4 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs @@ -19,15 +19,13 @@ public abstract class Infrastructure : Construct /// The tenant id to use. If not passed in will try to load from AZURE_TENANT_ID environment variable. /// The subscription id to use. If not passed, the subscription will be loaded from the deployment context. /// The environment name to use. If not passed in will try to load from AZURE_ENV_NAME environment variable. - /// Whether to use a single anonymous resource group. When deploying the resource group will need to be provided. - public Infrastructure(ConstructScope constructScope = ConstructScope.Subscription, Guid? tenantId = null, Guid? subscriptionId = null, string? envName = null, bool useAnonymousResourceGroup = false) + /// The configuration for the infrastructure. + public Infrastructure(ConstructScope constructScope = ConstructScope.Subscription, Guid? tenantId = null, Guid? subscriptionId = null, string? envName = null, Configuration? configuration = null) : base(null, "default", constructScope, tenantId, subscriptionId, envName ?? Environment.GetEnvironmentVariable("AZURE_ENV_NAME") ?? throw new Exception("No environment variable found named 'AZURE_ENV_NAME'"), resourceGroup: null) { - UseAnonymousResourceGroup = useAnonymousResourceGroup; + Configuration = configuration; } - internal bool UseAnonymousResourceGroup { get; } - /// /// Converts the infrastructure to Bicep files. /// diff --git a/sdk/provisioning/Azure.Provisioning/src/ModuleConstruct.cs b/sdk/provisioning/Azure.Provisioning/src/ModuleConstruct.cs index 791e86e143434..f740ee7a68b0c 100644 --- a/sdk/provisioning/Azure.Provisioning/src/ModuleConstruct.cs +++ b/sdk/provisioning/Azure.Provisioning/src/ModuleConstruct.cs @@ -254,18 +254,6 @@ private static void WriteLines(int depth, BinaryData data, MemoryStream stream, { start++; } - line = line.Slice(start); - int end = line.IndexOf(':'); - if (end > 0) - { - // foo: 1 - // foo: 'something.url' - string name = line.Slice(0, end).ToString(); - if (resource.ParameterOverrides.TryGetValue(name, out var value)) - { - lineToWrite = $"{new string(' ', start)}{name}: {value}"; - } - } stream.WriteLine($"{indent}{lineToWrite}"); } } diff --git a/sdk/provisioning/Azure.Provisioning/src/Resource.cs b/sdk/provisioning/Azure.Provisioning/src/Resource.cs index 1109aa31ef133..04e7bbdec2f98 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Resource.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Resource.cs @@ -13,6 +13,7 @@ using Azure.Provisioning.ResourceManager; using Azure.Provisioning.Resources; using Azure.ResourceManager; +using Azure.ResourceManager.Models; namespace Azure.Provisioning { @@ -25,6 +26,8 @@ public abstract class Resource : IPersistableModel { internal Dictionary> ParameterOverrides { get; } + private Dictionary> PropertyOverrides { get; } + private IList Dependencies { get; } internal void AddDependency(Resource resource) @@ -85,6 +88,7 @@ protected Resource(IConstruct scope, Resource? parent, string resourceName, Reso ResourceData = createProperties(azureName); Version = version; ParameterOverrides = new Dictionary>(); + PropertyOverrides = new Dictionary>(); Dependencies = new List(); ResourceType = resourceType; Id = Parent is null @@ -161,6 +165,18 @@ private protected void AssignParameter(object instance, string propertyName, Par Parameters.Add(parameter); } + private protected void AssignProperty(object instance, string propertyName, string propertyValue) + { + if (PropertyOverrides.TryGetValue(instance, out var overrides)) + { + overrides[propertyName] = propertyValue; + } + else + { + PropertyOverrides.Add(instance, new Dictionary { { propertyName, propertyValue } }); + } + } + /// /// Adds an output to the resource. /// @@ -245,6 +261,18 @@ private BinaryData SerializeModule(ModelReaderWriterOptions options) } bicepOptions.ParameterOverrides.Add(parameter.Key, dict); } + foreach (var propertyOverride in PropertyOverrides) + { + if (!bicepOptions.ParameterOverrides.TryGetValue(propertyOverride.Key, out var dict)) + { + dict = new Dictionary(); + bicepOptions.ParameterOverrides.Add(propertyOverride.Key, dict); + } + foreach (var kvp in propertyOverride.Value) + { + dict.Add(kvp.Key, kvp.Value); + } + } var data = ModelReaderWriter.Write(ResourceData, bicepOptions).ToMemory(); #if NET6_0_OR_GREATER diff --git a/sdk/provisioning/Azure.Provisioning/src/ResourceOfT.cs b/sdk/provisioning/Azure.Provisioning/src/ResourceOfT.cs index 63843e1f5a888..beaf0d16889fd 100644 --- a/sdk/provisioning/Azure.Provisioning/src/ResourceOfT.cs +++ b/sdk/provisioning/Azure.Provisioning/src/ResourceOfT.cs @@ -5,6 +5,8 @@ using System.Linq; using System.Linq.Expressions; using Azure.Core; +using Azure.Provisioning.ResourceManager; +using Azure.ResourceManager.Models; namespace Azure.Provisioning { @@ -33,10 +35,24 @@ public abstract class Resource : Resource /// The resourceType. /// The version. /// Lambda to create the ARM properties. - protected Resource(IConstruct scope, Resource? parent, string resourceName, ResourceType resourceType, string version, Func createProperties) - : base(scope, parent, resourceName, resourceType, version, (name) => createProperties(name)) + protected Resource( + IConstruct scope, + Resource? parent, + string resourceName, + ResourceType resourceType, + string version, + Func createProperties) + : base(scope, parent, resourceName, resourceType, version, name => createProperties(name)) { Properties = (T)ResourceData; + + // Resources that have a non-RG parent do not require a location value + if (scope.Configuration?.UsePromptMode == true && Parent is ResourceGroup) + { + // We can't use the lambda overload because not all of the T's will inherit from TrackedResourceData + // TODO we may need to add a protected LocationSelector property in the future if there are exceptions to the rule + AssignProperty(Properties, "Location", $"{ResourceGroup.AnonymousResourceGroupName}.location"); + } } /// @@ -51,6 +67,18 @@ public void AssignParameter(Expression> propertySelector, Param AssignParameter(instance, name, parameter); } + /// + /// + /// + /// + /// + /// + public void AssignProperty(Expression> propertySelector, string propertyValue) + { + (object instance, string name, string expression) = EvaluateLambda(propertySelector); + AssignProperty(instance, name, propertyValue); + } + /// /// Adds an output to the resource. /// @@ -113,6 +141,8 @@ private void GetBicepExpression(Expression expression, ref string result) GetBicepExpression(memberExpression.Expression, ref result); } break; + case UnaryExpression unaryExpression: + break; case MethodCallExpression methodCallExpression: break; // skip case ParameterExpression parameterExpression: diff --git a/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVault.cs b/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVault.cs index df064976fc256..4ba95b0c7f835 100644 --- a/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVault.cs +++ b/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVault.cs @@ -31,7 +31,6 @@ public KeyVault(IConstruct scope, ResourceGroup? parent = default, string name = resourceType: ResourceTypeName, location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS, properties: ArmKeyVaultModelFactory.KeyVaultProperties( - tenantId: scope.Root.Properties.TenantId!.Value, sku: new KeyVaultSku(KeyVaultSkuFamily.A, KeyVaultSkuName.Standard), accessPolicies: Environment.GetEnvironmentVariable("AZURE_PRINCIPAL_ID") is not null ? new List() { @@ -47,6 +46,10 @@ public KeyVault(IConstruct scope, ResourceGroup? parent = default, string name = enableRbacAuthorization: true))) { AddOutput(kv => kv.Properties.VaultUri, "vaultUri"); + if (scope.Root.Properties.TenantId == Guid.Empty) + { + AssignProperty(kv => kv.Properties.TenantId, "tenant()"); + } } /// diff --git a/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceManagerExtensions.cs b/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceManagerExtensions.cs index e8212e1241208..d5e0617d32621 100644 --- a/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceManagerExtensions.cs +++ b/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceManagerExtensions.cs @@ -23,7 +23,7 @@ public static ResourceGroup AddResourceGroup(this IConstruct construct) throw new InvalidOperationException("ResourceGroup already exists on the construct"); } - return new ResourceGroup(construct, name: construct is Infrastructure { UseAnonymousResourceGroup: true } ? ResourceGroup.AnonymousResourceGroupName : "rg"); + return new ResourceGroup(construct, name: construct.Configuration?.UsePromptMode == true ? ResourceGroup.AnonymousResourceGroupName : "rg"); } /// diff --git a/sdk/provisioning/Azure.Provisioning/src/sqlmanagement/SqlDatabase.cs b/sdk/provisioning/Azure.Provisioning/src/sqlmanagement/SqlDatabase.cs index d44088d6c3c73..89520de731aaf 100644 --- a/sdk/provisioning/Azure.Provisioning/src/sqlmanagement/SqlDatabase.cs +++ b/sdk/provisioning/Azure.Provisioning/src/sqlmanagement/SqlDatabase.cs @@ -26,8 +26,7 @@ public class SqlDatabase : Resource public SqlDatabase(IConstruct scope, SqlServer? parent = null, string name = "db", string version = "2022-08-01-preview", AzureLocation? location = default) : base(scope, parent, name, ResourceTypeName, version, (name) => ArmSqlModelFactory.SqlDatabaseData( name: name, - resourceType: ResourceTypeName, - location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS)) + resourceType: ResourceTypeName)) { } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST_module/rg1_TEST_module.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST_module/rg1_TEST_module.bicep index bbe77c40b1f50..3cea1347b1c42 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST_module/rg1_TEST_module.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST_module/rg1_TEST_module.bicep @@ -49,7 +49,7 @@ resource keyVault_j1ww9730M 'Microsoft.KeyVault/vaults@2023-02-01' = { name: 'kv-TEST' location: 'westus' properties: { - tenantId: '00000000-0000-0000-0000-000000000000' + tenantId: tenant() sku: { name: 'standard' family: 'A' diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST_module/rg_TEST_module.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST_module/rg_TEST_module.bicep index e6d15ef26352e..6ac855ffd0958 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST_module/rg_TEST_module.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST_module/rg_TEST_module.bicep @@ -1,6 +1,6 @@ -resource storageAccount_NHn0GuaqX 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoacct84d98ba67edc4e3' +resource storageAccount_hWQR13jUf 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoacct71d9792260684fd' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_NHn0GuaqX 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_58OA4T8kA 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_NHn0GuaqX +resource blobService_UnN8ydpj5 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_hWQR13jUf name: 'default' properties: { } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST_module/rg_TEST_module.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST_module/rg_TEST_module.bicep index 834cdaa38678a..a0ea74f4191de 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST_module/rg_TEST_module.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST_module/rg_TEST_module.bicep @@ -1,6 +1,6 @@ -resource storageAccount_hOJq7fwUJ 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoacct98d7a228f178408' +resource storageAccount_dx0zUTplq 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoacctc31a9d6584644ae' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_hOJq7fwUJ 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_c88nS1we4 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_hOJq7fwUJ +resource blobService_PYZrLaKZo 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_dx0zUTplq name: 'default' properties: { deleteRetentionPolicy: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST_module/rg_TEST_module.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST_module/rg_TEST_module.bicep index 58ecf1f8ac79c..4373889cae372 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST_module/rg_TEST_module.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST_module/rg_TEST_module.bicep @@ -75,7 +75,7 @@ resource keyVault_6DI6zrlsS 'Microsoft.KeyVault/vaults@2023-02-01' = { name: 'kv-TEST' location: 'westus' properties: { - tenantId: '00000000-0000-0000-0000-000000000000' + tenantId: tenant() sku: { name: 'standard' family: 'A' diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST_module/rg_TEST_module.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST_module/rg_TEST_module.bicep index 0130ad80b5daf..ffc5a4bf44398 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST_module/rg_TEST_module.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST_module/rg_TEST_module.bicep @@ -22,7 +22,7 @@ resource keyVault_6DI6zrlsS 'Microsoft.KeyVault/vaults@2023-02-01' = { name: 'kv-TEST' location: 'westus' properties: { - tenantId: '00000000-0000-0000-0000-000000000000' + tenantId: tenant() sku: { name: 'standard' family: 'A' diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST_module/rg_TEST_module.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST_module/rg_TEST_module.bicep index e9aed4080a1b2..3ed5ce32d85f9 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST_module/rg_TEST_module.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST_module/rg_TEST_module.bicep @@ -25,7 +25,7 @@ resource keyVault_6DI6zrlsS 'Microsoft.KeyVault/vaults@2023-02-01' = { 'key': 'value' } properties: { - tenantId: '00000000-0000-0000-0000-000000000000' + tenantId: tenant() sku: { name: 'standard' family: 'A' diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3ResourceGroupScope/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3ResourceGroupScope/main.bicep index 963de69bb5dbb..307f58507edf4 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3ResourceGroupScope/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3ResourceGroupScope/main.bicep @@ -11,7 +11,7 @@ param appUserPassword string resource appServicePlan_PxkuWnuWL 'Microsoft.Web/serverfarms@2021-02-01' = { name: 'appServicePlan-TEST' - location: 'westus' + location: resourceGroup().location sku: { name: 'B1' } @@ -22,12 +22,12 @@ resource appServicePlan_PxkuWnuWL 'Microsoft.Web/serverfarms@2021-02-01' = { resource keyVault_zomsD2kWf 'Microsoft.KeyVault/vaults@2023-02-01' = { name: 'kv-TEST' - location: 'westus' + location: resourceGroup().location tags: { 'key': 'value' } properties: { - tenantId: '00000000-0000-0000-0000-000000000000' + tenantId: tenant() sku: { name: 'standard' family: 'A' @@ -81,7 +81,7 @@ resource keyVaultSecret_YNErVycWe 'Microsoft.KeyVault/vaults/secrets@2023-02-01' resource webSite_IGuzwfciS 'Microsoft.Web/sites@2021-02-01' = { name: 'frontEnd-TEST' - location: 'westus' + location: resourceGroup().location kind: 'app,linux' properties: { serverFarmId: '/subscriptions/subscription()/resourceGroups/resourceGroup()/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' @@ -134,7 +134,7 @@ resource webSiteConfigLogs_GwVSHGFxS 'Microsoft.Web/sites/config@2021-02-01' = { resource sqlServer_2CRay8gJr 'Microsoft.Sql/servers@2022-08-01-preview' = { name: 'sqlserver-TEST' - location: 'westus' + location: resourceGroup().location properties: { administratorLogin: 'sqladmin' administratorLoginPassword: sqlAdminPassword @@ -147,7 +147,6 @@ resource sqlServer_2CRay8gJr 'Microsoft.Sql/servers@2022-08-01-preview' = { resource sqlDatabase_P8xenywiS 'Microsoft.Sql/servers/databases@2022-08-01-preview' = { parent: sqlServer_2CRay8gJr name: 'db-TEST' - location: 'westus' properties: { } } @@ -163,7 +162,7 @@ resource sqlFirewallRule_MTg5B9jZr 'Microsoft.Sql/servers/firewallRules@2020-11- resource deploymentScript_qloqQ8wU0 'Microsoft.Resources/deploymentScripts@2020-10-01' = { name: 'cliScript-TEST' - location: 'westus' + location: resourceGroup().location kind: 'AzureCLI' properties: { cleanupPreference: 'OnSuccess' @@ -213,7 +212,7 @@ SCRIPT_END resource webSite_TR8bo87ZZ 'Microsoft.Web/sites@2021-02-01' = { name: 'backEnd-TEST' - location: 'westus' + location: resourceGroup().location kind: 'app,linux' properties: { serverFarmId: '/subscriptions/subscription()/resourceGroups/resourceGroup()/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3SpecificSubscription/resources/rg_TEST_module/rg_TEST_module.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3SpecificSubscription/resources/rg_TEST_module/rg_TEST_module.bicep index 8acaae87f7e19..a6508b8c3d1b4 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3SpecificSubscription/resources/rg_TEST_module/rg_TEST_module.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3SpecificSubscription/resources/rg_TEST_module/rg_TEST_module.bicep @@ -25,7 +25,7 @@ resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' = { 'key': 'value' } properties: { - tenantId: '00000000-0000-0000-0000-000000000000' + tenantId: tenant() sku: { name: 'standard' family: 'A' diff --git a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs index e3bcbc645e5ab..8bab3611ee8a2 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs +++ b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs @@ -174,7 +174,7 @@ await ValidateBicepAsync(BinaryData.FromObjectAsJson( [Test] public async Task WebSiteUsingL3ResourceGroupScope() { - var infra = new TestInfrastructure(scope: ConstructScope.ResourceGroup, useAnonymousResourceGroup: true); + var infra = new TestInfrastructure(scope: ConstructScope.ResourceGroup, configuration: new Configuration { UsePromptMode = true }); infra.AddWebSiteWithSqlBackEnd(); infra.GetSingleResource()!.Properties.Tags.Add("key", "value"); diff --git a/sdk/provisioning/Azure.Provisioning/tests/TestInfrastructure.cs b/sdk/provisioning/Azure.Provisioning/tests/TestInfrastructure.cs index fa4d8bde5c7d2..edb4f127e9296 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/TestInfrastructure.cs +++ b/sdk/provisioning/Azure.Provisioning/tests/TestInfrastructure.cs @@ -7,8 +7,8 @@ namespace Azure.Provisioning.Tests { internal class TestInfrastructure : Infrastructure { - public TestInfrastructure(Guid? subscriptionId = null, ConstructScope scope = ConstructScope.Subscription, bool useAnonymousResourceGroup = false) - : base(scope, Guid.Empty, subscriptionId, "TEST", useAnonymousResourceGroup: useAnonymousResourceGroup) + public TestInfrastructure(Guid? subscriptionId = null, ConstructScope scope = ConstructScope.Subscription, Configuration? configuration = null) + : base(scope, Guid.Empty, subscriptionId, "TEST", configuration) { } }