diff --git a/eng/Packages.Data.props b/eng/Packages.Data.props index 4363e72c7171b..3574e1ec110a4 100644 --- a/eng/Packages.Data.props +++ b/eng/Packages.Data.props @@ -132,6 +132,7 @@ + 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 878a7cb5a803f..64323fef1c662 100644 --- a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs +++ b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs @@ -8,7 +8,7 @@ public static partial class CdkExtensions public partial class Configuration { public Configuration() { } - public bool UsePromptMode { get { throw null; } set { } } + public bool UseInteractiveMode { get { throw null; } set { } } } public abstract partial class Construct : Azure.Provisioning.IConstruct { @@ -92,6 +92,8 @@ protected Resource(Azure.Provisioning.IConstruct scope, Azure.Provisioning.Resou public string Version { get { throw null; } } protected virtual Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; } protected virtual string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; } + protected virtual bool NeedsParent() { throw null; } + protected virtual bool NeedsScope() { throw null; } Azure.Provisioning.Resource System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } @@ -151,6 +153,36 @@ public enum WebSiteRuntime Dotnetcore = 1, } } +namespace Azure.Provisioning.Authorization +{ + public static partial class AuthorizationExtensions + { + public static Azure.Provisioning.Authorization.RoleAssignment AssignRole(this Azure.Provisioning.Resource resource, Azure.Provisioning.Authorization.RoleDefinition roleDefinition, System.Guid? principalId = default(System.Guid?)) { throw null; } + } + public partial class RoleAssignment : Azure.Provisioning.Resource + { + internal RoleAssignment() : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } + protected override bool NeedsParent() { throw null; } + protected override bool NeedsScope() { throw null; } + } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct RoleDefinition : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public RoleDefinition(string value) { throw null; } + public static Azure.Provisioning.Authorization.RoleDefinition StorageBlobDataContributor { get { throw null; } } + public static Azure.Provisioning.Authorization.RoleDefinition StorageQueueDataContributor { get { throw null; } } + public static Azure.Provisioning.Authorization.RoleDefinition StorageTableDataContributor { get { throw null; } } + public bool Equals(Azure.Provisioning.Authorization.RoleDefinition other) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override bool Equals(object? obj) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override int GetHashCode() { throw null; } + public static implicit operator Azure.Provisioning.Authorization.RoleDefinition (string value) { throw null; } + public override string ToString() { throw null; } + } +} namespace Azure.Provisioning.KeyVaults { public partial class KeyVault : Azure.Provisioning.Resource @@ -193,7 +225,7 @@ public partial class Subscription : Azure.Provisioning.Resource { public Tenant(Azure.Provisioning.IConstruct scope, System.Guid? tenantId = default(System.Guid?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } - protected override string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; } + protected override string GetAzureName(Azure.Provisioning.IConstruct scope, string? resourceName) { throw null; } } } namespace Azure.Provisioning.Resources 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 878a7cb5a803f..64323fef1c662 100644 --- a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs +++ b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs @@ -8,7 +8,7 @@ public static partial class CdkExtensions public partial class Configuration { public Configuration() { } - public bool UsePromptMode { get { throw null; } set { } } + public bool UseInteractiveMode { get { throw null; } set { } } } public abstract partial class Construct : Azure.Provisioning.IConstruct { @@ -92,6 +92,8 @@ protected Resource(Azure.Provisioning.IConstruct scope, Azure.Provisioning.Resou public string Version { get { throw null; } } protected virtual Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; } protected virtual string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; } + protected virtual bool NeedsParent() { throw null; } + protected virtual bool NeedsScope() { throw null; } Azure.Provisioning.Resource System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } @@ -151,6 +153,36 @@ public enum WebSiteRuntime Dotnetcore = 1, } } +namespace Azure.Provisioning.Authorization +{ + public static partial class AuthorizationExtensions + { + public static Azure.Provisioning.Authorization.RoleAssignment AssignRole(this Azure.Provisioning.Resource resource, Azure.Provisioning.Authorization.RoleDefinition roleDefinition, System.Guid? principalId = default(System.Guid?)) { throw null; } + } + public partial class RoleAssignment : Azure.Provisioning.Resource + { + internal RoleAssignment() : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } + protected override bool NeedsParent() { throw null; } + protected override bool NeedsScope() { throw null; } + } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct RoleDefinition : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public RoleDefinition(string value) { throw null; } + public static Azure.Provisioning.Authorization.RoleDefinition StorageBlobDataContributor { get { throw null; } } + public static Azure.Provisioning.Authorization.RoleDefinition StorageQueueDataContributor { get { throw null; } } + public static Azure.Provisioning.Authorization.RoleDefinition StorageTableDataContributor { get { throw null; } } + public bool Equals(Azure.Provisioning.Authorization.RoleDefinition other) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override bool Equals(object? obj) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override int GetHashCode() { throw null; } + public static implicit operator Azure.Provisioning.Authorization.RoleDefinition (string value) { throw null; } + public override string ToString() { throw null; } + } +} namespace Azure.Provisioning.KeyVaults { public partial class KeyVault : Azure.Provisioning.Resource @@ -193,7 +225,7 @@ public partial class Subscription : Azure.Provisioning.Resource { public Tenant(Azure.Provisioning.IConstruct scope, System.Guid? tenantId = default(System.Guid?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } - protected override string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; } + protected override string GetAzureName(Azure.Provisioning.IConstruct scope, string? resourceName) { throw null; } } } namespace Azure.Provisioning.Resources diff --git a/sdk/provisioning/Azure.Provisioning/src/Azure.Provisioning.csproj b/sdk/provisioning/Azure.Provisioning/src/Azure.Provisioning.csproj index b8aaee0356391..9c227d3cfb0a9 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Azure.Provisioning.csproj +++ b/sdk/provisioning/Azure.Provisioning/src/Azure.Provisioning.csproj @@ -16,6 +16,7 @@ + diff --git a/sdk/provisioning/Azure.Provisioning/src/Configuration.cs b/sdk/provisioning/Azure.Provisioning/src/Configuration.cs index 88b8424e60b94..7fbaaabeaeca8 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Configuration.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Configuration.cs @@ -13,6 +13,6 @@ public class Configuration /// /// Whether to use prompt mode. /// - public bool UsePromptMode { get; set; } + public bool UseInteractiveMode { get; set; } } } diff --git a/sdk/provisioning/Azure.Provisioning/src/Extensions.cs b/sdk/provisioning/Azure.Provisioning/src/Extensions.cs index a3f18032ceeab..29769756e3d5f 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Extensions.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Extensions.cs @@ -4,6 +4,7 @@ using System; using System.IO; using System.Text; +using Azure.Provisioning.Authorization; using Azure.Provisioning.ResourceManager; using Azure.Provisioning.Resources; @@ -20,12 +21,6 @@ public static string ToCamelCase(this string str) #endif } - public static bool IsChildResource(this Resource resource) - { - //TODO: this is a bit of a hack. We should probably have a better way to determine if a resource is a child resource - return resource is DeploymentScript || (resource.Parent is not null && resource.Parent is not ResourceGroup && resource.Parent is not Subscription); - } - public static void Write(this MemoryStream stream, string value) { var bytes = Encoding.UTF8.GetBytes(value); diff --git a/sdk/provisioning/Azure.Provisioning/src/Parameter.cs b/sdk/provisioning/Azure.Provisioning/src/Parameter.cs index b940ad3065255..56d126010743f 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Parameter.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Parameter.cs @@ -86,7 +86,7 @@ public Parameter(string name, string? description = default, object? defaultValu /// The parameter defaultValue. /// Is the parameter secure. /// Is the parameter an expression. - internal Parameter(string name, string? description = default, object? defaultValue = default, bool isSecure = false, bool isExpression = false) + internal Parameter(string name, string? description, object? defaultValue = default, bool isSecure = false, bool isExpression = false) : this (name, description, defaultValue, isSecure) { IsExpression = isExpression; diff --git a/sdk/provisioning/Azure.Provisioning/src/Resource.cs b/sdk/provisioning/Azure.Provisioning/src/Resource.cs index 6cd183bb4d3eb..0cf18028d4ca8 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Resource.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Resource.cs @@ -10,9 +10,11 @@ using System.Security.Cryptography; using System.Text; using Azure.Core; +using Azure.Provisioning.Authorization; using Azure.Provisioning.ResourceManager; using Azure.Provisioning.Resources; using Azure.ResourceManager; +using Azure.ResourceManager.Authorization.Models; using Azure.ResourceManager.Models; namespace Azure.Provisioning @@ -246,7 +248,7 @@ private BinaryData SerializeModule(ModelReaderWriterOptions options) stream.WriteLine($"resource {Name} '{ResourceType}@{Version}' = {{"); - if (this.IsChildResource() && this is not DeploymentScript && this is not Subscription) + if (NeedsParent()) { stream.WriteLine($" parent: {Parent!.Name}"); } @@ -298,7 +300,20 @@ private BinaryData SerializeModule(ModelReaderWriterOptions options) return new BinaryData(stream.GetBuffer().AsMemory(0, (int)stream.Position)); } - private bool NeedsScope() + /// + /// Determines whether the resource needs a parent declaration. + /// + /// Whether the resource needs a parent. + protected virtual bool NeedsParent() + { + return this is not Subscription && Parent is not null && Parent is not (ResourceGroup or Subscription); + } + + /// + /// Determines whether the resource needs a scope declaration. + /// + /// Whether the resource needs a scope. + protected virtual bool NeedsScope() { Debug.Assert(ModuleScope != null, "ModuleScope should not be null"); diff --git a/sdk/provisioning/Azure.Provisioning/src/ResourceOfT.cs b/sdk/provisioning/Azure.Provisioning/src/ResourceOfT.cs index b67fd4e92f0bc..6fdafca7901a5 100644 --- a/sdk/provisioning/Azure.Provisioning/src/ResourceOfT.cs +++ b/sdk/provisioning/Azure.Provisioning/src/ResourceOfT.cs @@ -47,11 +47,11 @@ protected Resource( Properties = (T)ResourceData; // Resources that have a non-RG parent do not require a location value - if (scope.Configuration?.UsePromptMode == true && Parent is ResourceGroup) + if (scope.Configuration?.UseInteractiveMode == 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 - AssignParameter(Properties, "Location", new Parameter("location", defaultValue: $"{ResourceGroup.AnonymousResourceGroupName}.location", isExpression: true)); + AssignParameter(Properties, "Location", new Parameter("location", null, defaultValue: $"{ResourceGroup.AnonymousResourceGroupName}.location", isExpression: true)); } } diff --git a/sdk/provisioning/Azure.Provisioning/src/authorization/AuthorizationExtensions.cs b/sdk/provisioning/Azure.Provisioning/src/authorization/AuthorizationExtensions.cs new file mode 100644 index 0000000000000..b6e481343adb5 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/src/authorization/AuthorizationExtensions.cs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; + +namespace Azure.Provisioning.Authorization +{ + /// + /// Extension methods for authorization. + /// + public static class AuthorizationExtensions + { + /// + /// Assigns a role to the resource. + /// + /// The resource. + /// The role definition. + /// The principal ID. + public static RoleAssignment AssignRole(this Resource resource, RoleDefinition roleDefinition, Guid? principalId = default) + { + return new RoleAssignment(resource, roleDefinition, principalId); + } + } +} diff --git a/sdk/provisioning/Azure.Provisioning/src/authorization/RoleAssignment.cs b/sdk/provisioning/Azure.Provisioning/src/authorization/RoleAssignment.cs new file mode 100644 index 0000000000000..5408fb1fc20f9 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/src/authorization/RoleAssignment.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Azure.Core; +using Azure.ResourceManager.Authorization; +using Azure.ResourceManager.Authorization.Models; + +namespace Azure.Provisioning.Authorization +{ + /// + /// Role assignment resource. + /// + public class RoleAssignment : Resource + { + private static readonly ResourceType ResourceType = "Microsoft.Resources/roleAssignments"; + private static readonly ResourceType RoleDefinitionResourceType = "Microsoft.Authorization/roleDefinitions"; + + private const string SubscriptionResourceIdFunction = "subscriptionResourceId"; + + internal RoleAssignment( + Resource resource, + RoleDefinition roleDefinition, + Guid? principalId = default) + : base( + resource.Scope, + resource, + resource.Name, + ResourceType, + "2022-04-01", + (name) => ArmAuthorizationModelFactory.RoleAssignmentData( + name: name, + principalId: principalId)) + { + if (resource.Scope.Configuration?.UseInteractiveMode != true && principalId == null) + { + throw new InvalidOperationException("PrincipalId must be specified when not in interactive mode."); + } + + if (principalId == null) + { + AssignParameter(data => data.PrincipalId, new Parameter("principalId")); + } + + AssignProperty( + data => data.Name, + $"guid('{resource.Name}', {(principalId == null ? "principalId" : "'" + principalId + "'")}," + + $" {SubscriptionResourceIdFunction}({(resource.Scope.Configuration?.UseInteractiveMode != true ? "'" + Id.SubscriptionId + "', ": string.Empty)}" + + $"'{RoleDefinitionResourceType}', '{roleDefinition}'))"); + + AssignProperty( + data => data.RoleDefinitionId, + $"{SubscriptionResourceIdFunction}({(resource.Scope.Configuration?.UseInteractiveMode != true ? "'"+ Id.SubscriptionId + "', ": string.Empty)}" + + $"'{RoleDefinitionResourceType}', '{roleDefinition}')"); + } + + /// + protected override bool NeedsScope() => true; + + /// + protected override bool NeedsParent() => false; + } +} diff --git a/sdk/provisioning/Azure.Provisioning/src/authorization/RoleDefinition.cs b/sdk/provisioning/Azure.Provisioning/src/authorization/RoleDefinition.cs new file mode 100644 index 0000000000000..d12b51ceb443d --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/src/authorization/RoleDefinition.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.ComponentModel; + +namespace Azure.Provisioning.Authorization +{ + /// Role definition. + public readonly partial struct RoleDefinition : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public RoleDefinition(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + /// + /// Storage blob data contributor role. + /// + public static RoleDefinition StorageBlobDataContributor { get; } = new RoleDefinition("ba92f5b4-2d11-453d-a403-e96b0029c9fe"); + + /// + /// Storage queue data contributor role. + /// + public static RoleDefinition StorageQueueDataContributor { get; } = new RoleDefinition("974c5e8b-45b9-4653-ba55-5f855dd0fb88"); + + /// + /// Storage table data contributor role. + /// + public static RoleDefinition StorageTableDataContributor { get; } = new RoleDefinition("0a9a7e1f-b9d0-4cc4-a60d-0319b160aaa3"); + + /// Converts a string to a . + public static implicit operator RoleDefinition(string value) => new RoleDefinition(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object? obj) => obj is RoleDefinition other && Equals(other); + /// + public bool Equals(RoleDefinition other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceGroup.cs b/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceGroup.cs index 1c83014c082ad..e3393797027af 100644 --- a/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceGroup.cs +++ b/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceGroup.cs @@ -48,7 +48,7 @@ public ResourceGroup(IConstruct scope, string? name = "rg", string version = "20 /// protected override string GetAzureName(IConstruct scope, string resourceName) { - return resourceName == AnonymousResourceGroupName ? resourceName : base.GetAzureName(scope, resourceName); + return scope.Configuration?.UseInteractiveMode == true ? AnonymousResourceGroupName : base.GetAzureName(scope, resourceName); } } } diff --git a/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceManagerExtensions.cs b/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceManagerExtensions.cs index d5e0617d32621..e024febfc28ff 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.Configuration?.UsePromptMode == true ? ResourceGroup.AnonymousResourceGroupName : "rg"); + return new ResourceGroup(construct, name: "rg"); } /// diff --git a/sdk/provisioning/Azure.Provisioning/src/resourcemanager/Subscription.cs b/sdk/provisioning/Azure.Provisioning/src/resourcemanager/Subscription.cs index ed41bd9e9b372..d6a3d306108a9 100644 --- a/sdk/provisioning/Azure.Provisioning/src/resourcemanager/Subscription.cs +++ b/sdk/provisioning/Azure.Provisioning/src/resourcemanager/Subscription.cs @@ -39,7 +39,11 @@ public Subscription(IConstruct scope, Guid? guid = default) /// protected override string GetAzureName(IConstruct scope, string? resourceName) { - return resourceName ?? "subscription()"; + if (scope.Configuration?.UseInteractiveMode == true) + { + return "subscription()"; + } + return resourceName ?? Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID") ?? throw new InvalidOperationException("No environment variable named 'AZURE_SUBSCRIPTION_ID' found"); } } } diff --git a/sdk/provisioning/Azure.Provisioning/src/resourcemanager/Tenant.cs b/sdk/provisioning/Azure.Provisioning/src/resourcemanager/Tenant.cs index 35658a0754908..b7bfe43717cba 100644 --- a/sdk/provisioning/Azure.Provisioning/src/resourcemanager/Tenant.cs +++ b/sdk/provisioning/Azure.Provisioning/src/resourcemanager/Tenant.cs @@ -28,9 +28,13 @@ public Tenant(IConstruct scope, Guid? tenantId = null) } /// - protected override string GetAzureName(IConstruct scope, string resourceName) + protected override string GetAzureName(IConstruct scope, string? resourceName) { - return resourceName is not null ? resourceName : Environment.GetEnvironmentVariable("AZURE_TENANT_ID") ?? throw new InvalidOperationException("No environment variable named 'AZURE_TENANT_ID' found"); + if (scope.Configuration?.UseInteractiveMode == true) + { + return "tenant()"; + } + return resourceName ?? Environment.GetEnvironmentVariable("AZURE_TENANT_ID") ?? throw new InvalidOperationException("No environment variable named 'AZURE_TENANT_ID' found"); } } } diff --git a/sdk/provisioning/Azure.Provisioning/src/storage/StorageAccount.cs b/sdk/provisioning/Azure.Provisioning/src/storage/StorageAccount.cs index 4c89e4b8240ab..696e1caaaecdc 100644 --- a/sdk/provisioning/Azure.Provisioning/src/storage/StorageAccount.cs +++ b/sdk/provisioning/Azure.Provisioning/src/storage/StorageAccount.cs @@ -33,10 +33,7 @@ public StorageAccount(IConstruct scope, StorageKind kind, StorageSkuName sku, Re sku: new StorageSku(sku), kind: StorageKind.StorageV2)) { - if (scope.Configuration?.UsePromptMode == true) - { - AssignProperty(data => data.Name, $"toLower(take(concat('{name}', uniqueString(resourceGroup().id)), 24))"); - } + AssignProperty(data => data.Name, GetAzureName(scope, name)); } /// @@ -53,27 +50,7 @@ public StorageAccount(IConstruct scope, StorageKind kind, StorageSkuName sku, Re /// protected override string GetAzureName(IConstruct scope, string resourceName) { - var span = resourceName.AsSpan(); - StringBuilder stringBuilder = new StringBuilder(); - for (int i = 0; i < span.Length; i++) - { - char c = span[i]; - if (!char.IsLetterOrDigit(c)) - { - continue; - } - if (char.IsLetter(c)) - { - stringBuilder.Append(char.ToLowerInvariant(c)); - } - else - { - stringBuilder.Append(c); - } - } - stringBuilder.Append(Guid.NewGuid().ToString("N")); - - return stringBuilder.ToString(0, Math.Min(stringBuilder.Length, 24)); + return $"toLower(take(concat('{resourceName}', uniqueString(resourceGroup().id)), 24))"; } } } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/main.bicep index 13ad8590f5a2e..079b19cdd46ea 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/main.bicep @@ -1,7 +1,7 @@ targetScope = 'subscription' -resource resourceGroup_RKFHPNHNS 'Microsoft.Resources/resourceGroups@2023-07-01' = { +resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' location: 'westus' tags: { @@ -11,7 +11,7 @@ resource resourceGroup_RKFHPNHNS 'Microsoft.Resources/resourceGroups@2023-07-01' module rg_TEST_module './resources/rg_TEST_module/rg_TEST_module.bicep' = { name: 'rg_TEST_module' - scope: resourceGroup_RKFHPNHNS + scope: resourceGroup_I6QNkoPsb } -output appConfigurationStore_kRqdpAmmZ_endpoint string = rg_TEST_module.outputs.appConfigurationStore_kRqdpAmmZ_endpoint +output appConfigurationStore_sgecYnln3_endpoint string = rg_TEST_module.outputs.appConfigurationStore_sgecYnln3_endpoint diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/resources/rg_TEST_module/rg_TEST_module.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/resources/rg_TEST_module/rg_TEST_module.bicep index 5865755b5f5b6..12efbf2dc8b00 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/resources/rg_TEST_module/rg_TEST_module.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/resources/rg_TEST_module/rg_TEST_module.bicep @@ -1,5 +1,5 @@ -resource appConfigurationStore_kRqdpAmmZ 'Microsoft.AppConfiguration/configurationStores@2023-03-01' = { +resource appConfigurationStore_sgecYnln3 'Microsoft.AppConfiguration/configurationStores@2023-03-01' = { name: 'store-TEST' location: 'westus' sku: { @@ -9,4 +9,4 @@ resource appConfigurationStore_kRqdpAmmZ 'Microsoft.AppConfiguration/configurati } } -output appConfigurationStore_kRqdpAmmZ_endpoint string = appConfigurationStore_kRqdpAmmZ.properties.endpoint +output appConfigurationStore_sgecYnln3_endpoint string = appConfigurationStore_sgecYnln3.properties.endpoint diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep index 8cb757b2232d5..96ff62d3a80ea 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep @@ -4,7 +4,7 @@ targetScope = 'subscription' param enableSoftDelete string = 'True' -resource resourceGroup_g8nI7jPJ2 'Microsoft.Resources/resourceGroups@2023-07-01' = { +resource resourceGroup_AVG5HpqPz 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg1-TEST' location: 'westus' tags: { @@ -12,7 +12,7 @@ resource resourceGroup_g8nI7jPJ2 'Microsoft.Resources/resourceGroups@2023-07-01' } } -resource resourceGroup_azggXhH7X 'Microsoft.Resources/resourceGroups@2023-07-01' = { +resource resourceGroup_hu2r8JaSi 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg2-TEST' location: 'westus' tags: { @@ -20,7 +20,7 @@ resource resourceGroup_azggXhH7X 'Microsoft.Resources/resourceGroups@2023-07-01' } } -resource resourceGroup_9Y3rUN36f 'Microsoft.Resources/resourceGroups@2023-07-01' = { +resource resourceGroup_Q4i0lpa1h 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg3-TEST' location: 'westus' tags: { @@ -30,7 +30,7 @@ resource resourceGroup_9Y3rUN36f 'Microsoft.Resources/resourceGroups@2023-07-01' module rg1_TEST_module './resources/rg1_TEST_module/rg1_TEST_module.bicep' = { name: 'rg1_TEST_module' - scope: resourceGroup_g8nI7jPJ2 + scope: resourceGroup_AVG5HpqPz params: { enableSoftDelete: enableSoftDelete SERVICE_API_IDENTITY_PRINCIPAL_ID: rg3_TEST_module.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID @@ -39,7 +39,7 @@ module rg1_TEST_module './resources/rg1_TEST_module/rg1_TEST_module.bicep' = { module rg2_TEST_module './resources/rg2_TEST_module/rg2_TEST_module.bicep' = { name: 'rg2_TEST_module' - scope: resourceGroup_azggXhH7X + scope: resourceGroup_hu2r8JaSi params: { STORAGE_PRINCIPAL_ID: rg1_TEST_module.outputs.STORAGE_PRINCIPAL_ID } @@ -47,7 +47,7 @@ module rg2_TEST_module './resources/rg2_TEST_module/rg2_TEST_module.bicep' = { module rg3_TEST_module './resources/rg3_TEST_module/rg3_TEST_module.bicep' = { name: 'rg3_TEST_module' - scope: resourceGroup_9Y3rUN36f + scope: resourceGroup_Q4i0lpa1h } output STORAGE_PRINCIPAL_ID string = rg1_TEST_module.outputs.STORAGE_PRINCIPAL_ID 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 3cea1347b1c42..b5ec53cf22c12 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 @@ -6,7 +6,7 @@ param enableSoftDelete string = 'True' param SERVICE_API_IDENTITY_PRINCIPAL_ID string -resource appServicePlan_7ufAVFULu 'Microsoft.Web/serverfarms@2021-02-01' = { +resource appServicePlan_viooTTlOI 'Microsoft.Web/serverfarms@2021-02-01' = { name: 'appServicePlan-TEST' location: 'westus' sku: { @@ -17,12 +17,12 @@ resource appServicePlan_7ufAVFULu 'Microsoft.Web/serverfarms@2021-02-01' = { } } -resource webSite_7VDxFxfHl 'Microsoft.Web/sites@2021-02-01' = { +resource webSite_dOTaZfna6 'Microsoft.Web/sites@2021-02-01' = { name: 'frontEnd-TEST' location: 'westus' kind: 'app,linux' properties: { - serverFarmId: '/subscriptions/subscription()/resourceGroups/rg1-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' + serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' siteConfig: { linuxFxVersion: 'node|18-lts' alwaysOn: true @@ -40,12 +40,12 @@ resource webSite_7VDxFxfHl 'Microsoft.Web/sites@2021-02-01' = { } } -resource applicationSettingsResource_MbDOVsFgO 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_7VDxFxfHl +resource applicationSettingsResource_MAMFSSuFs 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_dOTaZfna6 name: 'appsettings' } -resource keyVault_j1ww9730M 'Microsoft.KeyVault/vaults@2023-02-01' = { +resource keyVault_BRsYQF4qT 'Microsoft.KeyVault/vaults@2023-02-01' = { name: 'kv-TEST' location: 'westus' properties: { @@ -59,8 +59,8 @@ resource keyVault_j1ww9730M 'Microsoft.KeyVault/vaults@2023-02-01' = { } } -resource keyVaultAddAccessPolicy_Jv1vsDkxL 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { - parent: keyVault_j1ww9730M +resource keyVaultAddAccessPolicy_lQ2z7dHpX 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { + parent: keyVault_BRsYQF4qT name: 'add' properties: { accessPolicies: [ @@ -78,6 +78,6 @@ resource keyVaultAddAccessPolicy_Jv1vsDkxL 'Microsoft.KeyVault/vaults/accessPoli } } -output STORAGE_PRINCIPAL_ID string = webSite_7VDxFxfHl.identity.principalId -output LOCATION string = webSite_7VDxFxfHl.location -output vaultUri string = keyVault_j1ww9730M.properties.vaultUri +output STORAGE_PRINCIPAL_ID string = webSite_dOTaZfna6.identity.principalId +output LOCATION string = webSite_dOTaZfna6.location +output vaultUri string = keyVault_BRsYQF4qT.properties.vaultUri diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg2_TEST_module/rg2_TEST_module.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg2_TEST_module/rg2_TEST_module.bicep index cb849e6553330..6fd9d14deae9a 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg2_TEST_module/rg2_TEST_module.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg2_TEST_module/rg2_TEST_module.bicep @@ -2,7 +2,7 @@ param STORAGE_PRINCIPAL_ID string -resource webSite_otUunDMEJ 'Microsoft.Web/sites@2021-02-01' = { +resource webSite_80I4ejz5T 'Microsoft.Web/sites@2021-02-01' = { name: 'frontEnd-TEST' location: 'westus' identity: { @@ -10,7 +10,7 @@ resource webSite_otUunDMEJ 'Microsoft.Web/sites@2021-02-01' = { } kind: 'app,linux' properties: { - serverFarmId: '/subscriptions/subscription()/resourceGroups/rg1-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' + serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' siteConfig: { linuxFxVersion: 'node|18-lts' alwaysOn: true @@ -28,7 +28,7 @@ resource webSite_otUunDMEJ 'Microsoft.Web/sites@2021-02-01' = { } } -resource applicationSettingsResource_ou87c8ivP 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_otUunDMEJ +resource applicationSettingsResource_eTrLWYWog 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_80I4ejz5T name: 'appsettings' } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg3_TEST_module/rg3_TEST_module.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg3_TEST_module/rg3_TEST_module.bicep index 740d8ea36ec83..935c5394002d7 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg3_TEST_module/rg3_TEST_module.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg3_TEST_module/rg3_TEST_module.bicep @@ -1,10 +1,10 @@ -resource webSite_ERn8dnbTV 'Microsoft.Web/sites@2021-02-01' = { +resource webSite_Y34mQ7HgU 'Microsoft.Web/sites@2021-02-01' = { name: 'frontEnd-TEST' location: 'westus' kind: 'app,linux' properties: { - serverFarmId: '/subscriptions/subscription()/resourceGroups/rg1-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' + serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' siteConfig: { linuxFxVersion: 'node|18-lts' alwaysOn: true @@ -22,13 +22,13 @@ resource webSite_ERn8dnbTV 'Microsoft.Web/sites@2021-02-01' = { } } -resource applicationSettingsResource_wmfJEHJsI 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_ERn8dnbTV +resource applicationSettingsResource_1XX3wQExf 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_Y34mQ7HgU name: 'appsettings' } -resource webSiteConfigLogs_OF3i4zuus 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_ERn8dnbTV +resource webSiteConfigLogs_vhJa9LaNc 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_Y34mQ7HgU name: 'logs' properties: { applicationLogs: { @@ -52,4 +52,4 @@ resource webSiteConfigLogs_OF3i4zuus 'Microsoft.Web/sites/config@2021-02-01' = { } } -output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_ERn8dnbTV.identity.principalId +output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_Y34mQ7HgU.identity.principalId diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/ResourceGroupOnly/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/ResourceGroupOnly/main.bicep index efca94c85c794..b775ff0ab5b6b 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/ResourceGroupOnly/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/ResourceGroupOnly/main.bicep @@ -1,7 +1,7 @@ targetScope = 'subscription' -resource resourceGroup_RKFHPNHNS 'Microsoft.Resources/resourceGroups@2023-07-01' = { +resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' location: 'westus' tags: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/RoleAssignmentWithParameter/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/RoleAssignmentWithParameter/main.bicep new file mode 100644 index 0000000000000..3d059cb68f6c1 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/RoleAssignmentWithParameter/main.bicep @@ -0,0 +1,35 @@ +targetScope = 'resourceGroup' + +@description('') +param location string = resourceGroup().location + +@description('') +param principalId string + + +resource storageAccount_YRiDhR43q 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: toLower(take(concat('photoAcct', uniqueString(resourceGroup().id)), 24)) + location: location + sku: { + name: 'Premium_LRS' + } + kind: 'StorageV2' + properties: { + } +} + +resource blobService_lnEDXlX5c 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_YRiDhR43q + name: 'default' + properties: { + } +} + +resource roleAssignment_ZBWGKDk4O 'Microsoft.Resources/roleAssignments@2022-04-01' = { + scope: storageAccount_YRiDhR43q + name: guid('storageAccount_YRiDhR43q', principalId, subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'ba92f5b4-2d11-453d-a403-e96b0029c9fe')) + properties: { + roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'ba92f5b4-2d11-453d-a403-e96b0029c9fe') + principalId: principalId + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/RoleAssignmentWithoutParameter/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/RoleAssignmentWithoutParameter/main.bicep new file mode 100644 index 0000000000000..136bc70205674 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/RoleAssignmentWithoutParameter/main.bicep @@ -0,0 +1,15 @@ +targetScope = 'subscription' + + +resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { + name: 'rg-TEST' + location: 'westus' + tags: { + 'azd-env-name': 'TEST' + } +} + +module rg_TEST_module './resources/rg_TEST_module/rg_TEST_module.bicep' = { + name: 'rg_TEST_module' + scope: resourceGroup_I6QNkoPsb +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/RoleAssignmentWithoutParameter/resources/rg_TEST_module/rg_TEST_module.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/RoleAssignmentWithoutParameter/resources/rg_TEST_module/rg_TEST_module.bicep new file mode 100644 index 0000000000000..789920d3acd86 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/RoleAssignmentWithoutParameter/resources/rg_TEST_module/rg_TEST_module.bicep @@ -0,0 +1,27 @@ + +resource storageAccount_melvnlpF2 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: toLower(take(concat('photoAcct', uniqueString(resourceGroup().id)), 24)) + location: 'westus' + sku: { + name: 'Premium_LRS' + } + kind: 'StorageV2' + properties: { + } +} + +resource blobService_NVMDcYVF9 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_melvnlpF2 + name: 'default' + properties: { + } +} + +resource roleAssignment_lDOSGTMrV 'Microsoft.Resources/roleAssignments@2022-04-01' = { + scope: storageAccount_melvnlpF2 + name: guid('storageAccount_melvnlpF2', '00000000-0000-0000-0000-000000000000', subscriptionResourceId('00000000-0000-0000-0000-000000000000', 'Microsoft.Authorization/roleDefinitions', 'ba92f5b4-2d11-453d-a403-e96b0029c9fe')) + properties: { + roleDefinitionId: subscriptionResourceId('00000000-0000-0000-0000-000000000000', 'Microsoft.Authorization/roleDefinitions', 'ba92f5b4-2d11-453d-a403-e96b0029c9fe') + principalId: '00000000-0000-0000-0000-000000000000' + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/RoleAssignmentWithoutParameterInteractiveMode/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/RoleAssignmentWithoutParameterInteractiveMode/main.bicep new file mode 100644 index 0000000000000..76067a58a1a4d --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/RoleAssignmentWithoutParameterInteractiveMode/main.bicep @@ -0,0 +1,32 @@ +targetScope = 'resourceGroup' + +@description('') +param location string = resourceGroup().location + + +resource storageAccount_YRiDhR43q 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: toLower(take(concat('photoAcct', uniqueString(resourceGroup().id)), 24)) + location: location + sku: { + name: 'Premium_LRS' + } + kind: 'StorageV2' + properties: { + } +} + +resource blobService_lnEDXlX5c 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_YRiDhR43q + name: 'default' + properties: { + } +} + +resource roleAssignment_ZBWGKDk4O 'Microsoft.Resources/roleAssignments@2022-04-01' = { + scope: storageAccount_YRiDhR43q + name: guid('storageAccount_YRiDhR43q', '00000000-0000-0000-0000-000000000000', subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'ba92f5b4-2d11-453d-a403-e96b0029c9fe')) + properties: { + roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'ba92f5b4-2d11-453d-a403-e96b0029c9fe') + principalId: '00000000-0000-0000-0000-000000000000' + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/main.bicep index 0e21f476379d0..136bc70205674 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/main.bicep @@ -1,7 +1,7 @@ targetScope = 'subscription' -resource resourceGroup_RKFHPNHNS 'Microsoft.Resources/resourceGroups@2023-07-01' = { +resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' location: 'westus' tags: { @@ -11,5 +11,5 @@ resource resourceGroup_RKFHPNHNS 'Microsoft.Resources/resourceGroups@2023-07-01' module rg_TEST_module './resources/rg_TEST_module/rg_TEST_module.bicep' = { name: 'rg_TEST_module' - scope: resourceGroup_RKFHPNHNS + scope: resourceGroup_I6QNkoPsb } 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 237c99e435bcd..271ca6961a777 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_rJRF56wLn 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoacctdbd29b86eb654ef' +resource storageAccount_melvnlpF2 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: toLower(take(concat('photoAcct', uniqueString(resourceGroup().id)), 24)) location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_rJRF56wLn 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_wGH0Fapvd 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_rJRF56wLn +resource blobService_NVMDcYVF9 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_melvnlpF2 name: 'default' properties: { } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaultsInPromptMode/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaultsInPromptMode/main.bicep index 21b06a8aa946a..36dd0947bc6be 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaultsInPromptMode/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaultsInPromptMode/main.bicep @@ -4,7 +4,7 @@ targetScope = 'resourceGroup' param location string = resourceGroup().location -resource storageAccount_1JetI2q6o 'Microsoft.Storage/storageAccounts@2022-09-01' = { +resource storageAccount_YRiDhR43q 'Microsoft.Storage/storageAccounts@2022-09-01' = { name: toLower(take(concat('photoAcct', uniqueString(resourceGroup().id)), 24)) location: location sku: { @@ -15,8 +15,8 @@ resource storageAccount_1JetI2q6o 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_vupTLRqwy 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_1JetI2q6o +resource blobService_lnEDXlX5c 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_YRiDhR43q name: 'default' properties: { } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/main.bicep index 0e21f476379d0..136bc70205674 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/main.bicep @@ -1,7 +1,7 @@ targetScope = 'subscription' -resource resourceGroup_RKFHPNHNS 'Microsoft.Resources/resourceGroups@2023-07-01' = { +resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' location: 'westus' tags: { @@ -11,5 +11,5 @@ resource resourceGroup_RKFHPNHNS 'Microsoft.Resources/resourceGroups@2023-07-01' module rg_TEST_module './resources/rg_TEST_module/rg_TEST_module.bicep' = { name: 'rg_TEST_module' - scope: resourceGroup_RKFHPNHNS + scope: resourceGroup_I6QNkoPsb } 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 e47a69c839aaa..6cfe9d90583f5 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_3S3yTe8Uk 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoacct0cba824071e046a' +resource storageAccount_melvnlpF2 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: toLower(take(concat('photoAcct', uniqueString(resourceGroup().id)), 24)) location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_3S3yTe8Uk 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_Mv9WBXOiS 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_3S3yTe8Uk +resource blobService_NVMDcYVF9 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_melvnlpF2 name: 'default' properties: { deleteRetentionPolicy: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep index 84b09f826cc41..b1ada50460d66 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep @@ -9,7 +9,7 @@ param sqlAdminPassword string param appUserPassword string -resource resourceGroup_RKFHPNHNS 'Microsoft.Resources/resourceGroups@2023-07-01' = { +resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' location: 'westus' tags: { @@ -20,7 +20,7 @@ resource resourceGroup_RKFHPNHNS 'Microsoft.Resources/resourceGroups@2023-07-01' module rg_TEST_module './resources/rg_TEST_module/rg_TEST_module.bicep' = { name: 'rg_TEST_module' - scope: resourceGroup_RKFHPNHNS + scope: resourceGroup_I6QNkoPsb params: { sqlAdminPassword: sqlAdminPassword appUserPassword: appUserPassword 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 52fc3eba727de..ec4626c43e358 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 @@ -7,7 +7,7 @@ param sqlAdminPassword string param appUserPassword string -resource appServicePlan_fTVlBeFo1 'Microsoft.Web/serverfarms@2021-02-01' = { +resource appServicePlan_kjMZSF1FP 'Microsoft.Web/serverfarms@2021-02-01' = { name: 'appServicePlan-TEST' location: 'westus' sku: { @@ -18,12 +18,12 @@ resource appServicePlan_fTVlBeFo1 'Microsoft.Web/serverfarms@2021-02-01' = { } } -resource webSite_Bml0wjwQj 'Microsoft.Web/sites@2021-02-01' = { +resource webSite_W5EweSXEq 'Microsoft.Web/sites@2021-02-01' = { name: 'frontEnd-TEST' location: 'westus' kind: 'app,linux' properties: { - serverFarmId: '/subscriptions/subscription()/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' + serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' siteConfig: { linuxFxVersion: 'node|18-lts' alwaysOn: true @@ -41,13 +41,13 @@ resource webSite_Bml0wjwQj 'Microsoft.Web/sites@2021-02-01' = { } } -resource applicationSettingsResource_V0kqb41CU 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_Bml0wjwQj +resource applicationSettingsResource_9BG7vUQd2 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_W5EweSXEq name: 'appsettings' } -resource webSiteConfigLogs_KUHXPsIWA 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_Bml0wjwQj +resource webSiteConfigLogs_giqxapQs0 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_W5EweSXEq name: 'logs' properties: { applicationLogs: { @@ -71,7 +71,7 @@ resource webSiteConfigLogs_KUHXPsIWA 'Microsoft.Web/sites/config@2021-02-01' = { } } -resource keyVault_6DI6zrlsS 'Microsoft.KeyVault/vaults@2023-02-01' = { +resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' = { name: 'kv-TEST' location: 'westus' properties: { @@ -84,14 +84,14 @@ resource keyVault_6DI6zrlsS 'Microsoft.KeyVault/vaults@2023-02-01' = { } } -resource keyVaultAddAccessPolicy_xskoP8a8D 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { - parent: keyVault_6DI6zrlsS +resource keyVaultAddAccessPolicy_NWCGclP20 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { + parent: keyVault_CRoMbemLF name: 'add' properties: { accessPolicies: [ { tenantId: '00000000-0000-0000-0000-000000000000' - objectId: webSite_Bml0wjwQj.identity.principalId + objectId: webSite_W5EweSXEq.identity.principalId permissions: { secrets: [ 'get' @@ -103,31 +103,31 @@ resource keyVaultAddAccessPolicy_xskoP8a8D 'Microsoft.KeyVault/vaults/accessPoli } } -resource keyVaultSecret_lEjD8OqD6 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { - parent: keyVault_6DI6zrlsS +resource keyVaultSecret_NmXfhaHvM 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { + parent: keyVault_CRoMbemLF name: 'sqlAdminPassword-TEST' properties: { value: sqlAdminPassword } } -resource keyVaultSecret_hR1lwUNzb 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { - parent: keyVault_6DI6zrlsS +resource keyVaultSecret_QRsiyFBMe 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { + parent: keyVault_CRoMbemLF name: 'appUserPassword-TEST' properties: { value: appUserPassword } } -resource keyVaultSecret_ZVaYjRWrI 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { - parent: keyVault_6DI6zrlsS +resource keyVaultSecret_7eiFxkj0r 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { + parent: keyVault_CRoMbemLF name: 'connectionString-TEST' properties: { - value: 'Server=${sqlServer_RgHXTrwDE.properties.fullyQualifiedDomainName}; Database=${sqlDatabase_6M6mjEKjO.name}; User=appUser; Password=${appUserPassword}' + value: 'Server=${sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName}; Database=${sqlDatabase_U7NzorRJT.name}; User=appUser; Password=${appUserPassword}' } } -resource sqlServer_RgHXTrwDE 'Microsoft.Sql/servers@2022-08-01-preview' = { +resource sqlServer_zjdvvB2wl 'Microsoft.Sql/servers@2022-08-01-preview' = { name: 'sqlserver-TEST' location: 'westus' properties: { @@ -139,15 +139,15 @@ resource sqlServer_RgHXTrwDE 'Microsoft.Sql/servers@2022-08-01-preview' = { } } -resource sqlDatabase_6M6mjEKjO 'Microsoft.Sql/servers/databases@2022-08-01-preview' = { - parent: sqlServer_RgHXTrwDE +resource sqlDatabase_U7NzorRJT 'Microsoft.Sql/servers/databases@2022-08-01-preview' = { + parent: sqlServer_zjdvvB2wl name: 'db-TEST' properties: { } } -resource sqlFirewallRule_vkOA14msE 'Microsoft.Sql/servers/firewallRules@2020-11-01-preview' = { - parent: sqlServer_RgHXTrwDE +resource sqlFirewallRule_eS4m8st65 'Microsoft.Sql/servers/firewallRules@2020-11-01-preview' = { + parent: sqlServer_zjdvvB2wl name: 'firewallRule-TEST' properties: { startIpAddress: '0.0.0.1' @@ -155,7 +155,7 @@ resource sqlFirewallRule_vkOA14msE 'Microsoft.Sql/servers/firewallRules@2020-11- } } -resource deploymentScript_GoSaRcjDM 'Microsoft.Resources/deploymentScripts@2020-10-01' = { +resource deploymentScript_3Zq2Pl8xa 'Microsoft.Resources/deploymentScripts@2020-10-01' = { name: 'cliScript-TEST' location: 'westus' kind: 'AzureCLI' @@ -184,7 +184,7 @@ SCRIPT_END } { name: 'DBSERVER' - value: sqlServer_RgHXTrwDE.properties.fullyQualifiedDomainName + value: sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName } { name: 'DBNAME' @@ -205,12 +205,12 @@ SCRIPT_END } } -resource webSite_Sn4fczQAl 'Microsoft.Web/sites@2021-02-01' = { +resource webSite_4pzZqR2OO 'Microsoft.Web/sites@2021-02-01' = { name: 'backEnd-TEST' location: 'westus' kind: 'app,linux' properties: { - serverFarmId: '/subscriptions/subscription()/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' + serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' siteConfig: { linuxFxVersion: 'dotnetcore|6.0' alwaysOn: true @@ -228,8 +228,8 @@ resource webSite_Sn4fczQAl 'Microsoft.Web/sites@2021-02-01' = { } } -resource applicationSettingsResource_vRjk46ZiQ 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_Sn4fczQAl +resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_4pzZqR2OO name: 'appsettings' properties: { 'SCM_DO_BUILD_DURING_DEPLOYMENT': 'False' @@ -237,6 +237,6 @@ resource applicationSettingsResource_vRjk46ZiQ 'Microsoft.Web/sites/config@2021- } } -output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_Bml0wjwQj.identity.principalId -output vaultUri string = keyVault_6DI6zrlsS.properties.vaultUri -output sqlServerName string = sqlServer_RgHXTrwDE.properties.fullyQualifiedDomainName +output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_W5EweSXEq.identity.principalId +output vaultUri string = keyVault_CRoMbemLF.properties.vaultUri +output sqlServerName string = sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep index cb0603a5155c1..46851b7fa8647 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep @@ -9,7 +9,7 @@ param sqlAdminPassword string param appUserPassword string -resource resourceGroup_RKFHPNHNS 'Microsoft.Resources/resourceGroups@2023-07-01' = { +resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' location: 'westus' tags: { @@ -20,7 +20,7 @@ resource resourceGroup_RKFHPNHNS 'Microsoft.Resources/resourceGroups@2023-07-01' module rg_TEST_module './resources/rg_TEST_module/rg_TEST_module.bicep' = { name: 'rg_TEST_module' - scope: resourceGroup_RKFHPNHNS + scope: resourceGroup_I6QNkoPsb params: { sqlAdminPassword: sqlAdminPassword appUserPassword: appUserPassword 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 3b66661aa5b88..adc0d74fdad37 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 @@ -7,7 +7,7 @@ param sqlAdminPassword string param appUserPassword string -resource appServicePlan_fTVlBeFo1 'Microsoft.Web/serverfarms@2021-02-01' = { +resource appServicePlan_kjMZSF1FP 'Microsoft.Web/serverfarms@2021-02-01' = { name: 'appServicePlan-TEST' location: 'westus' sku: { @@ -18,7 +18,7 @@ resource appServicePlan_fTVlBeFo1 'Microsoft.Web/serverfarms@2021-02-01' = { } } -resource keyVault_6DI6zrlsS 'Microsoft.KeyVault/vaults@2023-02-01' = { +resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' = { name: 'kv-TEST' location: 'westus' properties: { @@ -31,14 +31,14 @@ resource keyVault_6DI6zrlsS 'Microsoft.KeyVault/vaults@2023-02-01' = { } } -resource keyVaultAddAccessPolicy_xskoP8a8D 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { - parent: keyVault_6DI6zrlsS +resource keyVaultAddAccessPolicy_NWCGclP20 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { + parent: keyVault_CRoMbemLF name: 'add' properties: { accessPolicies: [ { tenantId: '00000000-0000-0000-0000-000000000000' - objectId: webSite_Bml0wjwQj.identity.principalId + objectId: webSite_W5EweSXEq.identity.principalId permissions: { secrets: [ 'get' @@ -50,36 +50,36 @@ resource keyVaultAddAccessPolicy_xskoP8a8D 'Microsoft.KeyVault/vaults/accessPoli } } -resource keyVaultSecret_lEjD8OqD6 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { - parent: keyVault_6DI6zrlsS +resource keyVaultSecret_NmXfhaHvM 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { + parent: keyVault_CRoMbemLF name: 'sqlAdminPassword-TEST' properties: { value: sqlAdminPassword } } -resource keyVaultSecret_hR1lwUNzb 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { - parent: keyVault_6DI6zrlsS +resource keyVaultSecret_QRsiyFBMe 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { + parent: keyVault_CRoMbemLF name: 'appUserPassword-TEST' properties: { value: appUserPassword } } -resource keyVaultSecret_ZVaYjRWrI 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { - parent: keyVault_6DI6zrlsS +resource keyVaultSecret_7eiFxkj0r 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { + parent: keyVault_CRoMbemLF name: 'connectionString-TEST' properties: { - value: 'Server=${sqlServer_RgHXTrwDE.properties.fullyQualifiedDomainName}; Database=${sqlDatabase_6M6mjEKjO.name}; User=appUser; Password=${appUserPassword}' + value: 'Server=${sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName}; Database=${sqlDatabase_U7NzorRJT.name}; User=appUser; Password=${appUserPassword}' } } -resource webSite_Bml0wjwQj 'Microsoft.Web/sites@2021-02-01' = { +resource webSite_W5EweSXEq 'Microsoft.Web/sites@2021-02-01' = { name: 'frontEnd-TEST' location: 'westus' kind: 'app,linux' properties: { - serverFarmId: '/subscriptions/subscription()/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' + serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' siteConfig: { linuxFxVersion: 'node|18-lts' alwaysOn: true @@ -97,13 +97,13 @@ resource webSite_Bml0wjwQj 'Microsoft.Web/sites@2021-02-01' = { } } -resource applicationSettingsResource_V0kqb41CU 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_Bml0wjwQj +resource applicationSettingsResource_9BG7vUQd2 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_W5EweSXEq name: 'appsettings' } -resource webSiteConfigLogs_KUHXPsIWA 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_Bml0wjwQj +resource webSiteConfigLogs_giqxapQs0 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_W5EweSXEq name: 'logs' properties: { applicationLogs: { @@ -127,7 +127,7 @@ resource webSiteConfigLogs_KUHXPsIWA 'Microsoft.Web/sites/config@2021-02-01' = { } } -resource sqlServer_RgHXTrwDE 'Microsoft.Sql/servers@2022-08-01-preview' = { +resource sqlServer_zjdvvB2wl 'Microsoft.Sql/servers@2022-08-01-preview' = { name: 'sqlserver-TEST' location: 'westus' properties: { @@ -139,15 +139,15 @@ resource sqlServer_RgHXTrwDE 'Microsoft.Sql/servers@2022-08-01-preview' = { } } -resource sqlDatabase_6M6mjEKjO 'Microsoft.Sql/servers/databases@2022-08-01-preview' = { - parent: sqlServer_RgHXTrwDE +resource sqlDatabase_U7NzorRJT 'Microsoft.Sql/servers/databases@2022-08-01-preview' = { + parent: sqlServer_zjdvvB2wl name: 'db-TEST' properties: { } } -resource sqlFirewallRule_vkOA14msE 'Microsoft.Sql/servers/firewallRules@2020-11-01-preview' = { - parent: sqlServer_RgHXTrwDE +resource sqlFirewallRule_eS4m8st65 'Microsoft.Sql/servers/firewallRules@2020-11-01-preview' = { + parent: sqlServer_zjdvvB2wl name: 'firewallRule-TEST' properties: { startIpAddress: '0.0.0.1' @@ -155,7 +155,7 @@ resource sqlFirewallRule_vkOA14msE 'Microsoft.Sql/servers/firewallRules@2020-11- } } -resource deploymentScript_GoSaRcjDM 'Microsoft.Resources/deploymentScripts@2020-10-01' = { +resource deploymentScript_3Zq2Pl8xa 'Microsoft.Resources/deploymentScripts@2020-10-01' = { name: 'cliScript-TEST' location: 'westus' kind: 'AzureCLI' @@ -184,7 +184,7 @@ SCRIPT_END } { name: 'DBSERVER' - value: sqlServer_RgHXTrwDE.properties.fullyQualifiedDomainName + value: sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName } { name: 'DBNAME' @@ -205,12 +205,12 @@ SCRIPT_END } } -resource webSite_Sn4fczQAl 'Microsoft.Web/sites@2021-02-01' = { +resource webSite_4pzZqR2OO 'Microsoft.Web/sites@2021-02-01' = { name: 'backEnd-TEST' location: 'westus' kind: 'app,linux' properties: { - serverFarmId: '/subscriptions/subscription()/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' + serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' siteConfig: { linuxFxVersion: 'dotnetcore|6.0' alwaysOn: true @@ -228,8 +228,8 @@ resource webSite_Sn4fczQAl 'Microsoft.Web/sites@2021-02-01' = { } } -resource applicationSettingsResource_vRjk46ZiQ 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_Sn4fczQAl +resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_4pzZqR2OO name: 'appsettings' properties: { 'SCM_DO_BUILD_DURING_DEPLOYMENT': 'False' @@ -237,6 +237,6 @@ resource applicationSettingsResource_vRjk46ZiQ 'Microsoft.Web/sites/config@2021- } } -output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_Bml0wjwQj.identity.principalId -output sqlServerName string = sqlServer_RgHXTrwDE.properties.fullyQualifiedDomainName -output vaultUri string = keyVault_6DI6zrlsS.properties.vaultUri +output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_W5EweSXEq.identity.principalId +output sqlServerName string = sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName +output vaultUri string = keyVault_CRoMbemLF.properties.vaultUri diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep index 94c1042973dcd..bfadd18f8ff68 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep @@ -9,7 +9,7 @@ param sqlAdminPassword string param appUserPassword string -resource resourceGroup_RKFHPNHNS 'Microsoft.Resources/resourceGroups@2023-07-01' = { +resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' location: 'westus' tags: { @@ -20,7 +20,7 @@ resource resourceGroup_RKFHPNHNS 'Microsoft.Resources/resourceGroups@2023-07-01' module rg_TEST_module './resources/rg_TEST_module/rg_TEST_module.bicep' = { name: 'rg_TEST_module' - scope: resourceGroup_RKFHPNHNS + scope: resourceGroup_I6QNkoPsb params: { sqlAdminPassword: sqlAdminPassword appUserPassword: appUserPassword 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 3415a0a67044b..6385533de29ba 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 @@ -7,7 +7,7 @@ param sqlAdminPassword string param appUserPassword string -resource appServicePlan_fTVlBeFo1 'Microsoft.Web/serverfarms@2021-02-01' = { +resource appServicePlan_kjMZSF1FP 'Microsoft.Web/serverfarms@2021-02-01' = { name: 'appServicePlan-TEST' location: 'westus' sku: { @@ -18,7 +18,7 @@ resource appServicePlan_fTVlBeFo1 'Microsoft.Web/serverfarms@2021-02-01' = { } } -resource keyVault_6DI6zrlsS 'Microsoft.KeyVault/vaults@2023-02-01' = { +resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' = { name: 'kv-TEST' location: 'westus' tags: { @@ -34,14 +34,14 @@ resource keyVault_6DI6zrlsS 'Microsoft.KeyVault/vaults@2023-02-01' = { } } -resource keyVaultAddAccessPolicy_xskoP8a8D 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { - parent: keyVault_6DI6zrlsS +resource keyVaultAddAccessPolicy_NWCGclP20 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { + parent: keyVault_CRoMbemLF name: 'add' properties: { accessPolicies: [ { tenantId: '00000000-0000-0000-0000-000000000000' - objectId: webSite_Bml0wjwQj.identity.principalId + objectId: webSite_W5EweSXEq.identity.principalId permissions: { secrets: [ 'get' @@ -53,36 +53,36 @@ resource keyVaultAddAccessPolicy_xskoP8a8D 'Microsoft.KeyVault/vaults/accessPoli } } -resource keyVaultSecret_lEjD8OqD6 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { - parent: keyVault_6DI6zrlsS +resource keyVaultSecret_NmXfhaHvM 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { + parent: keyVault_CRoMbemLF name: 'sqlAdminPassword-TEST' properties: { value: sqlAdminPassword } } -resource keyVaultSecret_hR1lwUNzb 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { - parent: keyVault_6DI6zrlsS +resource keyVaultSecret_QRsiyFBMe 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { + parent: keyVault_CRoMbemLF name: 'appUserPassword-TEST' properties: { value: appUserPassword } } -resource keyVaultSecret_ZVaYjRWrI 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { - parent: keyVault_6DI6zrlsS +resource keyVaultSecret_7eiFxkj0r 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { + parent: keyVault_CRoMbemLF name: 'connectionString-TEST' properties: { - value: 'Server=${sqlServer_RgHXTrwDE.properties.fullyQualifiedDomainName}; Database=${sqlDatabase_6M6mjEKjO.name}; User=appUser; Password=${appUserPassword}' + value: 'Server=${sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName}; Database=${sqlDatabase_U7NzorRJT.name}; User=appUser; Password=${appUserPassword}' } } -resource webSite_Bml0wjwQj 'Microsoft.Web/sites@2021-02-01' = { +resource webSite_W5EweSXEq 'Microsoft.Web/sites@2021-02-01' = { name: 'frontEnd-TEST' location: 'westus' kind: 'app,linux' properties: { - serverFarmId: '/subscriptions/subscription()/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' + serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' siteConfig: { linuxFxVersion: 'node|18-lts' alwaysOn: true @@ -100,13 +100,13 @@ resource webSite_Bml0wjwQj 'Microsoft.Web/sites@2021-02-01' = { } } -resource applicationSettingsResource_V0kqb41CU 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_Bml0wjwQj +resource applicationSettingsResource_9BG7vUQd2 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_W5EweSXEq name: 'appsettings' } -resource webSiteConfigLogs_KUHXPsIWA 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_Bml0wjwQj +resource webSiteConfigLogs_giqxapQs0 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_W5EweSXEq name: 'logs' properties: { applicationLogs: { @@ -130,7 +130,7 @@ resource webSiteConfigLogs_KUHXPsIWA 'Microsoft.Web/sites/config@2021-02-01' = { } } -resource sqlServer_RgHXTrwDE 'Microsoft.Sql/servers@2022-08-01-preview' = { +resource sqlServer_zjdvvB2wl 'Microsoft.Sql/servers@2022-08-01-preview' = { name: 'sqlserver-TEST' location: 'westus' properties: { @@ -142,15 +142,15 @@ resource sqlServer_RgHXTrwDE 'Microsoft.Sql/servers@2022-08-01-preview' = { } } -resource sqlDatabase_6M6mjEKjO 'Microsoft.Sql/servers/databases@2022-08-01-preview' = { - parent: sqlServer_RgHXTrwDE +resource sqlDatabase_U7NzorRJT 'Microsoft.Sql/servers/databases@2022-08-01-preview' = { + parent: sqlServer_zjdvvB2wl name: 'db-TEST' properties: { } } -resource sqlFirewallRule_vkOA14msE 'Microsoft.Sql/servers/firewallRules@2020-11-01-preview' = { - parent: sqlServer_RgHXTrwDE +resource sqlFirewallRule_eS4m8st65 'Microsoft.Sql/servers/firewallRules@2020-11-01-preview' = { + parent: sqlServer_zjdvvB2wl name: 'firewallRule-TEST' properties: { startIpAddress: '0.0.0.1' @@ -158,7 +158,7 @@ resource sqlFirewallRule_vkOA14msE 'Microsoft.Sql/servers/firewallRules@2020-11- } } -resource deploymentScript_GoSaRcjDM 'Microsoft.Resources/deploymentScripts@2020-10-01' = { +resource deploymentScript_3Zq2Pl8xa 'Microsoft.Resources/deploymentScripts@2020-10-01' = { name: 'cliScript-TEST' location: 'westus' kind: 'AzureCLI' @@ -187,7 +187,7 @@ SCRIPT_END } { name: 'DBSERVER' - value: sqlServer_RgHXTrwDE.properties.fullyQualifiedDomainName + value: sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName } { name: 'DBNAME' @@ -208,12 +208,12 @@ SCRIPT_END } } -resource webSite_Sn4fczQAl 'Microsoft.Web/sites@2021-02-01' = { +resource webSite_4pzZqR2OO 'Microsoft.Web/sites@2021-02-01' = { name: 'backEnd-TEST' location: 'westus' kind: 'app,linux' properties: { - serverFarmId: '/subscriptions/subscription()/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' + serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' siteConfig: { linuxFxVersion: 'dotnetcore|6.0' alwaysOn: true @@ -231,8 +231,8 @@ resource webSite_Sn4fczQAl 'Microsoft.Web/sites@2021-02-01' = { } } -resource applicationSettingsResource_vRjk46ZiQ 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_Sn4fczQAl +resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_4pzZqR2OO name: 'appsettings' properties: { 'SCM_DO_BUILD_DURING_DEPLOYMENT': 'False' @@ -240,6 +240,6 @@ resource applicationSettingsResource_vRjk46ZiQ 'Microsoft.Web/sites/config@2021- } } -output vaultUri string = keyVault_6DI6zrlsS.properties.vaultUri -output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_Bml0wjwQj.identity.principalId -output sqlServerName string = sqlServer_RgHXTrwDE.properties.fullyQualifiedDomainName +output vaultUri string = keyVault_CRoMbemLF.properties.vaultUri +output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_W5EweSXEq.identity.principalId +output sqlServerName string = sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName diff --git a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs index 52a27b4f1e57f..3f5759edd7f34 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs +++ b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs @@ -18,6 +18,7 @@ using Azure.Provisioning.Resources; using Azure.Provisioning.Storage; using Azure.Provisioning.AppConfiguration; +using Azure.Provisioning.Authorization; using Azure.ResourceManager; using Azure.ResourceManager.Resources; using Azure.ResourceManager.Resources.Models; @@ -45,7 +46,8 @@ public async Task WebSiteUsingL1() AppServicePlan appServicePlan = infra.AddAppServicePlan(); WebSite frontEnd = new WebSite(infra, "frontEnd", appServicePlan, WebSiteRuntime.Node, "18-lts"); - Assert.AreEqual("subscription()", frontEnd.Properties.AppServicePlanId.SubscriptionId); + + Assert.AreEqual(Guid.Empty.ToString(), frontEnd.Properties.AppServicePlanId.SubscriptionId); var frontEndPrincipalId = frontEnd.AddOutput( website => website.Identity.PrincipalId, //Identity.PrincipalId @@ -108,7 +110,8 @@ public async Task WebSiteUsingL2() { var infra = new TestInfrastructure(); infra.AddFrontEndWebSite(); - Assert.AreEqual("subscription()", infra.GetSingleResourceInScope()!.Properties.AppServicePlanId.SubscriptionId); + + Assert.AreEqual(Guid.Empty.ToString(), infra.GetSingleResourceInScope()!.Properties.AppServicePlanId.SubscriptionId); infra.AddCommonSqlDatabase(); infra.AddBackEndWebSite(); @@ -135,7 +138,7 @@ public async Task WebSiteUsingL3() foreach (var website in infra.GetResources().Where(r => r is WebSite)) { - Assert.AreEqual("subscription()", ((WebSite)website).Properties.AppServicePlanId.SubscriptionId); + Assert.AreEqual(Guid.Empty.ToString(), ((WebSite)website).Properties.AppServicePlanId.SubscriptionId); } infra.Build(GetOutputPath()); @@ -151,7 +154,7 @@ await ValidateBicepAsync(BinaryData.FromObjectAsJson( [Test] public async Task WebSiteUsingL3SpecificSubscription() { - var infra = new TestInfrastructure(Guid.Empty); + var infra = new TestInfrastructure(); infra.AddWebSiteWithSqlBackEnd(); infra.GetSingleResource()!.Properties.Tags.Add("key", "value"); @@ -174,7 +177,7 @@ await ValidateBicepAsync(BinaryData.FromObjectAsJson( [Test] public async Task WebSiteUsingL3ResourceGroupScope() { - var infra = new TestInfrastructure(scope: ConstructScope.ResourceGroup, configuration: new Configuration { UsePromptMode = true }); + var infra = new TestInfrastructure(scope: ConstructScope.ResourceGroup, configuration: new Configuration { UseInteractiveMode = true }); infra.AddWebSiteWithSqlBackEnd(); infra.GetSingleResource()!.Properties.Tags.Add("key", "value"); @@ -193,35 +196,81 @@ await ValidateBicepAsync(BinaryData.FromObjectAsJson( { sqlAdminPassword = new { value = "password" }, appUserPassword = new { value = "password" } - }), promptMode: true); + }), interactiveMode: true); } [Test] public async Task StorageBlobDefaults() { var infra = new TestInfrastructure(); - infra.AddStorageAccount(name: "photoAcct", sku: StorageSkuName.PremiumLrs, kind: StorageKind.BlockBlobStorage); + var storageAccount = infra.AddStorageAccount(name: "photoAcct", sku: StorageSkuName.PremiumLrs, kind: StorageKind.BlockBlobStorage); + infra.AddBlobService(); + infra.Build(GetOutputPath()); + + await ValidateBicepAsync(); + } + + [Test] + public async Task RoleAssignmentWithParameter() + { + var infra = new TestInfrastructure(configuration: new Configuration { UseInteractiveMode = true }); + var storageAccount = infra.AddStorageAccount(name: "photoAcct", sku: StorageSkuName.PremiumLrs, kind: StorageKind.BlockBlobStorage); + infra.AddBlobService(); + storageAccount.AssignRole(RoleDefinition.StorageBlobDataContributor); + infra.Build(GetOutputPath()); + + await ValidateBicepAsync(BinaryData.FromObjectAsJson(new { principalId = new { value = Guid.Empty }}), interactiveMode: true); + } + + [Test] + public async Task RoleAssignmentWithoutParameter() + { + var infra = new TestInfrastructure(); + var storageAccount = infra.AddStorageAccount(name: "photoAcct", sku: StorageSkuName.PremiumLrs, kind: StorageKind.BlockBlobStorage); infra.AddBlobService(); + storageAccount.AssignRole(RoleDefinition.StorageBlobDataContributor, Guid.Empty); infra.Build(GetOutputPath()); await ValidateBicepAsync(); } + [Test] + public async Task RoleAssignmentWithoutParameterInteractiveMode() + { + var infra = new TestInfrastructure(configuration: new Configuration { UseInteractiveMode = true }); + var storageAccount = infra.AddStorageAccount(name: "photoAcct", sku: StorageSkuName.PremiumLrs, kind: StorageKind.BlockBlobStorage); + infra.AddBlobService(); + storageAccount.AssignRole(RoleDefinition.StorageBlobDataContributor, Guid.Empty); + infra.Build(GetOutputPath()); + + await ValidateBicepAsync(interactiveMode: true); + } + + [Test] + public void RoleAssignmentPrincipalMustBeSuppliedInNonInteractiveMode() + { + var infra = new TestInfrastructure(); + var storageAccount = infra.AddStorageAccount(name: "photoAcct", sku: StorageSkuName.PremiumLrs, kind: StorageKind.BlockBlobStorage); + infra.AddBlobService(); + + Assert.Throws(() => storageAccount.AssignRole(RoleDefinition.StorageBlobDataContributor)); + } + [Test] public async Task StorageBlobDefaultsInPromptMode() { - var infra = new TestInfrastructure(configuration: new Configuration { UsePromptMode = true }); + var infra = new TestInfrastructure(configuration: new Configuration { UseInteractiveMode = true }); infra.AddStorageAccount(name: "photoAcct", sku: StorageSkuName.PremiumLrs, kind: StorageKind.BlockBlobStorage); infra.AddBlobService(); infra.Build(GetOutputPath()); - await ValidateBicepAsync(promptMode: true); + await ValidateBicepAsync(interactiveMode: true); } [Test] public void CannotAddLocationParameterInPromptMode() { - var infra = new TestInfrastructure(configuration: new Configuration { UsePromptMode = true }); + var infra = new TestInfrastructure(configuration: new Configuration { UseInteractiveMode = true }); var sa = infra.AddStorageAccount(name: "photoAcct", sku: StorageSkuName.PremiumLrs, kind: StorageKind.BlockBlobStorage); Assert.Throws(() => sa.AssignParameter(d => d.Location, new Parameter("myLocationParam"))); @@ -319,7 +368,7 @@ public async Task OutputsSpanningModules() await ValidateBicepAsync(); } - public async Task ValidateBicepAsync(BinaryData? parameters = null, bool promptMode = false) + public async Task ValidateBicepAsync(BinaryData? parameters = null, bool interactiveMode = false) { if (TestEnvironment.GlobalIsRunningInCI) { @@ -356,7 +405,7 @@ public async Task ValidateBicepAsync(BinaryData? parameters = null, bool promptM } ResourceIdentifier scope; - if (promptMode) + if (interactiveMode) { var rgs = subscription.GetResourceGroups(); var data = new ResourceGroupData("westus"); @@ -376,7 +425,7 @@ public async Task ValidateBicepAsync(BinaryData? parameters = null, bool promptM Template = new BinaryData(File.ReadAllText(Path.Combine(testPath, "main.json"))), Parameters = parameters }); - if (!promptMode) + if (!interactiveMode) { content.Location = "westus"; } diff --git a/sdk/provisioning/Azure.Provisioning/tests/TestInfrastructure.cs b/sdk/provisioning/Azure.Provisioning/tests/TestInfrastructure.cs index edb4f127e9296..9a4498d467545 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, Configuration? configuration = null) - : base(scope, Guid.Empty, subscriptionId, "TEST", configuration) + public TestInfrastructure(ConstructScope scope = ConstructScope.Subscription, Configuration? configuration = null) + : base(scope, Guid.Empty, Guid.Empty, "TEST", configuration) { } }