From 635c7ec8499988c7771867d8e94623b4ea85307d Mon Sep 17 00:00:00 2001 From: jolov Date: Fri, 16 Feb 2024 08:35:39 -0800 Subject: [PATCH 01/32] Write bicep into modules based on scope hierarchy rather than user constructs --- .../Azure.Provisioning/src/Construct.cs | 13 +- .../Azure.Provisioning/src/Infrastructure.cs | 183 ++++++++++++- .../Azure.Provisioning/src/Parameter.cs | 10 +- .../Azure.Provisioning/src/Resource.cs | 35 ++- .../src/keyvault/KeyVaultAddAccessPolicy.cs | 2 +- .../src/resourcemanager/ResourceGroup.cs | 5 +- .../ResourceManagerExtensions.cs | 4 +- .../src/websites/AppServicePlan.cs | 5 +- .../src/websites/AppServicesExtensions.cs | 2 +- .../src/websites/WebSite.cs | 5 +- .../MultipleSubscriptions/main.bicep | 12 + .../subscription_0n8qEB2gZ.bicep | 10 + .../subscription_LDRPSoVXn.bicep | 10 + .../OutputsSpanningModules/main.bicep | 41 +++ .../resources/rg1_TEST/rg1_TEST.bicep | 46 ++++ .../resources/rg2_TEST/rg2_TEST.bicep | 38 +++ .../ResourceGroupOnly/main.bicep | 2 +- .../StorageBlobDefaults/main.bicep | 22 +- .../resources/rg_TEST/rg_TEST.bicep | 20 ++ .../StorageBlobDropDown/main.bicep | 25 +- .../resources/rg_TEST/rg_TEST.bicep | 23 ++ .../Infrastructure/WebSiteUsingL1/main.bicep | 249 +----------------- .../resources/rg_TEST/rg_TEST.bicep | 248 +++++++++++++++++ .../Infrastructure/WebSiteUsingL2/main.bicep | 62 +---- .../TestBackEndWebSite.bicep | 40 --- .../TestCommonSqlDatabase.bicep | 115 -------- .../TestFrontEndWebSite.bicep | 67 ----- .../resources/rg_TEST/rg_TEST.bicep | 248 +++++++++++++++++ .../Infrastructure/WebSiteUsingL3/main.bicep | 18 +- .../TestBackEndWebSite.bicep | 40 --- .../TestCommonSqlDatabase.bicep | 115 -------- .../TestFrontEndWebSite.bicep | 67 ----- .../TestWebSiteWithSqlBackEnd.bicep | 74 ------ .../resources/rg_TEST/rg_TEST.bicep | 45 ++++ .../tests/ProvisioningTests.cs | 41 +++ .../tests/TestSubscriptionInfrastructure.cs | 15 ++ 36 files changed, 1048 insertions(+), 909 deletions(-) create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_0n8qEB2gZ/subscription_0n8qEB2gZ.bicep create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_LDRPSoVXn/subscription_LDRPSoVXn.bicep create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg2_TEST/rg2_TEST.bicep create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep delete mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestBackEndWebSite/TestBackEndWebSite.bicep delete mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestCommonSqlDatabase/TestCommonSqlDatabase.bicep delete mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestFrontEndWebSite/TestFrontEndWebSite.bicep create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep delete mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestBackEndWebSite/TestBackEndWebSite.bicep delete mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestCommonSqlDatabase/TestCommonSqlDatabase.bicep delete mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestFrontEndWebSite/TestFrontEndWebSite.bicep delete mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestWebSiteWithSqlBackEnd/TestWebSiteWithSqlBackEnd.bicep create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep create mode 100644 sdk/provisioning/Azure.Provisioning/tests/TestSubscriptionInfrastructure.cs diff --git a/sdk/provisioning/Azure.Provisioning/src/Construct.cs b/sdk/provisioning/Azure.Provisioning/src/Construct.cs index b1130a312585c..b10bd37380f07 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Construct.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Construct.cs @@ -50,6 +50,13 @@ public abstract class Construct : IConstruct, IPersistableModel /// The environment name to use. If not passed in will try to load from AZURE_ENV_NAME environment variable. /// is and is null. protected Construct(IConstruct? scope, string name, ConstructScope constructScope = ConstructScope.ResourceGroup, Guid? tenantId = null, Guid? subscriptionId = null, string? envName = null) + : this(scope, name, constructScope, tenantId, subscriptionId, envName, null) + { + } + + internal Construct(IConstruct? scope, string name, ConstructScope constructScope = ConstructScope.ResourceGroup, + Guid? tenantId = null, Guid? subscriptionId = null, string? envName = null, + ResourceGroup? resourceGroup = null) { if (scope is null && constructScope == ConstructScope.ResourceGroup) { @@ -68,7 +75,7 @@ protected Construct(IConstruct? scope, string name, ConstructScope constructScop ConstructScope = constructScope; if (constructScope == ConstructScope.ResourceGroup) { - ResourceGroup = scope!.ResourceGroup ?? scope.GetOrAddResourceGroup(); + ResourceGroup = resourceGroup ?? scope!.ResourceGroup ?? scope.GetOrAddResourceGroup(); } if (constructScope == ConstructScope.Subscription) { @@ -167,7 +174,7 @@ public void AddOutput(Output output) private string GetScopeName() { - return ResourceGroup?.Name ?? Subscription?.Name ?? "tenant()"; + return ResourceGroup?.Name ?? (Subscription != null ? $"subscription('{Subscription.Name}')" : "tenant()"); } private BinaryData SerializeModuleReference(ModelReaderWriterOptions options) @@ -244,7 +251,7 @@ private void WriteScopeLine(MemoryStream stream) { if (ConstructScope != ConstructScope.ResourceGroup) { - stream.WriteLine($"targetScope = {ConstructScope.ToString().ToCamelCase()}{Environment.NewLine}"); + stream.WriteLine($"targetScope = '{ConstructScope.ToString().ToCamelCase()}'{Environment.NewLine}"); } } diff --git a/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs b/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs index c9c49198eea9c..1a4024a0f5469 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs @@ -5,6 +5,8 @@ using System.ClientModel.Primitives; using System.Collections.Generic; using System.IO; +using System.Linq; +using Azure.Provisioning.ResourceManager; namespace Azure.Provisioning { @@ -36,34 +38,199 @@ public void Build(string? outputPath = null) outputPath ??= $".\\{GetType().Name}"; outputPath = Path.GetFullPath(outputPath); - WriteBicepFile(this, outputPath); + Dictionary> resourceTree = BuildResourceTree(); - var queue = new Queue(); - queue.Enqueue(this); + var constructs = GetConstructs(true).ToArray(); + foreach (var construct in constructs) + { + construct.GetResources(true); + } + + ModuleConstruct? root = null; + BuildModuleConstructs(Root, resourceTree, null, ref root); + + WriteBicepFile(root!, outputPath); + + var queue = new Queue(); + queue.Enqueue(root!); WriteConstructsByLevel(queue, outputPath); } - private void WriteConstructsByLevel(Queue constructs, string outputPath) + private Dictionary> BuildResourceTree() + { + var resources = GetResources(true).ToArray(); + Dictionary> resourceTree = new(); + HashSet visited = new(); + foreach (var resource in resources) + { + VisitResource(resource, resourceTree, visited); + } + + return resourceTree; + } + + private void BuildModuleConstructs(Resource resource, Dictionary> resourceTree, ModuleConstruct? parentScope, ref ModuleConstruct? root) + { + ModuleConstruct? construct = null; + if (NeedsModuleConstruct(resource, resourceTree)) + { + construct = new ModuleConstruct(resource); + + if (parentScope == null) + { + root = construct; + construct.IsRoot = true; + } + } + + if (construct != null) + { + parentScope?.AddConstruct(construct); + } + + if (parentScope != null) + { + parentScope.AddResource(resource); + resource.ModuleScope = parentScope; + } + + parentScope = parentScope ?? construct; + if (parentScope != null) + { + foreach (var parameter in resource.Parameters) + { + parentScope.AddParameter(parameter); + } + + foreach (var parameterOverride in resource.ParameterOverrides) + { + foreach (var kvp in parameterOverride.Value) + { + kvp.Value.Source = parentScope; + kvp.Value.Value = GetParameterValue(kvp.Value, parentScope); + } + } + + foreach (var output in resource.Outputs) + { + var moduleOutput = new Output(output.Name, output.Value, parentScope, output.IsLiteral, output.IsSecure); + parentScope.AddOutput(moduleOutput); + } + } + + foreach (var child in resourceTree[resource]) + { + BuildModuleConstructs(child, resourceTree, construct ?? parentScope, ref root); + } + } + + private static string GetParameterValue(Parameter parameter, IConstruct scope) + { + // If the parameter is a parameter of the module scope, use the parameter name. + if (scope.GetParameters(false).Contains(parameter)) + { + return parameter.Name; + } + // Otherwise we assume it is an output from the current module. + if ( parameter.Source is null || ReferenceEquals(parameter.Source, scope)) + { + return parameter.Value!; + } + + return $"{parameter.Source.Name}.outputs.{parameter.Name}"; + } + + private class ModuleConstruct : Construct + { + public ModuleConstruct(Resource resource) + : base( + resource.Scope, + resource is Subscription ? resource.Name : resource.Id.Name.Replace('-', '_'), + ResourceToConstructScope(resource), + subscriptionId: resource is not Tenant ? Guid.Parse(resource.Id.SubscriptionId!) : null, + resourceGroup: resource as ResourceGroup) + { + } + + public bool IsRoot { get; set; } + } + + private static ConstructScope ResourceToConstructScope(Resource resource) + { + return resource switch + { + Tenant => ConstructScope.Tenant, + ResourceManager.Subscription => ConstructScope.Subscription, + //TODO managementgroup support + ResourceManager.ResourceGroup => ConstructScope.ResourceGroup, + _ => throw new NotImplementedException(), + }; + } + + private bool NeedsModuleConstruct(Resource resource, Dictionary> resourceTree) + { + if (!(resource is Tenant || resource is Subscription || resource is ResourceGroup)) + { + return false; + } + if (resource is Tenant) + { + // TODO add management group check + return resourceTree[resource].Count > 1; + } + if (resource is Subscription || resource is ResourceGroup) + { + // TODO add policy support + return resourceTree[resource].Count > 0; + } + + return false; + } + + private void VisitResource(Resource resource, Dictionary> resourceTree, HashSet visited) + { + if (!visited.Add(resource)) + { + return; + } + + if (!resourceTree.ContainsKey(resource)) + { + resourceTree[resource] = new List(); + } + + if (resource.Parent != null) + { + if (!resourceTree.ContainsKey(resource.Parent)) + { + resourceTree[resource.Parent] = new List(); + } + resourceTree[resource.Parent].Add(resource); + VisitResource(resource.Parent, resourceTree, visited); + } + } + + private void WriteConstructsByLevel(Queue constructs, string outputPath) { while (constructs.Count > 0) { var construct = constructs.Dequeue(); foreach (var child in construct.GetConstructs(false)) { - constructs.Enqueue(child); + constructs.Enqueue((ModuleConstruct)child); } WriteBicepFile(construct, outputPath); } } - private string GetFilePath(IConstruct construct, string outputPath) + private string GetFilePath(ModuleConstruct construct, string outputPath) { - string fileName = object.ReferenceEquals(construct, this) ? Path.Combine(outputPath, "main.bicep") : Path.Combine(outputPath, "resources", construct.Name, $"{construct.Name}.bicep"); + string fileName = construct.IsRoot ? Path.Combine(outputPath, "main.bicep") : Path.Combine(outputPath, "resources", construct.Name, $"{construct.Name}.bicep"); Directory.CreateDirectory(Path.GetDirectoryName(fileName)!); return fileName; } - private void WriteBicepFile(IConstruct construct, string outputPath) + private void WriteBicepFile(ModuleConstruct construct, string outputPath) { using var stream = new FileStream(GetFilePath(construct, outputPath), FileMode.Create); #if NET6_0_OR_GREATER diff --git a/sdk/provisioning/Azure.Provisioning/src/Parameter.cs b/sdk/provisioning/Azure.Provisioning/src/Parameter.cs index 1ac6491823745..395e47f18e07c 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Parameter.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Parameter.cs @@ -7,7 +7,7 @@ namespace Azure.Provisioning /// Represents a parameter of an . /// #pragma warning disable AZC0012 // Avoid single word type names - public readonly struct Parameter + public class Parameter #pragma warning restore AZC0012 // Avoid single word type names { /// @@ -28,9 +28,13 @@ public readonly struct Parameter public bool IsSecure { get; } internal bool IsFromOutput { get; } internal bool IsLiteral { get; } - internal string? Value { get; } - internal IConstruct? Source { get; } + internal string? Value { get; set; } + internal IConstruct? Source { get; set; } + /// + /// + /// + /// internal Parameter(Output output) { Name = output.Name; diff --git a/sdk/provisioning/Azure.Provisioning/src/Resource.cs b/sdk/provisioning/Azure.Provisioning/src/Resource.cs index 46752e606e107..5a75deec959e5 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Resource.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Resource.cs @@ -4,7 +4,9 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Diagnostics; using System.IO; +using System.Runtime.InteropServices.ComTypes; using System.Security.Cryptography; using System.Text; using Azure.Core; @@ -21,7 +23,7 @@ namespace Azure.Provisioning public abstract class Resource : IPersistableModel #pragma warning restore AZC0012 // Avoid single word type names { - internal Dictionary> ParameterOverrides { get; } + internal Dictionary> ParameterOverrides { get; } private IList Dependencies { get; } @@ -59,6 +61,10 @@ internal void AddDependency(Resource resource) /// public IList Parameters { get; } + internal IList Outputs { get; } + + internal IConstruct? ModuleScope { get; set; } + /// /// Initializes a new instance of the . /// @@ -75,11 +81,12 @@ protected Resource(IConstruct scope, Resource? parent, string resourceName, Reso Scope = scope; Parameters = new List(); - Parent = parent ?? FindParentInScope(scope); + Outputs = new List(); + Parent = parent ?? FindParentInScope(scope); Scope.AddResource(this); Properties = properties; Version = version; - ParameterOverrides = new Dictionary>(); + ParameterOverrides = new Dictionary>(); Dependencies = new List(); ResourceType = resourceType; Id = Parent is null ? ResourceIdentifier.Root : Parent is ResourceGroup ? Parent.Id.AppendProviderResource(ResourceType.Namespace, ResourceType.GetLastType(), resourceName) : Parent.Id.AppendChildResource(ResourceType.GetLastType(), resourceName); @@ -106,11 +113,11 @@ private protected void AssignParameter(object instance, string propertyName, Par { if (ParameterOverrides.TryGetValue(instance, out var overrides)) { - overrides[propertyName] = parameter.Name; + overrides[propertyName] = parameter; } else { - ParameterOverrides.Add(instance, new Dictionary { { propertyName, parameter.Name } }); + ParameterOverrides.Add(instance, new Dictionary { { propertyName, parameter } }); } Parameters.Add(parameter); } @@ -133,6 +140,7 @@ private protected Output AddOutput(string name, object instance, string property throw new ArgumentException(nameof(propertyName), $"{propertyName} was not found in the property tree for {Properties.GetType().Name}"); var result = new Output(name, reference, Scope, isLiteral, isSecure); Scope.AddOutput(result); + Outputs.Add(result); return result; } @@ -195,7 +203,12 @@ private BinaryData SerializeModule(ModelReaderWriterOptions options) var bicepOptions = new BicepModelReaderWriterOptions(); foreach (var parameter in ParameterOverrides) { - bicepOptions.ParameterOverrides.Add(parameter.Key, parameter.Value); + var dict = new Dictionary(); + foreach (var kvp in parameter.Value) + { + dict.Add(kvp.Key, kvp.Value.Value!); + } + bicepOptions.ParameterOverrides.Add(parameter.Key, dict); } var data = ModelReaderWriter.Write(Properties, bicepOptions).ToMemory(); @@ -210,16 +223,18 @@ private BinaryData SerializeModule(ModelReaderWriterOptions options) private bool NeedsScope() { + Debug.Assert(ModuleScope != null, "ModuleScope should not be null"); + switch (Parent) { case ResourceGroup _: - return Scope.ConstructScope != ConstructScope.ResourceGroup; + return ModuleScope!.ConstructScope != ConstructScope.ResourceGroup; case Subscription _: - return Scope.ConstructScope != ConstructScope.Subscription; + return ModuleScope!.ConstructScope != ConstructScope.Subscription; case Tenant _: - return Scope.ConstructScope != ConstructScope.Tenant; + return ModuleScope!.ConstructScope != ConstructScope.Tenant; default: - return Scope.ConstructScope != ConstructScope.ResourceGroup; + return ModuleScope!.ConstructScope != ConstructScope.ResourceGroup; } } diff --git a/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVaultAddAccessPolicy.cs b/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVaultAddAccessPolicy.cs index 31999e92eed64..26150d8b6425e 100644 --- a/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVaultAddAccessPolicy.cs +++ b/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVaultAddAccessPolicy.cs @@ -32,7 +32,7 @@ public KeyVaultAddAccessPolicy(IConstruct scope, Parameter principalIdParameter, }) })) { - ParameterOverrides.Add(Properties.AccessPolicies[0], new Dictionary { { nameof(KeyVaultAccessPolicy.ObjectId), GetParamValue(principalIdParameter, scope) } }); + ParameterOverrides.Add(Properties.AccessPolicies[0], new Dictionary { { nameof(KeyVaultAccessPolicy.ObjectId), principalIdParameter } }); } private static string GetParamValue(Parameter principalIdParameter, IConstruct scope) diff --git a/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceGroup.cs b/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceGroup.cs index 61b36e0f0130b..53f5ec4aa6ddd 100644 --- a/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceGroup.cs +++ b/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceGroup.cs @@ -23,8 +23,9 @@ public class ResourceGroup : Resource /// The name of the resourceGroup. /// The version of the resourceGroup. /// The location of the resourceGroup. - public ResourceGroup(IConstruct scope, string? name = default, string version = "2023-07-01", AzureLocation? location = default) - : base(scope, null, GetName(scope, name), ResourceType, version, ResourceManagerModelFactory.ResourceGroupData( + /// + public ResourceGroup(IConstruct scope, string? name = default, string version = "2023-07-01", AzureLocation? location = default, Resource? parent = default) + : base(scope, parent, GetName(scope, name), ResourceType, version, ResourceManagerModelFactory.ResourceGroupData( name: GetName(scope, name), resourceType: ResourceType, tags: new Dictionary { { "azd-env-name", scope.EnvironmentName } }, diff --git a/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceManagerExtensions.cs b/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceManagerExtensions.cs index 49000090eb282..0ed54ac7cea8a 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, "rg"); + return new ResourceGroup(construct, name: "rg"); } /// @@ -44,7 +44,7 @@ public static ResourceGroup GetOrAddResourceGroup(this IConstruct construct) /// The see . public static Subscription GetOrCreateSubscription(this IConstruct construct, Guid? subscriptionId = null) { - return construct.Subscription ?? construct.GetSingleResource() ?? new Subscription(construct, subscriptionId); + return construct.Subscription ?? (subscriptionId != null ? new Subscription(construct, subscriptionId) : construct.GetSingleResource())!; } } } diff --git a/sdk/provisioning/Azure.Provisioning/src/websites/AppServicePlan.cs b/sdk/provisioning/Azure.Provisioning/src/websites/AppServicePlan.cs index 33d538d5083ce..f51da7bb9fc03 100644 --- a/sdk/provisioning/Azure.Provisioning/src/websites/AppServicePlan.cs +++ b/sdk/provisioning/Azure.Provisioning/src/websites/AppServicePlan.cs @@ -25,8 +25,9 @@ public class AppServicePlan : Resource /// The resource name. /// The version. /// The location. - public AppServicePlan(IConstruct scope, string resourceName, string version = "2021-02-01", AzureLocation? location = default) - : base(scope, null, GetName(scope, resourceName), ResourceTypeName, version, ArmAppServiceModelFactory.AppServicePlanData( + /// + public AppServicePlan(IConstruct scope, string resourceName, string version = "2021-02-01", AzureLocation? location = default, ResourceGroup? parent = default) + : base(scope, parent, GetName(scope, resourceName), ResourceTypeName, version, ArmAppServiceModelFactory.AppServicePlanData( name: GetName(scope, resourceName), location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS, sku: new AppServiceSkuDescription() { Name = "B1" }, diff --git a/sdk/provisioning/Azure.Provisioning/src/websites/AppServicesExtensions.cs b/sdk/provisioning/Azure.Provisioning/src/websites/AppServicesExtensions.cs index b0c834c309019..3e7a4c518db34 100644 --- a/sdk/provisioning/Azure.Provisioning/src/websites/AppServicesExtensions.cs +++ b/sdk/provisioning/Azure.Provisioning/src/websites/AppServicesExtensions.cs @@ -19,7 +19,7 @@ public static class AppServicesExtensions /// public static AppServicePlan AddAppServicePlan(this IConstruct construct, ResourceGroup? parent = null, string name = "appServicePlan") { - return new AppServicePlan(construct, name); ; + return new AppServicePlan(construct, name, parent: parent); } } } diff --git a/sdk/provisioning/Azure.Provisioning/src/websites/WebSite.cs b/sdk/provisioning/Azure.Provisioning/src/websites/WebSite.cs index 971d1275813da..912450cefc9f3 100644 --- a/sdk/provisioning/Azure.Provisioning/src/websites/WebSite.cs +++ b/sdk/provisioning/Azure.Provisioning/src/websites/WebSite.cs @@ -46,8 +46,9 @@ public class WebSite : Resource /// The runtime version /// The version. /// The location. - public WebSite(IConstruct scope, string resourceName, AppServicePlan appServicePlan, WebSiteRuntime runtime, string runtimeVersion, string version = "2021-02-01", AzureLocation? location = default) - : base(scope, null, GetName(scope, resourceName), ResourceTypeName, version, ArmAppServiceModelFactory.WebSiteData( + /// + public WebSite(IConstruct scope, string resourceName, AppServicePlan appServicePlan, WebSiteRuntime runtime, string runtimeVersion, string version = "2021-02-01", AzureLocation? location = default, ResourceGroup? parent = null) + : base(scope, parent, GetName(scope, resourceName), ResourceTypeName, version, ArmAppServiceModelFactory.WebSiteData( name: GetName(scope, resourceName), location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS, resourceType: ResourceTypeName, diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep new file mode 100644 index 0000000000000..e6e626c905bb2 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep @@ -0,0 +1,12 @@ +targetScope = 'tenant' + + +module subscription_LDRPSoVXn './resources/subscription_LDRPSoVXn/subscription_LDRPSoVXn.bicep' = { + name: 'subscription_LDRPSoVXn' + scope: subscription('subscription_LDRPSoVXn') +} + +module subscription_0n8qEB2gZ './resources/subscription_0n8qEB2gZ/subscription_0n8qEB2gZ.bicep' = { + name: 'subscription_0n8qEB2gZ' + scope: subscription('subscription_0n8qEB2gZ') +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_0n8qEB2gZ/subscription_0n8qEB2gZ.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_0n8qEB2gZ/subscription_0n8qEB2gZ.bicep new file mode 100644 index 0000000000000..42245982b194e --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_0n8qEB2gZ/subscription_0n8qEB2gZ.bicep @@ -0,0 +1,10 @@ +targetScope = 'subscription' + + +resource resourceGroup_moTSF0YWl 'Microsoft.Resources/resourceGroups@2023-07-01' = { + name: 'rg-TEST' + location: 'westus' + tags: { + azd-env-name: 'TEST' + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_LDRPSoVXn/subscription_LDRPSoVXn.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_LDRPSoVXn/subscription_LDRPSoVXn.bicep new file mode 100644 index 0000000000000..58f6525784517 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_LDRPSoVXn/subscription_LDRPSoVXn.bicep @@ -0,0 +1,10 @@ +targetScope = 'subscription' + + +resource resourceGroup_Yp9j3M9ZM 'Microsoft.Resources/resourceGroups@2023-07-01' = { + name: 'rg-TEST' + location: 'westus' + tags: { + azd-env-name: 'TEST' + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep new file mode 100644 index 0000000000000..61669b82ddf22 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep @@ -0,0 +1,41 @@ +targetScope = 'subscription' + +@description('') +param STORAGE_PRINCIPAL_ID string + +@description('') +param LOCATION string + + +resource resourceGroup_AVG5HpqPz 'Microsoft.Resources/resourceGroups@2023-07-01' = { + name: 'rg1-TEST' + location: 'westus' + tags: { + azd-env-name: 'TEST' + } +} + +resource resourceGroup_hu2r8JaSi 'Microsoft.Resources/resourceGroups@2023-07-01' = { + name: 'rg2-TEST' + location: 'westus' + tags: { + azd-env-name: 'TEST' + } +} + +module rg1_TEST './resources/rg1_TEST/rg1_TEST.bicep' = { + name: 'rg1_TEST' + scope: resourceGroup_AVG5HpqPz +} + +module rg2_TEST './resources/rg2_TEST/rg2_TEST.bicep' = { + name: 'rg2_TEST' + scope: resourceGroup_hu2r8JaSi + params: { + STORAGE_PRINCIPAL_ID: STORAGE_PRINCIPAL_ID + LOCATION: LOCATION + } +} + +output STORAGE_PRINCIPAL_ID string = rg1_TEST.outputs.STORAGE_PRINCIPAL_ID +output LOCATION string = rg1_TEST.outputs.LOCATION diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep new file mode 100644 index 0000000000000..ddf39fdb6b1d1 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep @@ -0,0 +1,46 @@ + +resource appServicePlan_viooTTlOI 'Microsoft.Web/serverfarms@2021-02-01' = { + name: 'appServicePlan-TEST' + location: 'westus' + sku: { + name: 'B1' + } + properties: { + reserved: true + } +} + +resource webSite_dOTaZfna6 'Microsoft.Web/sites@2021-02-01' = { + name: 'frontEnd-TEST' + location: 'westus' + identity: { + } + kind: 'app,linux' + properties: { + serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' + siteConfig: { + linuxFxVersion: 'node|18-lts' + alwaysOn: true + appCommandLine: './entrypoint.sh -o ./env-config.js && pm2 serve /home/site/wwwroot --no-daemon --spa' + experiments: { + } + cors: { + allowedOrigins: [ + 'https://portal.azure.com' + 'https://ms.portal.azure.com' + ] + } + minTlsVersion: '1.2' + ftpsState: 'FtpsOnly' + } + httpsOnly: true + } +} + +resource applicationSettingsResource_lzuRUWkeF 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_dOTaZfna6 + name: 'appsettings' +} + +output STORAGE_PRINCIPAL_ID string = webSite_dOTaZfna6.identity.principalId +output LOCATION string = webSite_dOTaZfna6.location diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg2_TEST/rg2_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg2_TEST/rg2_TEST.bicep new file mode 100644 index 0000000000000..c184fb6ae804f --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg2_TEST/rg2_TEST.bicep @@ -0,0 +1,38 @@ +@description('') +param STORAGE_PRINCIPAL_ID string + +@description('') +param LOCATION string + + +resource webSite_80I4ejz5T 'Microsoft.Web/sites@2021-02-01' = { + name: 'frontEnd-TEST' + location: LOCATION + identity: { + } + kind: 'app,linux' + properties: { + serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' + siteConfig: { + linuxFxVersion: 'node|18-lts' + alwaysOn: true + appCommandLine: './entrypoint.sh -o ./env-config.js && pm2 serve /home/site/wwwroot --no-daemon --spa' + experiments: { + } + cors: { + allowedOrigins: [ + 'https://portal.azure.com' + 'https://ms.portal.azure.com' + ] + } + minTlsVersion: '1.2' + ftpsState: 'FtpsOnly' + } + httpsOnly: true + } +} + +resource applicationSettingsResource_kPTV48HdO 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_80I4ejz5T + name: 'appsettings' +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/ResourceGroupOnly/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/ResourceGroupOnly/main.bicep index 9eb894c2b3ff2..b2316c67ec120 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/ResourceGroupOnly/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/ResourceGroupOnly/main.bicep @@ -1,4 +1,4 @@ -targetScope = subscription +targetScope = 'subscription' resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/main.bicep index 0264df3811fbd..298e5ac002ff5 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/main.bicep @@ -1,4 +1,4 @@ -targetScope = subscription +targetScope = 'subscription' resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { @@ -9,23 +9,7 @@ resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' } } -resource storageAccount_blTmfjwbK 'Microsoft.Storage/storageAccounts@2022-09-01' = { +module rg_TEST './resources/rg_TEST/rg_TEST.bicep' = { + name: 'rg_TEST' scope: resourceGroup_I6QNkoPsb - name: 'photoAcct-4e4db487e2b643' - location: 'westus' - sku: { - name: 'Premium_LRS' - } - kind: 'StorageV2' - properties: { - } -} - -resource blobService_BsPXWXWhN 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_blTmfjwbK - name: 'photos-TEST' - properties: { - cors: { - } - } } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep new file mode 100644 index 0000000000000..5f8645ed8eac9 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep @@ -0,0 +1,20 @@ + +resource storageAccount_S5qJniO7O 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-5fa1326a602c47' + location: 'westus' + sku: { + name: 'Premium_LRS' + } + kind: 'StorageV2' + properties: { + } +} + +resource blobService_NVGSBDZv1 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_S5qJniO7O + name: 'photos-TEST' + properties: { + cors: { + } + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/main.bicep index c03c30a706955..298e5ac002ff5 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/main.bicep @@ -1,4 +1,4 @@ -targetScope = subscription +targetScope = 'subscription' resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { @@ -9,26 +9,7 @@ resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' } } -resource storageAccount_hEAJzZrZs 'Microsoft.Storage/storageAccounts@2022-09-01' = { +module rg_TEST './resources/rg_TEST/rg_TEST.bicep' = { + name: 'rg_TEST' scope: resourceGroup_I6QNkoPsb - name: 'photoAcct-1b8d4004b0984b' - location: 'westus' - sku: { - name: 'Premium_LRS' - } - kind: 'StorageV2' - properties: { - } -} - -resource blobService_0wStUCho1 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_hEAJzZrZs - name: 'photos-TEST' - properties: { - cors: { - } - deleteRetentionPolicy: { - enabled: true - } - } } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep new file mode 100644 index 0000000000000..8d1eaa5d93cd9 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep @@ -0,0 +1,23 @@ + +resource storageAccount_g16JGJUrY 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-6c337c3efac749' + location: 'westus' + sku: { + name: 'Premium_LRS' + } + kind: 'StorageV2' + properties: { + } +} + +resource blobService_f8CmSjkLj 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_g16JGJUrY + name: 'photos-TEST' + properties: { + cors: { + } + deleteRetentionPolicy: { + enabled: true + } + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep index d43f5d9ffa9b1..a1dceb43a30e4 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep @@ -1,4 +1,4 @@ -targetScope = subscription +targetScope = 'subscription' @secure() @description('SQL Server administrator password') @@ -18,248 +18,13 @@ resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' } } -resource appServicePlan_kjMZSF1FP 'Microsoft.Web/serverfarms@2021-02-01' = { +module rg_TEST './resources/rg_TEST/rg_TEST.bicep' = { + name: 'rg_TEST' scope: resourceGroup_I6QNkoPsb - name: 'appServicePlan-TEST' - location: 'westus' - sku: { - name: 'B1' - } - properties: { - reserved: true - } -} - -resource webSite_W5EweSXEq 'Microsoft.Web/sites@2021-02-01' = { - scope: resourceGroup_I6QNkoPsb - name: 'frontEnd-TEST' - location: 'westus' - identity: { - } - kind: 'app,linux' - properties: { - serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' - siteConfig: { - linuxFxVersion: 'node|18-lts' - alwaysOn: true - appCommandLine: './entrypoint.sh -o ./env-config.js && pm2 serve /home/site/wwwroot --no-daemon --spa' - experiments: { - } - cors: { - allowedOrigins: [ - 'https://portal.azure.com' - 'https://ms.portal.azure.com' - ] - } - minTlsVersion: '1.2' - ftpsState: 'FtpsOnly' - } - httpsOnly: true - } -} - -resource applicationSettingsResource_NslbdUwEt 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_W5EweSXEq - name: 'appsettings' -} - -resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' = { - scope: resourceGroup_I6QNkoPsb - name: 'kv-TEST' - location: 'westus' - properties: { - tenantId: '00000000-0000-0000-0000-000000000000' - sku: { - name: 'standard' - family: 'A' - } - } -} - -resource keyVaultAddAccessPolicy_OttgS6uaT 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { - parent: keyVault_CRoMbemLF - name: 'add' - properties: { - accessPolicies: [ - { - tenantId: '00000000-0000-0000-0000-000000000000' - objectId: webSite_W5EweSXEq.identity.principalId - permissions: { - secrets: [ - 'get' - 'list' - ] - } - } - ] - } -} - -resource keyVaultSecret_nMDmVNMVq 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { - parent: keyVault_CRoMbemLF - name: 'sqlAdminPassword' - properties: { - value: sqlAdminPassword - } -} - -resource keyVaultSecret_PrlUnEuAz 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { - parent: keyVault_CRoMbemLF - name: 'appUserPassword' - properties: { - value: appUserPassword - } -} - -resource sqlServer_zjdvvB2wl 'Microsoft.Sql/servers@2022-08-01-preview' = { - scope: resourceGroup_I6QNkoPsb - name: 'sqlserver-TEST' - location: 'westus' - properties: { - administratorLogin: 'sqladmin' - administratorLoginPassword: sqlAdminPassword - version: '12.0' - minimalTlsVersion: '1.2' - publicNetworkAccess: 'Enabled' - } -} - -resource sqlDatabase_U7NzorRJT 'Microsoft.Sql/servers/databases@2022-08-01-preview' = { - parent: sqlServer_zjdvvB2wl - name: 'db-TEST' - location: 'westus' - properties: { - } -} - -resource keyVaultSecret_NP8ELZpgb 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { - parent: keyVault_CRoMbemLF - name: 'connectionString' - properties: { - value: 'Server=${sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName}; Database=${sqlDatabase_U7NzorRJT.name}; User=appUser; Password=${appUserPassword}' - } -} - -resource sqlFirewallRule_eS4m8st65 'Microsoft.Sql/servers/firewallRules@2020-11-01-preview' = { - parent: sqlServer_zjdvvB2wl - name: 'firewallRule-TEST' - properties: { - startIpAddress: '0.0.0.1' - endIpAddress: '255.255.255.254' - } -} - -resource deploymentScript_3Zq2Pl8xa 'Microsoft.Resources/deploymentScripts@2020-10-01' = { - scope: resourceGroup_I6QNkoPsb - name: 'cliScript-TEST' - location: 'westus' - kind: 'AzureCLI' - properties: { - cleanupPreference: 'OnSuccess' - scriptContent: ''' -wget https://github.com/microsoft/go-sqlcmd/releases/download/v0.8.1/sqlcmd-v0.8.1-linux-x64.tar.bz2 -tar x -f sqlcmd-v0.8.1-linux-x64.tar.bz2 -C . -cat < ./initDb.sql -drop user ${APPUSERNAME} -go -create user ${APPUSERNAME} with password = '${APPUSERPASSWORD}' -go -alter role db_owner add member ${APPUSERNAME} -go -SCRIPT_END -./sqlcmd -S ${DBSERVER} -d ${DBNAME} -U ${SQLADMIN} -i ./initDb.sql''' - environmentVariables: [ - { - name: 'APPUSERNAME' - value: 'appUser' - } - { - name: 'APPUSERPASSWORD' - secureValue: '_p_.appUserPassword' - } - { - name: 'DBNAME' - value: '_p_.sqlDatabase_U7NzorRJT.name' - } - { - name: 'DBSERVER' - value: '_p_.sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName' - } - { - name: 'SQLCMDPASSWORD' - secureValue: '_p_.sqlAdminPassword' - } - { - name: 'SQLADMIN' - value: 'sqlAdmin' - } - ] - retentionInterval: 'PT1H' - timeout: 'PT5M' - azCliVersion: '2.37.0' - } -} - -resource webSite_4pzZqR2OO 'Microsoft.Web/sites@2021-02-01' = { - scope: resourceGroup_I6QNkoPsb - name: 'backEnd-TEST' - location: 'westus' - identity: { - } - kind: 'app,linux' - properties: { - serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' - siteConfig: { - linuxFxVersion: 'dotnetcore|6.0' - alwaysOn: true - appCommandLine: '' - experiments: { - } - cors: { - allowedOrigins: [ - 'https://portal.azure.com' - 'https://ms.portal.azure.com' - ] - } - minTlsVersion: '1.2' - ftpsState: 'FtpsOnly' - } - httpsOnly: true - } -} - -resource applicationSettingsResource_Pfdqa0OdT 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_4pzZqR2OO - name: 'appsettings' - properties: { - SCM_DO_BUILD_DURING_DEPLOYMENT: 'False' - ENABLE_ORYX_BUILD: 'True' - } -} - -resource webSiteConfigLogs_giqxapQs0 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_W5EweSXEq - name: 'logs' - properties: { - applicationLogs: { - fileSystem: { - level: 'Verbose' - } - } - httpLogs: { - fileSystem: { - retentionInMb: 35 - retentionInDays: 1 - enabled: true - } - } - failedRequestsTracing: { - enabled: true - } - detailedErrorMessages: { - enabled: true - } + params: { + sqlAdminPassword: sqlAdminPassword + appUserPassword: appUserPassword } } -output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_W5EweSXEq.identity.principalId +output SERVICE_API_IDENTITY_PRINCIPAL_ID string = rg_TEST.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep new file mode 100644 index 0000000000000..d14361b48c20d --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep @@ -0,0 +1,248 @@ +@secure() +@description('SQL Server administrator password') +param sqlAdminPassword string + +@secure() +@description('Application user password') +param appUserPassword string + + +resource appServicePlan_kjMZSF1FP 'Microsoft.Web/serverfarms@2021-02-01' = { + name: 'appServicePlan-TEST' + location: 'westus' + sku: { + name: 'B1' + } + properties: { + reserved: true + } +} + +resource webSite_W5EweSXEq 'Microsoft.Web/sites@2021-02-01' = { + name: 'frontEnd-TEST' + location: 'westus' + identity: { + } + kind: 'app,linux' + properties: { + serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' + siteConfig: { + linuxFxVersion: 'node|18-lts' + alwaysOn: true + appCommandLine: './entrypoint.sh -o ./env-config.js && pm2 serve /home/site/wwwroot --no-daemon --spa' + experiments: { + } + cors: { + allowedOrigins: [ + 'https://portal.azure.com' + 'https://ms.portal.azure.com' + ] + } + minTlsVersion: '1.2' + ftpsState: 'FtpsOnly' + } + httpsOnly: true + } +} + +resource applicationSettingsResource_NslbdUwEt 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_W5EweSXEq + name: 'appsettings' +} + +resource webSiteConfigLogs_giqxapQs0 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_W5EweSXEq + name: 'logs' + properties: { + applicationLogs: { + fileSystem: { + level: 'Verbose' + } + } + httpLogs: { + fileSystem: { + retentionInMb: 35 + retentionInDays: 1 + enabled: true + } + } + failedRequestsTracing: { + enabled: true + } + detailedErrorMessages: { + enabled: true + } + } +} + +resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' = { + name: 'kv-TEST' + location: 'westus' + properties: { + tenantId: '00000000-0000-0000-0000-000000000000' + sku: { + name: 'standard' + family: 'A' + } + } +} + +resource keyVaultAddAccessPolicy_OttgS6uaT 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { + parent: keyVault_CRoMbemLF + name: 'add' + properties: { + accessPolicies: [ + { + tenantId: '00000000-0000-0000-0000-000000000000' + objectId: webSite_W5EweSXEq.identity.principalId + permissions: { + secrets: [ + 'get' + 'list' + ] + } + } + ] + } +} + +resource keyVaultSecret_nMDmVNMVq 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { + parent: keyVault_CRoMbemLF + name: 'sqlAdminPassword' + properties: { + value: sqlAdminPassword + } +} + +resource keyVaultSecret_PrlUnEuAz 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { + parent: keyVault_CRoMbemLF + name: 'appUserPassword' + properties: { + value: appUserPassword + } +} + +resource keyVaultSecret_NP8ELZpgb 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { + parent: keyVault_CRoMbemLF + name: 'connectionString' + properties: { + value: 'Server=${sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName}; Database=${sqlDatabase_U7NzorRJT.name}; User=appUser; Password=${appUserPassword}' + } +} + +resource sqlServer_zjdvvB2wl 'Microsoft.Sql/servers@2022-08-01-preview' = { + name: 'sqlserver-TEST' + location: 'westus' + properties: { + administratorLogin: 'sqladmin' + administratorLoginPassword: sqlAdminPassword + version: '12.0' + minimalTlsVersion: '1.2' + publicNetworkAccess: 'Enabled' + } +} + +resource sqlDatabase_U7NzorRJT 'Microsoft.Sql/servers/databases@2022-08-01-preview' = { + parent: sqlServer_zjdvvB2wl + name: 'db-TEST' + location: 'westus' + properties: { + } +} + +resource sqlFirewallRule_eS4m8st65 'Microsoft.Sql/servers/firewallRules@2020-11-01-preview' = { + parent: sqlServer_zjdvvB2wl + name: 'firewallRule-TEST' + properties: { + startIpAddress: '0.0.0.1' + endIpAddress: '255.255.255.254' + } +} + +resource deploymentScript_3Zq2Pl8xa 'Microsoft.Resources/deploymentScripts@2020-10-01' = { + name: 'cliScript-TEST' + location: 'westus' + kind: 'AzureCLI' + properties: { + cleanupPreference: 'OnSuccess' + scriptContent: ''' +wget https://github.com/microsoft/go-sqlcmd/releases/download/v0.8.1/sqlcmd-v0.8.1-linux-x64.tar.bz2 +tar x -f sqlcmd-v0.8.1-linux-x64.tar.bz2 -C . +cat < ./initDb.sql +drop user ${APPUSERNAME} +go +create user ${APPUSERNAME} with password = '${APPUSERPASSWORD}' +go +alter role db_owner add member ${APPUSERNAME} +go +SCRIPT_END +./sqlcmd -S ${DBSERVER} -d ${DBNAME} -U ${SQLADMIN} -i ./initDb.sql''' + environmentVariables: [ + { + name: 'APPUSERNAME' + value: 'appUser' + } + { + name: 'APPUSERPASSWORD' + secureValue: '_p_.appUserPassword' + } + { + name: 'DBNAME' + value: '_p_.sqlDatabase_U7NzorRJT.name' + } + { + name: 'DBSERVER' + value: '_p_.sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName' + } + { + name: 'SQLCMDPASSWORD' + secureValue: '_p_.sqlAdminPassword' + } + { + name: 'SQLADMIN' + value: 'sqlAdmin' + } + ] + retentionInterval: 'PT1H' + timeout: 'PT5M' + azCliVersion: '2.37.0' + } +} + +resource webSite_4pzZqR2OO 'Microsoft.Web/sites@2021-02-01' = { + name: 'backEnd-TEST' + location: 'westus' + identity: { + } + kind: 'app,linux' + properties: { + serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' + siteConfig: { + linuxFxVersion: 'dotnetcore|6.0' + alwaysOn: true + appCommandLine: '' + experiments: { + } + cors: { + allowedOrigins: [ + 'https://portal.azure.com' + 'https://ms.portal.azure.com' + ] + } + minTlsVersion: '1.2' + ftpsState: 'FtpsOnly' + } + httpsOnly: true + } +} + +resource applicationSettingsResource_Pfdqa0OdT 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_4pzZqR2OO + name: 'appsettings' + properties: { + SCM_DO_BUILD_DURING_DEPLOYMENT: 'False' + ENABLE_ORYX_BUILD: 'True' + } +} + +output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_W5EweSXEq.identity.principalId diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep index 748389309f98d..a1dceb43a30e4 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep @@ -1,4 +1,4 @@ -targetScope = subscription +targetScope = 'subscription' @secure() @description('SQL Server administrator password') @@ -18,57 +18,8 @@ resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' } } -resource appServicePlan_kjMZSF1FP 'Microsoft.Web/serverfarms@2021-02-01' = { - scope: resourceGroup_I6QNkoPsb - name: 'appServicePlan-TEST' - location: 'westus' - sku: { - name: 'B1' - } - properties: { - reserved: true - } -} - -resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' = { - scope: resourceGroup_I6QNkoPsb - name: 'kv-TEST' - location: 'westus' - properties: { - tenantId: '00000000-0000-0000-0000-000000000000' - sku: { - name: 'standard' - family: 'A' - } - } -} - -resource keyVaultAddAccessPolicy_OttgS6uaT 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { - parent: keyVault_CRoMbemLF - name: 'add' - properties: { - accessPolicies: [ - { - tenantId: '00000000-0000-0000-0000-000000000000' - objectId: TestFrontEndWebSite.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID - permissions: { - secrets: [ - 'get' - 'list' - ] - } - } - ] - } -} - -module TestFrontEndWebSite './resources/TestFrontEndWebSite/TestFrontEndWebSite.bicep' = { - name: 'TestFrontEndWebSite' - scope: resourceGroup_I6QNkoPsb -} - -module TestCommonSqlDatabase './resources/TestCommonSqlDatabase/TestCommonSqlDatabase.bicep' = { - name: 'TestCommonSqlDatabase' +module rg_TEST './resources/rg_TEST/rg_TEST.bicep' = { + name: 'rg_TEST' scope: resourceGroup_I6QNkoPsb params: { sqlAdminPassword: sqlAdminPassword @@ -76,9 +27,4 @@ module TestCommonSqlDatabase './resources/TestCommonSqlDatabase/TestCommonSqlDat } } -module TestBackEndWebSite './resources/TestBackEndWebSite/TestBackEndWebSite.bicep' = { - name: 'TestBackEndWebSite' - scope: resourceGroup_I6QNkoPsb -} - -output SERVICE_API_IDENTITY_PRINCIPAL_ID string = TestFrontEndWebSite.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID +output SERVICE_API_IDENTITY_PRINCIPAL_ID string = rg_TEST.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestBackEndWebSite/TestBackEndWebSite.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestBackEndWebSite/TestBackEndWebSite.bicep deleted file mode 100644 index 6922472a5c1f4..0000000000000 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestBackEndWebSite/TestBackEndWebSite.bicep +++ /dev/null @@ -1,40 +0,0 @@ - -resource appServicePlan_kjMZSF1FP 'Microsoft.Web/serverfarms@2021-02-01' existing = { - name: 'appServicePlan_kjMZSF1FP' -} - -resource webSite_4pzZqR2OO 'Microsoft.Web/sites@2021-02-01' = { - name: 'backEnd-TEST' - location: 'westus' - identity: { - } - kind: 'app,linux' - properties: { - serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' - siteConfig: { - linuxFxVersion: 'dotnetcore|6.0' - alwaysOn: true - appCommandLine: '' - experiments: { - } - cors: { - allowedOrigins: [ - 'https://portal.azure.com' - 'https://ms.portal.azure.com' - ] - } - minTlsVersion: '1.2' - ftpsState: 'FtpsOnly' - } - httpsOnly: true - } -} - -resource applicationSettingsResource_Pfdqa0OdT 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_4pzZqR2OO - name: 'appsettings' - properties: { - SCM_DO_BUILD_DURING_DEPLOYMENT: 'False' - ENABLE_ORYX_BUILD: 'True' - } -} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestCommonSqlDatabase/TestCommonSqlDatabase.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestCommonSqlDatabase/TestCommonSqlDatabase.bicep deleted file mode 100644 index ff3a54c940cf5..0000000000000 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestCommonSqlDatabase/TestCommonSqlDatabase.bicep +++ /dev/null @@ -1,115 +0,0 @@ -@secure() -@description('SQL Server administrator password') -param sqlAdminPassword string - -@secure() -@description('Application user password') -param appUserPassword string - - -resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' existing = { - name: 'keyVault_CRoMbemLF' -} - -resource keyVaultSecret_nMDmVNMVq 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { - parent: keyVault_CRoMbemLF - name: 'sqlAdminPassword' - properties: { - value: sqlAdminPassword - } -} - -resource keyVaultSecret_PrlUnEuAz 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { - parent: keyVault_CRoMbemLF - name: 'appUserPassword' - properties: { - value: appUserPassword - } -} - -resource sqlServer_zjdvvB2wl 'Microsoft.Sql/servers@2022-08-01-preview' = { - name: 'sqlserver-TEST' - location: 'westus' - properties: { - administratorLogin: 'sqladmin' - administratorLoginPassword: sqlAdminPassword - version: '12.0' - minimalTlsVersion: '1.2' - publicNetworkAccess: 'Enabled' - } -} - -resource sqlDatabase_U7NzorRJT 'Microsoft.Sql/servers/databases@2022-08-01-preview' = { - parent: sqlServer_zjdvvB2wl - name: 'db-TEST' - location: 'westus' - properties: { - } -} - -resource keyVaultSecret_NP8ELZpgb 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { - parent: keyVault_CRoMbemLF - name: 'connectionString' - properties: { - value: 'Server=${sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName}; Database=${sqlDatabase_U7NzorRJT.name}; User=appUser; Password=${appUserPassword}' - } -} - -resource sqlFirewallRule_eS4m8st65 'Microsoft.Sql/servers/firewallRules@2020-11-01-preview' = { - parent: sqlServer_zjdvvB2wl - name: 'firewallRule-TEST' - properties: { - startIpAddress: '0.0.0.1' - endIpAddress: '255.255.255.254' - } -} - -resource deploymentScript_3Zq2Pl8xa 'Microsoft.Resources/deploymentScripts@2020-10-01' = { - name: 'cliScript-TEST' - location: 'westus' - kind: 'AzureCLI' - properties: { - cleanupPreference: 'OnSuccess' - scriptContent: ''' -wget https://github.com/microsoft/go-sqlcmd/releases/download/v0.8.1/sqlcmd-v0.8.1-linux-x64.tar.bz2 -tar x -f sqlcmd-v0.8.1-linux-x64.tar.bz2 -C . -cat < ./initDb.sql -drop user ${APPUSERNAME} -go -create user ${APPUSERNAME} with password = '${APPUSERPASSWORD}' -go -alter role db_owner add member ${APPUSERNAME} -go -SCRIPT_END -./sqlcmd -S ${DBSERVER} -d ${DBNAME} -U ${SQLADMIN} -i ./initDb.sql''' - environmentVariables: [ - { - name: 'APPUSERNAME' - value: 'appUser' - } - { - name: 'APPUSERPASSWORD' - secureValue: '_p_.appUserPassword' - } - { - name: 'DBNAME' - value: '_p_.sqlDatabase_U7NzorRJT.name' - } - { - name: 'DBSERVER' - value: '_p_.sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName' - } - { - name: 'SQLCMDPASSWORD' - secureValue: '_p_.sqlAdminPassword' - } - { - name: 'SQLADMIN' - value: 'sqlAdmin' - } - ] - retentionInterval: 'PT1H' - timeout: 'PT5M' - azCliVersion: '2.37.0' - } -} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestFrontEndWebSite/TestFrontEndWebSite.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestFrontEndWebSite/TestFrontEndWebSite.bicep deleted file mode 100644 index 70b2a2a6da499..0000000000000 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestFrontEndWebSite/TestFrontEndWebSite.bicep +++ /dev/null @@ -1,67 +0,0 @@ - -resource appServicePlan_kjMZSF1FP 'Microsoft.Web/serverfarms@2021-02-01' existing = { - name: 'appServicePlan_kjMZSF1FP' -} - -resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' existing = { - name: 'keyVault_CRoMbemLF' -} - -resource webSite_W5EweSXEq 'Microsoft.Web/sites@2021-02-01' = { - name: 'frontEnd-TEST' - location: 'westus' - identity: { - } - kind: 'app,linux' - properties: { - serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' - siteConfig: { - linuxFxVersion: 'node|18-lts' - alwaysOn: true - appCommandLine: './entrypoint.sh -o ./env-config.js && pm2 serve /home/site/wwwroot --no-daemon --spa' - experiments: { - } - cors: { - allowedOrigins: [ - 'https://portal.azure.com' - 'https://ms.portal.azure.com' - ] - } - minTlsVersion: '1.2' - ftpsState: 'FtpsOnly' - } - httpsOnly: true - } -} - -resource applicationSettingsResource_NslbdUwEt 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_W5EweSXEq - name: 'appsettings' -} - -resource webSiteConfigLogs_giqxapQs0 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_W5EweSXEq - name: 'logs' - properties: { - applicationLogs: { - fileSystem: { - level: 'Verbose' - } - } - httpLogs: { - fileSystem: { - retentionInMb: 35 - retentionInDays: 1 - enabled: true - } - } - failedRequestsTracing: { - enabled: true - } - detailedErrorMessages: { - enabled: true - } - } -} - -output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_W5EweSXEq.identity.principalId diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep new file mode 100644 index 0000000000000..5e9fd39b4c484 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep @@ -0,0 +1,248 @@ +@secure() +@description('SQL Server administrator password') +param sqlAdminPassword string + +@secure() +@description('Application user password') +param appUserPassword string + + +resource appServicePlan_kjMZSF1FP 'Microsoft.Web/serverfarms@2021-02-01' = { + name: 'appServicePlan-TEST' + location: 'westus' + sku: { + name: 'B1' + } + properties: { + reserved: true + } +} + +resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' = { + name: 'kv-TEST' + location: 'westus' + properties: { + tenantId: '00000000-0000-0000-0000-000000000000' + sku: { + name: 'standard' + family: 'A' + } + } +} + +resource keyVaultAddAccessPolicy_OttgS6uaT 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { + parent: keyVault_CRoMbemLF + name: 'add' + properties: { + accessPolicies: [ + { + tenantId: '00000000-0000-0000-0000-000000000000' + objectId: webSite_W5EweSXEq.identity.principalId + permissions: { + secrets: [ + 'get' + 'list' + ] + } + } + ] + } +} + +resource keyVaultSecret_nMDmVNMVq 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { + parent: keyVault_CRoMbemLF + name: 'sqlAdminPassword' + properties: { + value: sqlAdminPassword + } +} + +resource keyVaultSecret_PrlUnEuAz 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { + parent: keyVault_CRoMbemLF + name: 'appUserPassword' + properties: { + value: appUserPassword + } +} + +resource keyVaultSecret_NP8ELZpgb 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { + parent: keyVault_CRoMbemLF + name: 'connectionString' + properties: { + value: 'Server=${sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName}; Database=${sqlDatabase_U7NzorRJT.name}; User=appUser; Password=${appUserPassword}' + } +} + +resource webSite_W5EweSXEq 'Microsoft.Web/sites@2021-02-01' = { + name: 'frontEnd-TEST' + location: 'westus' + identity: { + } + kind: 'app,linux' + properties: { + serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' + siteConfig: { + linuxFxVersion: 'node|18-lts' + alwaysOn: true + appCommandLine: './entrypoint.sh -o ./env-config.js && pm2 serve /home/site/wwwroot --no-daemon --spa' + experiments: { + } + cors: { + allowedOrigins: [ + 'https://portal.azure.com' + 'https://ms.portal.azure.com' + ] + } + minTlsVersion: '1.2' + ftpsState: 'FtpsOnly' + } + httpsOnly: true + } +} + +resource applicationSettingsResource_NslbdUwEt 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_W5EweSXEq + name: 'appsettings' +} + +resource webSiteConfigLogs_giqxapQs0 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_W5EweSXEq + name: 'logs' + properties: { + applicationLogs: { + fileSystem: { + level: 'Verbose' + } + } + httpLogs: { + fileSystem: { + retentionInMb: 35 + retentionInDays: 1 + enabled: true + } + } + failedRequestsTracing: { + enabled: true + } + detailedErrorMessages: { + enabled: true + } + } +} + +resource sqlServer_zjdvvB2wl 'Microsoft.Sql/servers@2022-08-01-preview' = { + name: 'sqlserver-TEST' + location: 'westus' + properties: { + administratorLogin: 'sqladmin' + administratorLoginPassword: sqlAdminPassword + version: '12.0' + minimalTlsVersion: '1.2' + publicNetworkAccess: 'Enabled' + } +} + +resource sqlDatabase_U7NzorRJT 'Microsoft.Sql/servers/databases@2022-08-01-preview' = { + parent: sqlServer_zjdvvB2wl + name: 'db-TEST' + location: 'westus' + properties: { + } +} + +resource sqlFirewallRule_eS4m8st65 'Microsoft.Sql/servers/firewallRules@2020-11-01-preview' = { + parent: sqlServer_zjdvvB2wl + name: 'firewallRule-TEST' + properties: { + startIpAddress: '0.0.0.1' + endIpAddress: '255.255.255.254' + } +} + +resource deploymentScript_3Zq2Pl8xa 'Microsoft.Resources/deploymentScripts@2020-10-01' = { + name: 'cliScript-TEST' + location: 'westus' + kind: 'AzureCLI' + properties: { + cleanupPreference: 'OnSuccess' + scriptContent: ''' +wget https://github.com/microsoft/go-sqlcmd/releases/download/v0.8.1/sqlcmd-v0.8.1-linux-x64.tar.bz2 +tar x -f sqlcmd-v0.8.1-linux-x64.tar.bz2 -C . +cat < ./initDb.sql +drop user ${APPUSERNAME} +go +create user ${APPUSERNAME} with password = '${APPUSERPASSWORD}' +go +alter role db_owner add member ${APPUSERNAME} +go +SCRIPT_END +./sqlcmd -S ${DBSERVER} -d ${DBNAME} -U ${SQLADMIN} -i ./initDb.sql''' + environmentVariables: [ + { + name: 'APPUSERNAME' + value: 'appUser' + } + { + name: 'APPUSERPASSWORD' + secureValue: '_p_.appUserPassword' + } + { + name: 'DBNAME' + value: '_p_.sqlDatabase_U7NzorRJT.name' + } + { + name: 'DBSERVER' + value: '_p_.sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName' + } + { + name: 'SQLCMDPASSWORD' + secureValue: '_p_.sqlAdminPassword' + } + { + name: 'SQLADMIN' + value: 'sqlAdmin' + } + ] + retentionInterval: 'PT1H' + timeout: 'PT5M' + azCliVersion: '2.37.0' + } +} + +resource webSite_4pzZqR2OO 'Microsoft.Web/sites@2021-02-01' = { + name: 'backEnd-TEST' + location: 'westus' + identity: { + } + kind: 'app,linux' + properties: { + serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' + siteConfig: { + linuxFxVersion: 'dotnetcore|6.0' + alwaysOn: true + appCommandLine: '' + experiments: { + } + cors: { + allowedOrigins: [ + 'https://portal.azure.com' + 'https://ms.portal.azure.com' + ] + } + minTlsVersion: '1.2' + ftpsState: 'FtpsOnly' + } + httpsOnly: true + } +} + +resource applicationSettingsResource_Pfdqa0OdT 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_4pzZqR2OO + name: 'appsettings' + properties: { + SCM_DO_BUILD_DURING_DEPLOYMENT: 'False' + ENABLE_ORYX_BUILD: 'True' + } +} + +output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_W5EweSXEq.identity.principalId diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep index ef77e05ab3243..b05d876d14113 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep @@ -1,12 +1,4 @@ -targetScope = subscription - -@secure() -@description('SQL Server administrator password') -param sqlAdminPassword string - -@secure() -@description('Application user password') -param appUserPassword string +targetScope = 'subscription' resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { @@ -18,11 +10,7 @@ resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' } } -module TestWebSiteWithSqlBackEnd './resources/TestWebSiteWithSqlBackEnd/TestWebSiteWithSqlBackEnd.bicep' = { - name: 'TestWebSiteWithSqlBackEnd' +module rg_TEST './resources/rg_TEST/rg_TEST.bicep' = { + name: 'rg_TEST' scope: resourceGroup_I6QNkoPsb - params: { - sqlAdminPassword: sqlAdminPassword - appUserPassword: appUserPassword - } } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestBackEndWebSite/TestBackEndWebSite.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestBackEndWebSite/TestBackEndWebSite.bicep deleted file mode 100644 index 6922472a5c1f4..0000000000000 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestBackEndWebSite/TestBackEndWebSite.bicep +++ /dev/null @@ -1,40 +0,0 @@ - -resource appServicePlan_kjMZSF1FP 'Microsoft.Web/serverfarms@2021-02-01' existing = { - name: 'appServicePlan_kjMZSF1FP' -} - -resource webSite_4pzZqR2OO 'Microsoft.Web/sites@2021-02-01' = { - name: 'backEnd-TEST' - location: 'westus' - identity: { - } - kind: 'app,linux' - properties: { - serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' - siteConfig: { - linuxFxVersion: 'dotnetcore|6.0' - alwaysOn: true - appCommandLine: '' - experiments: { - } - cors: { - allowedOrigins: [ - 'https://portal.azure.com' - 'https://ms.portal.azure.com' - ] - } - minTlsVersion: '1.2' - ftpsState: 'FtpsOnly' - } - httpsOnly: true - } -} - -resource applicationSettingsResource_Pfdqa0OdT 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_4pzZqR2OO - name: 'appsettings' - properties: { - SCM_DO_BUILD_DURING_DEPLOYMENT: 'False' - ENABLE_ORYX_BUILD: 'True' - } -} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestCommonSqlDatabase/TestCommonSqlDatabase.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestCommonSqlDatabase/TestCommonSqlDatabase.bicep deleted file mode 100644 index ff3a54c940cf5..0000000000000 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestCommonSqlDatabase/TestCommonSqlDatabase.bicep +++ /dev/null @@ -1,115 +0,0 @@ -@secure() -@description('SQL Server administrator password') -param sqlAdminPassword string - -@secure() -@description('Application user password') -param appUserPassword string - - -resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' existing = { - name: 'keyVault_CRoMbemLF' -} - -resource keyVaultSecret_nMDmVNMVq 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { - parent: keyVault_CRoMbemLF - name: 'sqlAdminPassword' - properties: { - value: sqlAdminPassword - } -} - -resource keyVaultSecret_PrlUnEuAz 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { - parent: keyVault_CRoMbemLF - name: 'appUserPassword' - properties: { - value: appUserPassword - } -} - -resource sqlServer_zjdvvB2wl 'Microsoft.Sql/servers@2022-08-01-preview' = { - name: 'sqlserver-TEST' - location: 'westus' - properties: { - administratorLogin: 'sqladmin' - administratorLoginPassword: sqlAdminPassword - version: '12.0' - minimalTlsVersion: '1.2' - publicNetworkAccess: 'Enabled' - } -} - -resource sqlDatabase_U7NzorRJT 'Microsoft.Sql/servers/databases@2022-08-01-preview' = { - parent: sqlServer_zjdvvB2wl - name: 'db-TEST' - location: 'westus' - properties: { - } -} - -resource keyVaultSecret_NP8ELZpgb 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { - parent: keyVault_CRoMbemLF - name: 'connectionString' - properties: { - value: 'Server=${sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName}; Database=${sqlDatabase_U7NzorRJT.name}; User=appUser; Password=${appUserPassword}' - } -} - -resource sqlFirewallRule_eS4m8st65 'Microsoft.Sql/servers/firewallRules@2020-11-01-preview' = { - parent: sqlServer_zjdvvB2wl - name: 'firewallRule-TEST' - properties: { - startIpAddress: '0.0.0.1' - endIpAddress: '255.255.255.254' - } -} - -resource deploymentScript_3Zq2Pl8xa 'Microsoft.Resources/deploymentScripts@2020-10-01' = { - name: 'cliScript-TEST' - location: 'westus' - kind: 'AzureCLI' - properties: { - cleanupPreference: 'OnSuccess' - scriptContent: ''' -wget https://github.com/microsoft/go-sqlcmd/releases/download/v0.8.1/sqlcmd-v0.8.1-linux-x64.tar.bz2 -tar x -f sqlcmd-v0.8.1-linux-x64.tar.bz2 -C . -cat < ./initDb.sql -drop user ${APPUSERNAME} -go -create user ${APPUSERNAME} with password = '${APPUSERPASSWORD}' -go -alter role db_owner add member ${APPUSERNAME} -go -SCRIPT_END -./sqlcmd -S ${DBSERVER} -d ${DBNAME} -U ${SQLADMIN} -i ./initDb.sql''' - environmentVariables: [ - { - name: 'APPUSERNAME' - value: 'appUser' - } - { - name: 'APPUSERPASSWORD' - secureValue: '_p_.appUserPassword' - } - { - name: 'DBNAME' - value: '_p_.sqlDatabase_U7NzorRJT.name' - } - { - name: 'DBSERVER' - value: '_p_.sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName' - } - { - name: 'SQLCMDPASSWORD' - secureValue: '_p_.sqlAdminPassword' - } - { - name: 'SQLADMIN' - value: 'sqlAdmin' - } - ] - retentionInterval: 'PT1H' - timeout: 'PT5M' - azCliVersion: '2.37.0' - } -} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestFrontEndWebSite/TestFrontEndWebSite.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestFrontEndWebSite/TestFrontEndWebSite.bicep deleted file mode 100644 index 70b2a2a6da499..0000000000000 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestFrontEndWebSite/TestFrontEndWebSite.bicep +++ /dev/null @@ -1,67 +0,0 @@ - -resource appServicePlan_kjMZSF1FP 'Microsoft.Web/serverfarms@2021-02-01' existing = { - name: 'appServicePlan_kjMZSF1FP' -} - -resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' existing = { - name: 'keyVault_CRoMbemLF' -} - -resource webSite_W5EweSXEq 'Microsoft.Web/sites@2021-02-01' = { - name: 'frontEnd-TEST' - location: 'westus' - identity: { - } - kind: 'app,linux' - properties: { - serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' - siteConfig: { - linuxFxVersion: 'node|18-lts' - alwaysOn: true - appCommandLine: './entrypoint.sh -o ./env-config.js && pm2 serve /home/site/wwwroot --no-daemon --spa' - experiments: { - } - cors: { - allowedOrigins: [ - 'https://portal.azure.com' - 'https://ms.portal.azure.com' - ] - } - minTlsVersion: '1.2' - ftpsState: 'FtpsOnly' - } - httpsOnly: true - } -} - -resource applicationSettingsResource_NslbdUwEt 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_W5EweSXEq - name: 'appsettings' -} - -resource webSiteConfigLogs_giqxapQs0 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_W5EweSXEq - name: 'logs' - properties: { - applicationLogs: { - fileSystem: { - level: 'Verbose' - } - } - httpLogs: { - fileSystem: { - retentionInMb: 35 - retentionInDays: 1 - enabled: true - } - } - failedRequestsTracing: { - enabled: true - } - detailedErrorMessages: { - enabled: true - } - } -} - -output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_W5EweSXEq.identity.principalId diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestWebSiteWithSqlBackEnd/TestWebSiteWithSqlBackEnd.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestWebSiteWithSqlBackEnd/TestWebSiteWithSqlBackEnd.bicep deleted file mode 100644 index 26593965a6196..0000000000000 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestWebSiteWithSqlBackEnd/TestWebSiteWithSqlBackEnd.bicep +++ /dev/null @@ -1,74 +0,0 @@ -@secure() -@description('SQL Server administrator password') -param sqlAdminPassword string - -@secure() -@description('Application user password') -param appUserPassword string - - -resource appServicePlan_kjMZSF1FP 'Microsoft.Web/serverfarms@2021-02-01' = { - name: 'appServicePlan-TEST' - location: 'westus' - sku: { - name: 'B1' - } - properties: { - reserved: true - } -} - -resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' = { - name: 'kv-TEST' - location: 'westus' - tags: { - key: 'value' - } - properties: { - tenantId: '00000000-0000-0000-0000-000000000000' - sku: { - name: 'standard' - family: 'A' - } - } -} - -resource keyVaultAddAccessPolicy_OttgS6uaT 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { - parent: keyVault_CRoMbemLF - name: 'add' - properties: { - accessPolicies: [ - { - tenantId: '00000000-0000-0000-0000-000000000000' - objectId: TestFrontEndWebSite.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID - permissions: { - secrets: [ - 'get' - 'list' - ] - } - } - ] - } -} - -module TestFrontEndWebSite './resources/TestFrontEndWebSite/TestFrontEndWebSite.bicep' = { - name: 'TestFrontEndWebSite' - scope: resourceGroup_I6QNkoPsb -} - -module TestCommonSqlDatabase './resources/TestCommonSqlDatabase/TestCommonSqlDatabase.bicep' = { - name: 'TestCommonSqlDatabase' - scope: resourceGroup_I6QNkoPsb - params: { - sqlAdminPassword: sqlAdminPassword - appUserPassword: appUserPassword - } -} - -module TestBackEndWebSite './resources/TestBackEndWebSite/TestBackEndWebSite.bicep' = { - name: 'TestBackEndWebSite' - scope: resourceGroup_I6QNkoPsb -} - -output SERVICE_API_IDENTITY_PRINCIPAL_ID string = TestFrontEndWebSite.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep new file mode 100644 index 0000000000000..bc5dadc1f248c --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep @@ -0,0 +1,45 @@ + +resource appServicePlan_kjMZSF1FP 'Microsoft.Web/serverfarms@2021-02-01' = { + name: 'appServicePlan-TEST' + location: 'westus' + sku: { + name: 'B1' + } + properties: { + reserved: true + } +} + +resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' = { + name: 'kv-TEST' + location: 'westus' + tags: { + key: 'value' + } + properties: { + tenantId: '00000000-0000-0000-0000-000000000000' + sku: { + name: 'standard' + family: 'A' + } + } +} + +resource keyVaultAddAccessPolicy_OttgS6uaT 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { + parent: keyVault_CRoMbemLF + name: 'add' + properties: { + accessPolicies: [ + { + tenantId: '00000000-0000-0000-0000-000000000000' + objectId: webSite_W5EweSXEq.identity.principalId + permissions: { + secrets: [ + 'get' + 'list' + ] + } + } + ] + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs index 6a99870be8659..6be02cfe480dd 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs +++ b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs @@ -65,6 +65,17 @@ public void WebSiteUsingL1() WebSiteConfigLogs logs = new WebSiteConfigLogs(infra, "logs", frontEnd); infra.Build(GetOutputPath()); + // var client = new ArmClient(new DefaultAzureCredential()); + // var sub = client.GetSubscriptions() + // .Where(s => s.Data.SubscriptionId == "faa080af-c1d8-40ad-9cce-e1a450ca5b57").Single(); + // var identifier = ArmDeploymentResource.CreateResourceIdentifier(sub.Id, "test"); + // var resource = client.GetArmDeploymentResource(identifier); + // resource.Validate(WaitUntil.Completed, + // new ArmDeploymentContent( + // new ArmDeploymentProperties(ArmDeploymentMode.Complete) + // { + // Template = new BinaryData((object)File.ReadAllText(Path.Combine(GetOutputPath(), "main.bicep"))), + // })); } [Test] @@ -120,6 +131,36 @@ public void StorageBlobDropDown() infra.Build(GetOutputPath()); } + [Test] + public void MultipleSubscriptions() + { + var infra = new TestSubscriptionInfrastructure(); + var sub1 = new Subscription(infra, Guid.NewGuid()); + var sub2 = new Subscription(infra, Guid.NewGuid()); + _ = new ResourceGroup(infra, parent: sub1); + _ = new ResourceGroup(infra, parent: sub2); + infra.Build(GetOutputPath()); + } + + [Test] + public void OutputsSpanningModules() + { + var infra = new TestInfrastructure(); + var rg1 = new ResourceGroup(infra, "rg1"); + var rg2 = new ResourceGroup(infra, "rg2"); + var appServicePlan = infra.AddAppServicePlan(parent: rg1); + WebSite frontEnd1 = new WebSite(infra, "frontEnd", appServicePlan, WebSiteRuntime.Node, "18-lts", parent: rg1); + + var output1 = frontEnd1.AddOutput(data => data.Identity.PrincipalId, "STORAGE_PRINCIPAL_ID"); + var output2 = frontEnd1.AddOutput(data => data.Location, "LOCATION"); + + WebSite frontEnd2 = new WebSite(infra, "frontEnd", appServicePlan, WebSiteRuntime.Node, "18-lts", parent: rg2); + + frontEnd2.AssignParameter(data => data.Identity.PrincipalId, new Parameter(output1.Name)); + frontEnd2.AssignParameter(data => data.Location, new Parameter(output2.Name)); + infra.Build(GetOutputPath()); + } + private static string GetGitRoot() { ProcessStartInfo startInfo = new ProcessStartInfo diff --git a/sdk/provisioning/Azure.Provisioning/tests/TestSubscriptionInfrastructure.cs b/sdk/provisioning/Azure.Provisioning/tests/TestSubscriptionInfrastructure.cs new file mode 100644 index 0000000000000..fd80ae167118f --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/TestSubscriptionInfrastructure.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; + +namespace Azure.Provisioning.Tests +{ + public class TestSubscriptionInfrastructure : Infrastructure + { + public TestSubscriptionInfrastructure() + : base(ConstructScope.Tenant, Guid.Empty, Guid.Empty, "TEST") + { + } + } +} From 54ad6d393190d572940eb545174454fb7744a5f5 Mon Sep 17 00:00:00 2001 From: jolov Date: Fri, 16 Feb 2024 08:43:18 -0800 Subject: [PATCH 02/32] Clean up --- .../Azure.Provisioning/src/Infrastructure.cs | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs b/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs index 1a4024a0f5469..db80082424fdb 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs @@ -69,6 +69,29 @@ private Dictionary> BuildResourceTree() return resourceTree; } + private void VisitResource(Resource resource, Dictionary> resourceTree, HashSet visited) + { + if (!visited.Add(resource)) + { + return; + } + + if (!resourceTree.ContainsKey(resource)) + { + resourceTree[resource] = new List(); + } + + if (resource.Parent != null) + { + if (!resourceTree.ContainsKey(resource.Parent)) + { + resourceTree[resource.Parent] = new List(); + } + resourceTree[resource.Parent].Add(resource); + VisitResource(resource.Parent, resourceTree, visited); + } + } + private void BuildModuleConstructs(Resource resource, Dictionary> resourceTree, ModuleConstruct? parentScope, ref ModuleConstruct? root) { ModuleConstruct? construct = null; @@ -102,12 +125,12 @@ private void BuildModuleConstructs(Resource resource, Dictionary> resourceTree, HashSet visited) - { - if (!visited.Add(resource)) - { - return; - } - - if (!resourceTree.ContainsKey(resource)) - { - resourceTree[resource] = new List(); - } - - if (resource.Parent != null) - { - if (!resourceTree.ContainsKey(resource.Parent)) - { - resourceTree[resource.Parent] = new List(); - } - resourceTree[resource.Parent].Add(resource); - VisitResource(resource.Parent, resourceTree, visited); - } - } - private void WriteConstructsByLevel(Queue constructs, string outputPath) { while (constructs.Count > 0) @@ -241,5 +226,20 @@ private void WriteBicepFile(ModuleConstruct construct, string outputPath) stream.Write(buffer, 0, buffer.Length); #endif } + + private class ModuleConstruct : Construct + { + public ModuleConstruct(Resource resource) + : base( + resource.Scope, + resource is Subscription ? resource.Name : resource.Id.Name.Replace('-', '_'), + ResourceToConstructScope(resource), + subscriptionId: resource is not Tenant ? Guid.Parse(resource.Id.SubscriptionId!) : null, + resourceGroup: resource as ResourceGroup) + { + } + + public bool IsRoot { get; set; } + } } } From 410f3729c07f0ea692ac09779b16666105c7ca25 Mon Sep 17 00:00:00 2001 From: jolov Date: Fri, 16 Feb 2024 09:06:21 -0800 Subject: [PATCH 03/32] remove dead code --- .../Azure.Provisioning/src/Infrastructure.cs | 6 ------ .../Infrastructure/AppConfiguration/main.bicep | 12 +++--------- .../resources/rg_TEST/rg_TEST.bicep | 10 ++++++++++ .../MultipleSubscriptions/main.bicep | 12 ++++++------ .../subscription_epOY9bzbr.bicep | 10 ++++++++++ .../subscription_kIWr5ZL1I.bicep | 10 ++++++++++ .../resources/rg1_TEST/rg1_TEST.bicep | 2 +- .../resources/rg2_TEST/rg2_TEST.bicep | 2 +- .../resources/rg_TEST/rg_TEST.bicep | 10 +++++----- .../resources/rg_TEST/rg_TEST.bicep | 10 +++++----- .../resources/rg_TEST/rg_TEST.bicep | 18 +++++++++--------- .../resources/rg_TEST/rg_TEST.bicep | 18 +++++++++--------- .../resources/rg_TEST/rg_TEST.bicep | 2 +- 13 files changed, 70 insertions(+), 52 deletions(-) create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/resources/rg_TEST/rg_TEST.bicep create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_epOY9bzbr/subscription_epOY9bzbr.bicep create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_kIWr5ZL1I/subscription_kIWr5ZL1I.bicep diff --git a/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs b/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs index db80082424fdb..2cecbf711260b 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs @@ -40,12 +40,6 @@ public void Build(string? outputPath = null) Dictionary> resourceTree = BuildResourceTree(); - var constructs = GetConstructs(true).ToArray(); - foreach (var construct in constructs) - { - construct.GetResources(true); - } - ModuleConstruct? root = null; BuildModuleConstructs(Root, resourceTree, null, ref root); diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/main.bicep index 48aeda971d698..298e5ac002ff5 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/main.bicep @@ -1,4 +1,4 @@ -targetScope = subscription +targetScope = 'subscription' resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { @@ -9,13 +9,7 @@ resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' } } -resource appConfigurationStore_sgecYnln3 'Microsoft.AppConfiguration/configurationStores@2023-03-01' = { +module rg_TEST './resources/rg_TEST/rg_TEST.bicep' = { + name: 'rg_TEST' scope: resourceGroup_I6QNkoPsb - name: 'store-TEST' - location: 'westus' - sku: { - name: 'free' - } - properties: { - } } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/resources/rg_TEST/rg_TEST.bicep new file mode 100644 index 0000000000000..31221f07fe431 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/resources/rg_TEST/rg_TEST.bicep @@ -0,0 +1,10 @@ + +resource appConfigurationStore_sgecYnln3 'Microsoft.AppConfiguration/configurationStores@2023-03-01' = { + name: 'store-TEST' + location: 'westus' + sku: { + name: 'free' + } + properties: { + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep index e6e626c905bb2..724354e8d2b31 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep @@ -1,12 +1,12 @@ targetScope = 'tenant' -module subscription_LDRPSoVXn './resources/subscription_LDRPSoVXn/subscription_LDRPSoVXn.bicep' = { - name: 'subscription_LDRPSoVXn' - scope: subscription('subscription_LDRPSoVXn') +module subscription_kIWr5ZL1I './resources/subscription_kIWr5ZL1I/subscription_kIWr5ZL1I.bicep' = { + name: 'subscription_kIWr5ZL1I' + scope: subscription('subscription_kIWr5ZL1I') } -module subscription_0n8qEB2gZ './resources/subscription_0n8qEB2gZ/subscription_0n8qEB2gZ.bicep' = { - name: 'subscription_0n8qEB2gZ' - scope: subscription('subscription_0n8qEB2gZ') +module subscription_epOY9bzbr './resources/subscription_epOY9bzbr/subscription_epOY9bzbr.bicep' = { + name: 'subscription_epOY9bzbr' + scope: subscription('subscription_epOY9bzbr') } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_epOY9bzbr/subscription_epOY9bzbr.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_epOY9bzbr/subscription_epOY9bzbr.bicep new file mode 100644 index 0000000000000..0ca05e2e731b5 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_epOY9bzbr/subscription_epOY9bzbr.bicep @@ -0,0 +1,10 @@ +targetScope = 'subscription' + + +resource resourceGroup_SzjQXHS7M 'Microsoft.Resources/resourceGroups@2023-07-01' = { + name: 'rg-TEST' + location: 'westus' + tags: { + azd-env-name: 'TEST' + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_kIWr5ZL1I/subscription_kIWr5ZL1I.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_kIWr5ZL1I/subscription_kIWr5ZL1I.bicep new file mode 100644 index 0000000000000..dad2d47267ec3 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_kIWr5ZL1I/subscription_kIWr5ZL1I.bicep @@ -0,0 +1,10 @@ +targetScope = 'subscription' + + +resource resourceGroup_gxKtbEVWD 'Microsoft.Resources/resourceGroups@2023-07-01' = { + name: 'rg-TEST' + location: 'westus' + tags: { + azd-env-name: 'TEST' + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep index ddf39fdb6b1d1..8fd8fce8da3e5 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep @@ -37,7 +37,7 @@ resource webSite_dOTaZfna6 'Microsoft.Web/sites@2021-02-01' = { } } -resource applicationSettingsResource_lzuRUWkeF 'Microsoft.Web/sites/config@2021-02-01' = { +resource applicationSettingsResource_MAMFSSuFs 'Microsoft.Web/sites/config@2021-02-01' = { parent: webSite_dOTaZfna6 name: 'appsettings' } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg2_TEST/rg2_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg2_TEST/rg2_TEST.bicep index c184fb6ae804f..b506f40b2de1a 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg2_TEST/rg2_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg2_TEST/rg2_TEST.bicep @@ -32,7 +32,7 @@ resource webSite_80I4ejz5T 'Microsoft.Web/sites@2021-02-01' = { } } -resource applicationSettingsResource_kPTV48HdO 'Microsoft.Web/sites/config@2021-02-01' = { +resource applicationSettingsResource_eTrLWYWog 'Microsoft.Web/sites/config@2021-02-01' = { parent: webSite_80I4ejz5T name: 'appsettings' } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep index 5f8645ed8eac9..48c4e0163290b 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_S5qJniO7O 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-5fa1326a602c47' +resource storageAccount_0S3JP33rx 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-7d403f703f2345' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,9 +10,9 @@ resource storageAccount_S5qJniO7O 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_NVGSBDZv1 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_S5qJniO7O - name: 'photos-TEST' +resource blobService_N4xqIZXcl 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_0S3JP33rx + name: 'default' properties: { cors: { } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep index 8d1eaa5d93cd9..b07edb795d94d 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_g16JGJUrY 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-6c337c3efac749' +resource storageAccount_2jsIm80wf 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-9848177a84ad43' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,9 +10,9 @@ resource storageAccount_g16JGJUrY 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_f8CmSjkLj 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_g16JGJUrY - name: 'photos-TEST' +resource blobService_6NwKBOBDn 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_2jsIm80wf + name: 'default' properties: { cors: { } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep index d14361b48c20d..536cb6a6e93f7 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep @@ -45,7 +45,7 @@ resource webSite_W5EweSXEq 'Microsoft.Web/sites@2021-02-01' = { } } -resource applicationSettingsResource_NslbdUwEt 'Microsoft.Web/sites/config@2021-02-01' = { +resource applicationSettingsResource_9BG7vUQd2 'Microsoft.Web/sites/config@2021-02-01' = { parent: webSite_W5EweSXEq name: 'appsettings' } @@ -87,7 +87,7 @@ resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' = { } } -resource keyVaultAddAccessPolicy_OttgS6uaT 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { +resource keyVaultAddAccessPolicy_NWCGclP20 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { parent: keyVault_CRoMbemLF name: 'add' properties: { @@ -106,25 +106,25 @@ resource keyVaultAddAccessPolicy_OttgS6uaT 'Microsoft.KeyVault/vaults/accessPoli } } -resource keyVaultSecret_nMDmVNMVq 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { +resource keyVaultSecret_NmXfhaHvM 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { parent: keyVault_CRoMbemLF - name: 'sqlAdminPassword' + name: 'sqlAdminPassword-TEST' properties: { value: sqlAdminPassword } } -resource keyVaultSecret_PrlUnEuAz 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { +resource keyVaultSecret_QRsiyFBMe 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { parent: keyVault_CRoMbemLF - name: 'appUserPassword' + name: 'appUserPassword-TEST' properties: { value: appUserPassword } } -resource keyVaultSecret_NP8ELZpgb 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { +resource keyVaultSecret_7eiFxkj0r 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { parent: keyVault_CRoMbemLF - name: 'connectionString' + name: 'connectionString-TEST' properties: { value: 'Server=${sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName}; Database=${sqlDatabase_U7NzorRJT.name}; User=appUser; Password=${appUserPassword}' } @@ -236,7 +236,7 @@ resource webSite_4pzZqR2OO 'Microsoft.Web/sites@2021-02-01' = { } } -resource applicationSettingsResource_Pfdqa0OdT 'Microsoft.Web/sites/config@2021-02-01' = { +resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021-02-01' = { parent: webSite_4pzZqR2OO name: 'appsettings' properties: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep index 5e9fd39b4c484..436cd38c95c01 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep @@ -30,7 +30,7 @@ resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' = { } } -resource keyVaultAddAccessPolicy_OttgS6uaT 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { +resource keyVaultAddAccessPolicy_NWCGclP20 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { parent: keyVault_CRoMbemLF name: 'add' properties: { @@ -49,25 +49,25 @@ resource keyVaultAddAccessPolicy_OttgS6uaT 'Microsoft.KeyVault/vaults/accessPoli } } -resource keyVaultSecret_nMDmVNMVq 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { +resource keyVaultSecret_NmXfhaHvM 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { parent: keyVault_CRoMbemLF - name: 'sqlAdminPassword' + name: 'sqlAdminPassword-TEST' properties: { value: sqlAdminPassword } } -resource keyVaultSecret_PrlUnEuAz 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { +resource keyVaultSecret_QRsiyFBMe 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { parent: keyVault_CRoMbemLF - name: 'appUserPassword' + name: 'appUserPassword-TEST' properties: { value: appUserPassword } } -resource keyVaultSecret_NP8ELZpgb 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { +resource keyVaultSecret_7eiFxkj0r 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { parent: keyVault_CRoMbemLF - name: 'connectionString' + name: 'connectionString-TEST' properties: { value: 'Server=${sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName}; Database=${sqlDatabase_U7NzorRJT.name}; User=appUser; Password=${appUserPassword}' } @@ -100,7 +100,7 @@ resource webSite_W5EweSXEq 'Microsoft.Web/sites@2021-02-01' = { } } -resource applicationSettingsResource_NslbdUwEt 'Microsoft.Web/sites/config@2021-02-01' = { +resource applicationSettingsResource_9BG7vUQd2 'Microsoft.Web/sites/config@2021-02-01' = { parent: webSite_W5EweSXEq name: 'appsettings' } @@ -236,7 +236,7 @@ resource webSite_4pzZqR2OO 'Microsoft.Web/sites@2021-02-01' = { } } -resource applicationSettingsResource_Pfdqa0OdT 'Microsoft.Web/sites/config@2021-02-01' = { +resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021-02-01' = { parent: webSite_4pzZqR2OO name: 'appsettings' properties: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep index bc5dadc1f248c..267942128a15d 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep @@ -25,7 +25,7 @@ resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' = { } } -resource keyVaultAddAccessPolicy_OttgS6uaT 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { +resource keyVaultAddAccessPolicy_NWCGclP20 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { parent: keyVault_CRoMbemLF name: 'add' properties: { From 5c41e5a6442c7b632b7129272ef273560fdf3e7b Mon Sep 17 00:00:00 2001 From: jolov Date: Fri, 16 Feb 2024 09:19:13 -0800 Subject: [PATCH 04/32] Add override logic for ManagedService --- .../ManagedServiceIdentity.Serialization.cs | 48 +++++++++++++++---- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Common/Custom/Models/ManagedServiceIdentity.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Common/Custom/Models/ManagedServiceIdentity.Serialization.cs index 7189a9ad5a2f8..6f2a424278d69 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/Common/Custom/Models/ManagedServiceIdentity.Serialization.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Common/Custom/Models/ManagedServiceIdentity.Serialization.cs @@ -87,27 +87,59 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOpti private BinaryData SerializeBicep(ModelReaderWriterOptions options) { StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; builder.AppendLine("{"); - if (Optional.IsDefined(PrincipalId)) + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrincipalId), out propertyOverride); + if (Optional.IsDefined(PrincipalId) || hasPropertyOverride) { builder.Append(" principalId:"); - builder.AppendLine($" '{PrincipalId.Value}'"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{PrincipalId.Value}'"); + } } - if (Optional.IsDefined(TenantId)) + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TenantId), out propertyOverride); + if (Optional.IsDefined(TenantId) || hasPropertyOverride) { builder.Append("tenantId:"); - builder.AppendLine($" '{TenantId.Value}'"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{TenantId.Value}'"); + } } - if (UserAssignedIdentities.Any()) + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(UserAssignedIdentities), out propertyOverride); + if (UserAssignedIdentities.Any() || hasPropertyOverride) { builder.Append(" userAssignedIdentities:"); builder.AppendLine(" {"); - foreach (var item in UserAssignedIdentities) + if (hasPropertyOverride) { - builder.Append($" {item.Key}:"); - AppendChildObject(builder, item.Value, options, 4, false); + builder.AppendLine($" {propertyOverride}"); } + else + { + foreach (var item in UserAssignedIdentities) + { + builder.Append($" {item.Key}:"); + AppendChildObject(builder, item.Value, options, 4, false); + } + } + builder.AppendLine(" }"); } From c9add633f0da3701467cda499d89dfe76d09b20c Mon Sep 17 00:00:00 2001 From: jolov Date: Fri, 16 Feb 2024 11:18:29 -0800 Subject: [PATCH 05/32] PR fb --- .../Azure.Provisioning/src/Construct.cs | 2 +- .../Azure.Provisioning/src/Infrastructure.cs | 27 ++- .../Azure.Provisioning/src/Output.cs | 6 +- .../Azure.Provisioning/src/Resource.cs | 6 +- .../src/resourcemanager/ResourceGroup.cs | 2 +- .../MultipleSubscriptions/main.bicep | 12 +- .../subscription_a3FxKLjJ7.bicep} | 2 +- .../subscription_epOY9bzbr.bicep | 10 - .../subscription_kIWr5ZL1I.bicep | 10 - .../subscription_nYVc2plFi.bicep} | 2 +- .../OutputsSpanningModules/main.bicep | 3 - .../resources/rg1_TEST/rg1_TEST.bicep | 3 - .../resources/rg_TEST/rg_TEST.bicep | 8 +- .../resources/rg_TEST/rg_TEST.bicep | 8 +- .../Infrastructure/WebSiteUsingL1/main.bicep | 2 - .../resources/rg_TEST/rg_TEST.bicep | 2 - .../Infrastructure/WebSiteUsingL2/main.bicep | 2 +- .../resources/rg_TEST/rg_TEST.bicep | 2 +- .../Infrastructure/WebSiteUsingL3/main.bicep | 14 ++ .../resources/rg_TEST/rg_TEST.bicep | 206 ++++++++++++++++++ 20 files changed, 266 insertions(+), 63 deletions(-) rename sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/{subscription_0n8qEB2gZ/subscription_0n8qEB2gZ.bicep => subscription_a3FxKLjJ7/subscription_a3FxKLjJ7.bicep} (67%) delete mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_epOY9bzbr/subscription_epOY9bzbr.bicep delete mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_kIWr5ZL1I/subscription_kIWr5ZL1I.bicep rename sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/{subscription_LDRPSoVXn/subscription_LDRPSoVXn.bicep => subscription_nYVc2plFi/subscription_nYVc2plFi.bicep} (67%) diff --git a/sdk/provisioning/Azure.Provisioning/src/Construct.cs b/sdk/provisioning/Azure.Provisioning/src/Construct.cs index b10bd37380f07..96282b83180e6 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Construct.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Construct.cs @@ -110,7 +110,7 @@ public IEnumerable GetResources(bool recursive = true) IEnumerable result = _resources; if (recursive) { - result = result.Concat(GetConstructs(false).SelectMany(c => c.GetResources(false))); + result = result.Concat(GetConstructs(false).SelectMany(c => c.GetResources(recursive))); } return result; } diff --git a/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs b/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs index 2cecbf711260b..caa7bd9749f18 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs @@ -43,6 +43,8 @@ public void Build(string? outputPath = null) ModuleConstruct? root = null; BuildModuleConstructs(Root, resourceTree, null, ref root); + AddOutputsToModules(); + WriteBicepFile(root!, outputPath); var queue = new Queue(); @@ -50,9 +52,20 @@ public void Build(string? outputPath = null) WriteConstructsByLevel(queue, outputPath); } + private void AddOutputsToModules() + { + foreach (var construct in Root.Scope.GetConstructs(true)) + { + foreach (var output in construct.GetOutputs(false).ToList()) + { + output.Resource.ModuleScope!.AddOutput(output); + } + } + } + private Dictionary> BuildResourceTree() { - var resources = GetResources(true).ToArray(); + var resources = GetResources(true); Dictionary> resourceTree = new(); HashSet visited = new(); foreach (var resource in resources) @@ -128,11 +141,11 @@ private void BuildModuleConstructs(Resource resource, Dictionary ConstructScope.Subscription, //TODO managementgroup support ResourceManager.ResourceGroup => ConstructScope.ResourceGroup, - _ => throw new NotImplementedException(), + _ => throw new InvalidOperationException(), }; } diff --git a/sdk/provisioning/Azure.Provisioning/src/Output.cs b/sdk/provisioning/Azure.Provisioning/src/Output.cs index 0ec2ea6fdb751..2da64556a6b1a 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Output.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Output.cs @@ -28,6 +28,8 @@ public class Output public bool IsSecure { get; } internal IConstruct Source { get; } + internal Resource Resource { get; } + /// /// Initializes a new instance of the . /// @@ -36,13 +38,15 @@ public class Output /// The output source. /// Is the output a literal value. /// Is the output secure. - public Output(string name, string value, IConstruct source, bool isLiteral = false, bool isSecure = false) + /// + internal Output(string name, string value, IConstruct source, Resource resource, bool isLiteral = false, bool isSecure = false) { Name = name; Value = value; IsLiteral = isLiteral; IsSecure = isSecure; Source = source; + Resource = resource; } } } diff --git a/sdk/provisioning/Azure.Provisioning/src/Resource.cs b/sdk/provisioning/Azure.Provisioning/src/Resource.cs index ef396557169c9..5a17dd5f8df8a 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Resource.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Resource.cs @@ -61,8 +61,6 @@ internal void AddDependency(Resource resource) /// public IList Parameters { get; } - internal IList Outputs { get; } - internal IConstruct? ModuleScope { get; set; } /// @@ -82,7 +80,6 @@ protected Resource(IConstruct scope, Resource? parent, string resourceName, Reso var azureName = GetAzureName(scope, resourceName); Scope = scope; Parameters = new List(); - Outputs = new List(); Parent = parent ?? FindParentInScope(scope); Scope.AddResource(this); ResourceData = createProperties(azureName); @@ -177,9 +174,8 @@ private protected Output AddOutput(string name, object instance, string property if (reference is null) throw new ArgumentException(nameof(propertyName), $"{propertyName} was not found in the property tree for {ResourceData.GetType().Name}"); - var result = new Output(name, reference, Scope, isLiteral, isSecure); + var result = new Output(name, reference, Scope, this, isLiteral, isSecure); Scope.AddOutput(result); - Outputs.Add(result); return result; } diff --git a/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceGroup.cs b/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceGroup.cs index 203ebf5ecee89..c69be981062eb 100644 --- a/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceGroup.cs +++ b/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceGroup.cs @@ -24,7 +24,7 @@ public class ResourceGroup : Resource /// The version of the resourceGroup. /// The location of the resourceGroup. /// The parent of the resourceGroup. - public ResourceGroup(IConstruct scope, string name = "rg", string version = "2023-07-01", AzureLocation? location = default, Resource? parent = default) + public ResourceGroup(IConstruct scope, string name = "rg", string version = "2023-07-01", AzureLocation? location = default, Subscription? parent = default) : base(scope, parent, name, ResourceType, version, (name) => ResourceManagerModelFactory.ResourceGroupData( name: name, resourceType: ResourceType, diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep index 724354e8d2b31..e21566b0796fb 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep @@ -1,12 +1,12 @@ targetScope = 'tenant' -module subscription_kIWr5ZL1I './resources/subscription_kIWr5ZL1I/subscription_kIWr5ZL1I.bicep' = { - name: 'subscription_kIWr5ZL1I' - scope: subscription('subscription_kIWr5ZL1I') +module subscription_Gyb7DE27G './resources/subscription_Gyb7DE27G/subscription_Gyb7DE27G.bicep' = { + name: 'subscription_Gyb7DE27G' + scope: subscription('subscription_Gyb7DE27G') } -module subscription_epOY9bzbr './resources/subscription_epOY9bzbr/subscription_epOY9bzbr.bicep' = { - name: 'subscription_epOY9bzbr' - scope: subscription('subscription_epOY9bzbr') +module subscription_1w5hHhR5H './resources/subscription_1w5hHhR5H/subscription_1w5hHhR5H.bicep' = { + name: 'subscription_1w5hHhR5H' + scope: subscription('subscription_1w5hHhR5H') } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_0n8qEB2gZ/subscription_0n8qEB2gZ.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_a3FxKLjJ7/subscription_a3FxKLjJ7.bicep similarity index 67% rename from sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_0n8qEB2gZ/subscription_0n8qEB2gZ.bicep rename to sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_a3FxKLjJ7/subscription_a3FxKLjJ7.bicep index 42245982b194e..d39491cda13b3 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_0n8qEB2gZ/subscription_0n8qEB2gZ.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_a3FxKLjJ7/subscription_a3FxKLjJ7.bicep @@ -1,7 +1,7 @@ targetScope = 'subscription' -resource resourceGroup_moTSF0YWl 'Microsoft.Resources/resourceGroups@2023-07-01' = { +resource resourceGroup_8PCF8X8la 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' location: 'westus' tags: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_epOY9bzbr/subscription_epOY9bzbr.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_epOY9bzbr/subscription_epOY9bzbr.bicep deleted file mode 100644 index 0ca05e2e731b5..0000000000000 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_epOY9bzbr/subscription_epOY9bzbr.bicep +++ /dev/null @@ -1,10 +0,0 @@ -targetScope = 'subscription' - - -resource resourceGroup_SzjQXHS7M 'Microsoft.Resources/resourceGroups@2023-07-01' = { - name: 'rg-TEST' - location: 'westus' - tags: { - azd-env-name: 'TEST' - } -} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_kIWr5ZL1I/subscription_kIWr5ZL1I.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_kIWr5ZL1I/subscription_kIWr5ZL1I.bicep deleted file mode 100644 index dad2d47267ec3..0000000000000 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_kIWr5ZL1I/subscription_kIWr5ZL1I.bicep +++ /dev/null @@ -1,10 +0,0 @@ -targetScope = 'subscription' - - -resource resourceGroup_gxKtbEVWD 'Microsoft.Resources/resourceGroups@2023-07-01' = { - name: 'rg-TEST' - location: 'westus' - tags: { - azd-env-name: 'TEST' - } -} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_LDRPSoVXn/subscription_LDRPSoVXn.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_nYVc2plFi/subscription_nYVc2plFi.bicep similarity index 67% rename from sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_LDRPSoVXn/subscription_LDRPSoVXn.bicep rename to sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_nYVc2plFi/subscription_nYVc2plFi.bicep index 58f6525784517..32c62a12f2e70 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_LDRPSoVXn/subscription_LDRPSoVXn.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_nYVc2plFi/subscription_nYVc2plFi.bicep @@ -1,7 +1,7 @@ targetScope = 'subscription' -resource resourceGroup_Yp9j3M9ZM 'Microsoft.Resources/resourceGroups@2023-07-01' = { +resource resourceGroup_vRdpPlmuP 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' location: 'westus' tags: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep index 61669b82ddf22..6b50c5384857f 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep @@ -36,6 +36,3 @@ module rg2_TEST './resources/rg2_TEST/rg2_TEST.bicep' = { LOCATION: LOCATION } } - -output STORAGE_PRINCIPAL_ID string = rg1_TEST.outputs.STORAGE_PRINCIPAL_ID -output LOCATION string = rg1_TEST.outputs.LOCATION diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep index 8fd8fce8da3e5..d7c4dd861c9ee 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep @@ -41,6 +41,3 @@ resource applicationSettingsResource_MAMFSSuFs 'Microsoft.Web/sites/config@2021- parent: webSite_dOTaZfna6 name: 'appsettings' } - -output STORAGE_PRINCIPAL_ID string = webSite_dOTaZfna6.identity.principalId -output LOCATION string = webSite_dOTaZfna6.location diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep index 48c4e0163290b..9ae37fd197093 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_0S3JP33rx 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-7d403f703f2345' +resource storageAccount_HZVm6r0ff 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-ef79af70b9ff4a' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_0S3JP33rx 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_N4xqIZXcl 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_0S3JP33rx +resource blobService_kHNZCivIP 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_HZVm6r0ff name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep index b07edb795d94d..e124239dc420f 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_2jsIm80wf 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-9848177a84ad43' +resource storageAccount_cbqpTzUq1 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-e6cc582c16114a' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_2jsIm80wf 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_6NwKBOBDn 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_2jsIm80wf +resource blobService_rkzENGcjp 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_cbqpTzUq1 name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep index a1dceb43a30e4..c63d530b60280 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep @@ -26,5 +26,3 @@ module rg_TEST './resources/rg_TEST/rg_TEST.bicep' = { appUserPassword: appUserPassword } } - -output SERVICE_API_IDENTITY_PRINCIPAL_ID string = rg_TEST.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep index 536cb6a6e93f7..e9c8b3fb0d43f 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep @@ -244,5 +244,3 @@ resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021- ENABLE_ORYX_BUILD: 'True' } } - -output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_W5EweSXEq.identity.principalId diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep index a1dceb43a30e4..6d685312630af 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep @@ -27,4 +27,4 @@ module rg_TEST './resources/rg_TEST/rg_TEST.bicep' = { } } -output SERVICE_API_IDENTITY_PRINCIPAL_ID string = rg_TEST.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID +output SERVICE_API_IDENTITY_PRINCIPAL_ID string = TestFrontEndWebSite.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep index 436cd38c95c01..90c0e97cb4658 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep @@ -245,4 +245,4 @@ resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021- } } -output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_W5EweSXEq.identity.principalId +output SERVICE_API_IDENTITY_PRINCIPAL_ID string = TestFrontEndWebSite.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep index b05d876d14113..6d685312630af 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep @@ -1,5 +1,13 @@ targetScope = 'subscription' +@secure() +@description('SQL Server administrator password') +param sqlAdminPassword string + +@secure() +@description('Application user password') +param appUserPassword string + resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' @@ -13,4 +21,10 @@ resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' module rg_TEST './resources/rg_TEST/rg_TEST.bicep' = { name: 'rg_TEST' scope: resourceGroup_I6QNkoPsb + params: { + sqlAdminPassword: sqlAdminPassword + appUserPassword: appUserPassword + } } + +output SERVICE_API_IDENTITY_PRINCIPAL_ID string = TestFrontEndWebSite.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep index 267942128a15d..4784e63f4adf4 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep @@ -1,3 +1,11 @@ +@secure() +@description('SQL Server administrator password') +param sqlAdminPassword string + +@secure() +@description('Application user password') +param appUserPassword string + resource appServicePlan_kjMZSF1FP 'Microsoft.Web/serverfarms@2021-02-01' = { name: 'appServicePlan-TEST' @@ -43,3 +51,201 @@ resource keyVaultAddAccessPolicy_NWCGclP20 'Microsoft.KeyVault/vaults/accessPoli ] } } + +resource keyVaultSecret_NmXfhaHvM 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { + parent: keyVault_CRoMbemLF + name: 'sqlAdminPassword-TEST' + properties: { + value: sqlAdminPassword + } +} + +resource keyVaultSecret_QRsiyFBMe 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { + parent: keyVault_CRoMbemLF + name: 'appUserPassword-TEST' + properties: { + value: appUserPassword + } +} + +resource keyVaultSecret_7eiFxkj0r 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { + parent: keyVault_CRoMbemLF + name: 'connectionString-TEST' + properties: { + value: 'Server=${sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName}; Database=${sqlDatabase_U7NzorRJT.name}; User=appUser; Password=${appUserPassword}' + } +} + +resource webSite_W5EweSXEq 'Microsoft.Web/sites@2021-02-01' = { + name: 'frontEnd-TEST' + location: 'westus' + identity: { + } + kind: 'app,linux' + properties: { + serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' + siteConfig: { + linuxFxVersion: 'node|18-lts' + alwaysOn: true + appCommandLine: './entrypoint.sh -o ./env-config.js && pm2 serve /home/site/wwwroot --no-daemon --spa' + experiments: { + } + cors: { + allowedOrigins: [ + 'https://portal.azure.com' + 'https://ms.portal.azure.com' + ] + } + minTlsVersion: '1.2' + ftpsState: 'FtpsOnly' + } + httpsOnly: true + } +} + +resource applicationSettingsResource_9BG7vUQd2 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_W5EweSXEq + name: 'appsettings' +} + +resource webSiteConfigLogs_giqxapQs0 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_W5EweSXEq + name: 'logs' + properties: { + applicationLogs: { + fileSystem: { + level: 'Verbose' + } + } + httpLogs: { + fileSystem: { + retentionInMb: 35 + retentionInDays: 1 + enabled: true + } + } + failedRequestsTracing: { + enabled: true + } + detailedErrorMessages: { + enabled: true + } + } +} + +resource sqlServer_zjdvvB2wl 'Microsoft.Sql/servers@2022-08-01-preview' = { + name: 'sqlserver-TEST' + location: 'westus' + properties: { + administratorLogin: 'sqladmin' + administratorLoginPassword: sqlAdminPassword + version: '12.0' + minimalTlsVersion: '1.2' + publicNetworkAccess: 'Enabled' + } +} + +resource sqlDatabase_U7NzorRJT 'Microsoft.Sql/servers/databases@2022-08-01-preview' = { + parent: sqlServer_zjdvvB2wl + name: 'db-TEST' + location: 'westus' + properties: { + } +} + +resource sqlFirewallRule_eS4m8st65 'Microsoft.Sql/servers/firewallRules@2020-11-01-preview' = { + parent: sqlServer_zjdvvB2wl + name: 'firewallRule-TEST' + properties: { + startIpAddress: '0.0.0.1' + endIpAddress: '255.255.255.254' + } +} + +resource deploymentScript_3Zq2Pl8xa 'Microsoft.Resources/deploymentScripts@2020-10-01' = { + name: 'cliScript-TEST' + location: 'westus' + kind: 'AzureCLI' + properties: { + cleanupPreference: 'OnSuccess' + scriptContent: ''' +wget https://github.com/microsoft/go-sqlcmd/releases/download/v0.8.1/sqlcmd-v0.8.1-linux-x64.tar.bz2 +tar x -f sqlcmd-v0.8.1-linux-x64.tar.bz2 -C . +cat < ./initDb.sql +drop user ${APPUSERNAME} +go +create user ${APPUSERNAME} with password = '${APPUSERPASSWORD}' +go +alter role db_owner add member ${APPUSERNAME} +go +SCRIPT_END +./sqlcmd -S ${DBSERVER} -d ${DBNAME} -U ${SQLADMIN} -i ./initDb.sql''' + environmentVariables: [ + { + name: 'APPUSERNAME' + value: 'appUser' + } + { + name: 'APPUSERPASSWORD' + secureValue: '_p_.appUserPassword' + } + { + name: 'DBNAME' + value: '_p_.sqlDatabase_U7NzorRJT.name' + } + { + name: 'DBSERVER' + value: '_p_.sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName' + } + { + name: 'SQLCMDPASSWORD' + secureValue: '_p_.sqlAdminPassword' + } + { + name: 'SQLADMIN' + value: 'sqlAdmin' + } + ] + retentionInterval: 'PT1H' + timeout: 'PT5M' + azCliVersion: '2.37.0' + } +} + +resource webSite_4pzZqR2OO 'Microsoft.Web/sites@2021-02-01' = { + name: 'backEnd-TEST' + location: 'westus' + identity: { + } + kind: 'app,linux' + properties: { + serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' + siteConfig: { + linuxFxVersion: 'dotnetcore|6.0' + alwaysOn: true + appCommandLine: '' + experiments: { + } + cors: { + allowedOrigins: [ + 'https://portal.azure.com' + 'https://ms.portal.azure.com' + ] + } + minTlsVersion: '1.2' + ftpsState: 'FtpsOnly' + } + httpsOnly: true + } +} + +resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_4pzZqR2OO + name: 'appsettings' + properties: { + SCM_DO_BUILD_DURING_DEPLOYMENT: 'False' + ENABLE_ORYX_BUILD: 'True' + } +} + +output SERVICE_API_IDENTITY_PRINCIPAL_ID string = TestFrontEndWebSite.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID From fdd2d5ed9396dbff8e73029becadc8de58e1c11f Mon Sep 17 00:00:00 2001 From: jolov Date: Fri, 16 Feb 2024 11:22:25 -0800 Subject: [PATCH 06/32] deleted files --- .../subscription_1w5hHhR5H.bicep | 10 ++++++++++ .../subscription_23o8OBlvk.bicep | 10 ++++++++++ .../subscription_8sEiYSnOk.bicep | 10 ++++++++++ .../subscription_Gyb7DE27G.bicep | 10 ++++++++++ .../subscription_d3oYZeSej.bicep | 10 ++++++++++ .../subscription_yfMNzpEgq.bicep | 10 ++++++++++ 6 files changed, 60 insertions(+) create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_1w5hHhR5H/subscription_1w5hHhR5H.bicep create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_23o8OBlvk/subscription_23o8OBlvk.bicep create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_8sEiYSnOk/subscription_8sEiYSnOk.bicep create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_Gyb7DE27G/subscription_Gyb7DE27G.bicep create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_d3oYZeSej/subscription_d3oYZeSej.bicep create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_yfMNzpEgq/subscription_yfMNzpEgq.bicep diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_1w5hHhR5H/subscription_1w5hHhR5H.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_1w5hHhR5H/subscription_1w5hHhR5H.bicep new file mode 100644 index 0000000000000..34517c1ae8770 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_1w5hHhR5H/subscription_1w5hHhR5H.bicep @@ -0,0 +1,10 @@ +targetScope = 'subscription' + + +resource resourceGroup_T6BljVFvm 'Microsoft.Resources/resourceGroups@2023-07-01' = { + name: 'rg-TEST' + location: 'westus' + tags: { + azd-env-name: 'TEST' + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_23o8OBlvk/subscription_23o8OBlvk.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_23o8OBlvk/subscription_23o8OBlvk.bicep new file mode 100644 index 0000000000000..530a5ebbd0fba --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_23o8OBlvk/subscription_23o8OBlvk.bicep @@ -0,0 +1,10 @@ +targetScope = 'subscription' + + +resource resourceGroup_dN31EQvtE 'Microsoft.Resources/resourceGroups@2023-07-01' = { + name: 'rg-TEST' + location: 'westus' + tags: { + azd-env-name: 'TEST' + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_8sEiYSnOk/subscription_8sEiYSnOk.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_8sEiYSnOk/subscription_8sEiYSnOk.bicep new file mode 100644 index 0000000000000..64ebbc449e84b --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_8sEiYSnOk/subscription_8sEiYSnOk.bicep @@ -0,0 +1,10 @@ +targetScope = 'subscription' + + +resource resourceGroup_fJxtAAXwc 'Microsoft.Resources/resourceGroups@2023-07-01' = { + name: 'rg-TEST' + location: 'westus' + tags: { + azd-env-name: 'TEST' + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_Gyb7DE27G/subscription_Gyb7DE27G.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_Gyb7DE27G/subscription_Gyb7DE27G.bicep new file mode 100644 index 0000000000000..66e4ff50826d3 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_Gyb7DE27G/subscription_Gyb7DE27G.bicep @@ -0,0 +1,10 @@ +targetScope = 'subscription' + + +resource resourceGroup_OQ9lepQpY 'Microsoft.Resources/resourceGroups@2023-07-01' = { + name: 'rg-TEST' + location: 'westus' + tags: { + azd-env-name: 'TEST' + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_d3oYZeSej/subscription_d3oYZeSej.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_d3oYZeSej/subscription_d3oYZeSej.bicep new file mode 100644 index 0000000000000..98d24a0a8e65b --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_d3oYZeSej/subscription_d3oYZeSej.bicep @@ -0,0 +1,10 @@ +targetScope = 'subscription' + + +resource resourceGroup_ms3OREPE6 'Microsoft.Resources/resourceGroups@2023-07-01' = { + name: 'rg-TEST' + location: 'westus' + tags: { + azd-env-name: 'TEST' + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_yfMNzpEgq/subscription_yfMNzpEgq.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_yfMNzpEgq/subscription_yfMNzpEgq.bicep new file mode 100644 index 0000000000000..b43bc197dfc54 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_yfMNzpEgq/subscription_yfMNzpEgq.bicep @@ -0,0 +1,10 @@ +targetScope = 'subscription' + + +resource resourceGroup_9RTImufMF 'Microsoft.Resources/resourceGroups@2023-07-01' = { + name: 'rg-TEST' + location: 'westus' + tags: { + azd-env-name: 'TEST' + } +} From ee33dee29784620fafef74143fa5b0d10c3313a1 Mon Sep 17 00:00:00 2001 From: jolov Date: Fri, 16 Feb 2024 11:22:56 -0800 Subject: [PATCH 07/32] API --- .../api/Azure.Provisioning.net6.0.cs | 15 ++++++--------- .../api/Azure.Provisioning.netstandard2.0.cs | 15 ++++++--------- 2 files changed, 12 insertions(+), 18 deletions(-) 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 050e917cc1a5f..6bcb94897c340 100644 --- a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs +++ b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs @@ -60,18 +60,15 @@ public void Build(string? outputPath = null) { } } public partial class Output { - public Output(string name, string value, Azure.Provisioning.IConstruct source, bool isLiteral = false, bool isSecure = false) { } + internal Output() { } public bool IsLiteral { get { throw null; } } public bool IsSecure { get { throw null; } } public string Name { get { throw null; } } public string Value { get { throw null; } } } - [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public readonly partial struct Parameter + public partial class Parameter { - private readonly object _dummy; - private readonly int _dummyPrimitive; - public Parameter(string name, string? description = null, object? defaultValue = null, bool isSecure = false) { throw null; } + public Parameter(string name, string? description = null, object? defaultValue = null, bool isSecure = false) { } public object? DefaultValue { get { throw null; } } public string? Description { get { throw null; } } public bool IsSecure { get { throw null; } } @@ -116,7 +113,7 @@ namespace Azure.Provisioning.AppService { public partial class AppServicePlan : Azure.Provisioning.Resource { - public AppServicePlan(Azure.Provisioning.IConstruct scope, string resourceName, string version = "2021-02-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } + public AppServicePlan(Azure.Provisioning.IConstruct scope, string resourceName, string version = "2021-02-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?), Azure.Provisioning.ResourceManager.ResourceGroup? parent = null) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; } } public static partial class AppServicesExtensions @@ -125,7 +122,7 @@ public static partial class AppServicesExtensions } public partial class WebSite : Azure.Provisioning.Resource { - public WebSite(Azure.Provisioning.IConstruct scope, string resourceName, Azure.Provisioning.AppService.AppServicePlan appServicePlan, Azure.Provisioning.AppService.WebSiteRuntime runtime, string runtimeVersion, string version = "2021-02-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } + public WebSite(Azure.Provisioning.IConstruct scope, string resourceName, Azure.Provisioning.AppService.AppServicePlan appServicePlan, Azure.Provisioning.AppService.WebSiteRuntime runtime, string runtimeVersion, string version = "2021-02-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?), Azure.Provisioning.ResourceManager.ResourceGroup? parent = null) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } public void AddApplicationSetting(string key, Azure.Provisioning.Parameter value) { } public void AddApplicationSetting(string key, string value) { } public void AddLogConfig(string resourceName) { } @@ -170,7 +167,7 @@ namespace Azure.Provisioning.ResourceManager { public partial class ResourceGroup : Azure.Provisioning.Resource { - public ResourceGroup(Azure.Provisioning.IConstruct scope, string name = "rg", string version = "2023-07-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } + public ResourceGroup(Azure.Provisioning.IConstruct scope, string name = "rg", string version = "2023-07-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?), Azure.Provisioning.ResourceManager.Subscription? parent = null) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; } } public static partial class ResourceManagerExtensions 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 050e917cc1a5f..6bcb94897c340 100644 --- a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs +++ b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs @@ -60,18 +60,15 @@ public void Build(string? outputPath = null) { } } public partial class Output { - public Output(string name, string value, Azure.Provisioning.IConstruct source, bool isLiteral = false, bool isSecure = false) { } + internal Output() { } public bool IsLiteral { get { throw null; } } public bool IsSecure { get { throw null; } } public string Name { get { throw null; } } public string Value { get { throw null; } } } - [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public readonly partial struct Parameter + public partial class Parameter { - private readonly object _dummy; - private readonly int _dummyPrimitive; - public Parameter(string name, string? description = null, object? defaultValue = null, bool isSecure = false) { throw null; } + public Parameter(string name, string? description = null, object? defaultValue = null, bool isSecure = false) { } public object? DefaultValue { get { throw null; } } public string? Description { get { throw null; } } public bool IsSecure { get { throw null; } } @@ -116,7 +113,7 @@ namespace Azure.Provisioning.AppService { public partial class AppServicePlan : Azure.Provisioning.Resource { - public AppServicePlan(Azure.Provisioning.IConstruct scope, string resourceName, string version = "2021-02-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } + public AppServicePlan(Azure.Provisioning.IConstruct scope, string resourceName, string version = "2021-02-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?), Azure.Provisioning.ResourceManager.ResourceGroup? parent = null) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; } } public static partial class AppServicesExtensions @@ -125,7 +122,7 @@ public static partial class AppServicesExtensions } public partial class WebSite : Azure.Provisioning.Resource { - public WebSite(Azure.Provisioning.IConstruct scope, string resourceName, Azure.Provisioning.AppService.AppServicePlan appServicePlan, Azure.Provisioning.AppService.WebSiteRuntime runtime, string runtimeVersion, string version = "2021-02-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } + public WebSite(Azure.Provisioning.IConstruct scope, string resourceName, Azure.Provisioning.AppService.AppServicePlan appServicePlan, Azure.Provisioning.AppService.WebSiteRuntime runtime, string runtimeVersion, string version = "2021-02-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?), Azure.Provisioning.ResourceManager.ResourceGroup? parent = null) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } public void AddApplicationSetting(string key, Azure.Provisioning.Parameter value) { } public void AddApplicationSetting(string key, string value) { } public void AddLogConfig(string resourceName) { } @@ -170,7 +167,7 @@ namespace Azure.Provisioning.ResourceManager { public partial class ResourceGroup : Azure.Provisioning.Resource { - public ResourceGroup(Azure.Provisioning.IConstruct scope, string name = "rg", string version = "2023-07-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } + public ResourceGroup(Azure.Provisioning.IConstruct scope, string name = "rg", string version = "2023-07-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?), Azure.Provisioning.ResourceManager.Subscription? parent = null) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; } } public static partial class ResourceManagerExtensions From f5a7d2bc5711c2461c48985665b1162cfa10aae9 Mon Sep 17 00:00:00 2001 From: jolov Date: Fri, 16 Feb 2024 11:25:33 -0800 Subject: [PATCH 08/32] Fix getResources --- sdk/provisioning/Azure.Provisioning/src/Construct.cs | 2 +- .../Infrastructure/MultipleSubscriptions/main.bicep | 12 ++++++------ .../subscription_B8fZorY2U.bicep | 10 ++++++++++ .../subscription_qL49QZscA.bicep | 10 ++++++++++ .../resources/rg_TEST/rg_TEST.bicep | 8 ++++---- .../resources/rg_TEST/rg_TEST.bicep | 8 ++++---- 6 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_B8fZorY2U/subscription_B8fZorY2U.bicep create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_qL49QZscA/subscription_qL49QZscA.bicep diff --git a/sdk/provisioning/Azure.Provisioning/src/Construct.cs b/sdk/provisioning/Azure.Provisioning/src/Construct.cs index 96282b83180e6..c05b26d7d53e3 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Construct.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Construct.cs @@ -110,7 +110,7 @@ public IEnumerable GetResources(bool recursive = true) IEnumerable result = _resources; if (recursive) { - result = result.Concat(GetConstructs(false).SelectMany(c => c.GetResources(recursive))); + result = result.Concat(GetConstructs(true).SelectMany(c => c.GetResources(false))); } return result; } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep index e21566b0796fb..5a228572197d7 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep @@ -1,12 +1,12 @@ targetScope = 'tenant' -module subscription_Gyb7DE27G './resources/subscription_Gyb7DE27G/subscription_Gyb7DE27G.bicep' = { - name: 'subscription_Gyb7DE27G' - scope: subscription('subscription_Gyb7DE27G') +module subscription_B8fZorY2U './resources/subscription_B8fZorY2U/subscription_B8fZorY2U.bicep' = { + name: 'subscription_B8fZorY2U' + scope: subscription('subscription_B8fZorY2U') } -module subscription_1w5hHhR5H './resources/subscription_1w5hHhR5H/subscription_1w5hHhR5H.bicep' = { - name: 'subscription_1w5hHhR5H' - scope: subscription('subscription_1w5hHhR5H') +module subscription_qL49QZscA './resources/subscription_qL49QZscA/subscription_qL49QZscA.bicep' = { + name: 'subscription_qL49QZscA' + scope: subscription('subscription_qL49QZscA') } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_B8fZorY2U/subscription_B8fZorY2U.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_B8fZorY2U/subscription_B8fZorY2U.bicep new file mode 100644 index 0000000000000..bff7ccf99aa98 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_B8fZorY2U/subscription_B8fZorY2U.bicep @@ -0,0 +1,10 @@ +targetScope = 'subscription' + + +resource resourceGroup_rYdK1plny 'Microsoft.Resources/resourceGroups@2023-07-01' = { + name: 'rg-TEST' + location: 'westus' + tags: { + azd-env-name: 'TEST' + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_qL49QZscA/subscription_qL49QZscA.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_qL49QZscA/subscription_qL49QZscA.bicep new file mode 100644 index 0000000000000..a9676175cf8dc --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_qL49QZscA/subscription_qL49QZscA.bicep @@ -0,0 +1,10 @@ +targetScope = 'subscription' + + +resource resourceGroup_oM1vUIbNM 'Microsoft.Resources/resourceGroups@2023-07-01' = { + name: 'rg-TEST' + location: 'westus' + tags: { + azd-env-name: 'TEST' + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep index 9ae37fd197093..419323594ffc1 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_HZVm6r0ff 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-ef79af70b9ff4a' +resource storageAccount_ft4agpZKs 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-d486cf68eaf642' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_HZVm6r0ff 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_kHNZCivIP 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_HZVm6r0ff +resource blobService_iyZCMCxIy 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_ft4agpZKs name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep index e124239dc420f..57a647ce4ae97 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_cbqpTzUq1 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-e6cc582c16114a' +resource storageAccount_wkpTyTxEg 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-85e78c3b34ff40' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_cbqpTzUq1 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_rkzENGcjp 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_cbqpTzUq1 +resource blobService_vAIKMJkqV 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_wkpTyTxEg name: 'default' properties: { cors: { From 16e0e5de373cb4159384bed3b546f43231cf1770 Mon Sep 17 00:00:00 2001 From: jolov Date: Fri, 16 Feb 2024 11:26:17 -0800 Subject: [PATCH 09/32] tests --- .../Infrastructure/MultipleSubscriptions/main.bicep | 12 ++++++------ .../subscription_8sEiYSnOk.bicep | 10 ---------- .../subscription_B8fZorY2U.bicep | 10 ---------- .../subscription_Gyb7DE27G.bicep | 10 ---------- .../subscription_UAtmuuT4I.bicep} | 2 +- .../subscription_YHysOsqvo.bicep} | 2 +- .../subscription_a3FxKLjJ7.bicep | 10 ---------- .../subscription_d3oYZeSej.bicep | 10 ---------- .../subscription_nYVc2plFi.bicep | 10 ---------- .../subscription_qL49QZscA.bicep | 10 ---------- .../subscription_yfMNzpEgq.bicep | 10 ---------- .../resources/rg_TEST/rg_TEST.bicep | 8 ++++---- .../resources/rg_TEST/rg_TEST.bicep | 8 ++++---- 13 files changed, 16 insertions(+), 96 deletions(-) delete mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_8sEiYSnOk/subscription_8sEiYSnOk.bicep delete mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_B8fZorY2U/subscription_B8fZorY2U.bicep delete mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_Gyb7DE27G/subscription_Gyb7DE27G.bicep rename sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/{subscription_1w5hHhR5H/subscription_1w5hHhR5H.bicep => subscription_UAtmuuT4I/subscription_UAtmuuT4I.bicep} (67%) rename sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/{subscription_23o8OBlvk/subscription_23o8OBlvk.bicep => subscription_YHysOsqvo/subscription_YHysOsqvo.bicep} (67%) delete mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_a3FxKLjJ7/subscription_a3FxKLjJ7.bicep delete mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_d3oYZeSej/subscription_d3oYZeSej.bicep delete mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_nYVc2plFi/subscription_nYVc2plFi.bicep delete mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_qL49QZscA/subscription_qL49QZscA.bicep delete mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_yfMNzpEgq/subscription_yfMNzpEgq.bicep diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep index 5a228572197d7..619bbd880dd21 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep @@ -1,12 +1,12 @@ targetScope = 'tenant' -module subscription_B8fZorY2U './resources/subscription_B8fZorY2U/subscription_B8fZorY2U.bicep' = { - name: 'subscription_B8fZorY2U' - scope: subscription('subscription_B8fZorY2U') +module subscription_YHysOsqvo './resources/subscription_YHysOsqvo/subscription_YHysOsqvo.bicep' = { + name: 'subscription_YHysOsqvo' + scope: subscription('subscription_YHysOsqvo') } -module subscription_qL49QZscA './resources/subscription_qL49QZscA/subscription_qL49QZscA.bicep' = { - name: 'subscription_qL49QZscA' - scope: subscription('subscription_qL49QZscA') +module subscription_UAtmuuT4I './resources/subscription_UAtmuuT4I/subscription_UAtmuuT4I.bicep' = { + name: 'subscription_UAtmuuT4I' + scope: subscription('subscription_UAtmuuT4I') } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_8sEiYSnOk/subscription_8sEiYSnOk.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_8sEiYSnOk/subscription_8sEiYSnOk.bicep deleted file mode 100644 index 64ebbc449e84b..0000000000000 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_8sEiYSnOk/subscription_8sEiYSnOk.bicep +++ /dev/null @@ -1,10 +0,0 @@ -targetScope = 'subscription' - - -resource resourceGroup_fJxtAAXwc 'Microsoft.Resources/resourceGroups@2023-07-01' = { - name: 'rg-TEST' - location: 'westus' - tags: { - azd-env-name: 'TEST' - } -} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_B8fZorY2U/subscription_B8fZorY2U.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_B8fZorY2U/subscription_B8fZorY2U.bicep deleted file mode 100644 index bff7ccf99aa98..0000000000000 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_B8fZorY2U/subscription_B8fZorY2U.bicep +++ /dev/null @@ -1,10 +0,0 @@ -targetScope = 'subscription' - - -resource resourceGroup_rYdK1plny 'Microsoft.Resources/resourceGroups@2023-07-01' = { - name: 'rg-TEST' - location: 'westus' - tags: { - azd-env-name: 'TEST' - } -} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_Gyb7DE27G/subscription_Gyb7DE27G.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_Gyb7DE27G/subscription_Gyb7DE27G.bicep deleted file mode 100644 index 66e4ff50826d3..0000000000000 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_Gyb7DE27G/subscription_Gyb7DE27G.bicep +++ /dev/null @@ -1,10 +0,0 @@ -targetScope = 'subscription' - - -resource resourceGroup_OQ9lepQpY 'Microsoft.Resources/resourceGroups@2023-07-01' = { - name: 'rg-TEST' - location: 'westus' - tags: { - azd-env-name: 'TEST' - } -} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_1w5hHhR5H/subscription_1w5hHhR5H.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_UAtmuuT4I/subscription_UAtmuuT4I.bicep similarity index 67% rename from sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_1w5hHhR5H/subscription_1w5hHhR5H.bicep rename to sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_UAtmuuT4I/subscription_UAtmuuT4I.bicep index 34517c1ae8770..bc459403f1796 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_1w5hHhR5H/subscription_1w5hHhR5H.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_UAtmuuT4I/subscription_UAtmuuT4I.bicep @@ -1,7 +1,7 @@ targetScope = 'subscription' -resource resourceGroup_T6BljVFvm 'Microsoft.Resources/resourceGroups@2023-07-01' = { +resource resourceGroup_chziT9ZEN 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' location: 'westus' tags: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_23o8OBlvk/subscription_23o8OBlvk.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_YHysOsqvo/subscription_YHysOsqvo.bicep similarity index 67% rename from sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_23o8OBlvk/subscription_23o8OBlvk.bicep rename to sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_YHysOsqvo/subscription_YHysOsqvo.bicep index 530a5ebbd0fba..6f94802e8bd0c 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_23o8OBlvk/subscription_23o8OBlvk.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_YHysOsqvo/subscription_YHysOsqvo.bicep @@ -1,7 +1,7 @@ targetScope = 'subscription' -resource resourceGroup_dN31EQvtE 'Microsoft.Resources/resourceGroups@2023-07-01' = { +resource resourceGroup_KzJWnDxbG 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' location: 'westus' tags: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_a3FxKLjJ7/subscription_a3FxKLjJ7.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_a3FxKLjJ7/subscription_a3FxKLjJ7.bicep deleted file mode 100644 index d39491cda13b3..0000000000000 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_a3FxKLjJ7/subscription_a3FxKLjJ7.bicep +++ /dev/null @@ -1,10 +0,0 @@ -targetScope = 'subscription' - - -resource resourceGroup_8PCF8X8la 'Microsoft.Resources/resourceGroups@2023-07-01' = { - name: 'rg-TEST' - location: 'westus' - tags: { - azd-env-name: 'TEST' - } -} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_d3oYZeSej/subscription_d3oYZeSej.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_d3oYZeSej/subscription_d3oYZeSej.bicep deleted file mode 100644 index 98d24a0a8e65b..0000000000000 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_d3oYZeSej/subscription_d3oYZeSej.bicep +++ /dev/null @@ -1,10 +0,0 @@ -targetScope = 'subscription' - - -resource resourceGroup_ms3OREPE6 'Microsoft.Resources/resourceGroups@2023-07-01' = { - name: 'rg-TEST' - location: 'westus' - tags: { - azd-env-name: 'TEST' - } -} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_nYVc2plFi/subscription_nYVc2plFi.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_nYVc2plFi/subscription_nYVc2plFi.bicep deleted file mode 100644 index 32c62a12f2e70..0000000000000 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_nYVc2plFi/subscription_nYVc2plFi.bicep +++ /dev/null @@ -1,10 +0,0 @@ -targetScope = 'subscription' - - -resource resourceGroup_vRdpPlmuP 'Microsoft.Resources/resourceGroups@2023-07-01' = { - name: 'rg-TEST' - location: 'westus' - tags: { - azd-env-name: 'TEST' - } -} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_qL49QZscA/subscription_qL49QZscA.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_qL49QZscA/subscription_qL49QZscA.bicep deleted file mode 100644 index a9676175cf8dc..0000000000000 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_qL49QZscA/subscription_qL49QZscA.bicep +++ /dev/null @@ -1,10 +0,0 @@ -targetScope = 'subscription' - - -resource resourceGroup_oM1vUIbNM 'Microsoft.Resources/resourceGroups@2023-07-01' = { - name: 'rg-TEST' - location: 'westus' - tags: { - azd-env-name: 'TEST' - } -} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_yfMNzpEgq/subscription_yfMNzpEgq.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_yfMNzpEgq/subscription_yfMNzpEgq.bicep deleted file mode 100644 index b43bc197dfc54..0000000000000 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_yfMNzpEgq/subscription_yfMNzpEgq.bicep +++ /dev/null @@ -1,10 +0,0 @@ -targetScope = 'subscription' - - -resource resourceGroup_9RTImufMF 'Microsoft.Resources/resourceGroups@2023-07-01' = { - name: 'rg-TEST' - location: 'westus' - tags: { - azd-env-name: 'TEST' - } -} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep index 419323594ffc1..0c6b4c11dae18 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_ft4agpZKs 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-d486cf68eaf642' +resource storageAccount_iyoTs4lhI 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-122b5075e14f4e' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_ft4agpZKs 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_iyZCMCxIy 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_ft4agpZKs +resource blobService_2AWlCCB4v 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_iyoTs4lhI name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep index 57a647ce4ae97..37a91f1b6d4b7 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_wkpTyTxEg 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-85e78c3b34ff40' +resource storageAccount_3NwCr26bs 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-0a5678be9deb41' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_wkpTyTxEg 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_vAIKMJkqV 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_wkpTyTxEg +resource blobService_A6eisTKKC 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_3NwCr26bs name: 'default' properties: { cors: { From 78251ad944db2e7abca7c729fc44b4943b31fbe6 Mon Sep 17 00:00:00 2001 From: jolov Date: Fri, 16 Feb 2024 12:17:35 -0800 Subject: [PATCH 10/32] Fix outputs --- .../Azure.Provisioning/src/Infrastructure.cs | 8 ++++++-- .../Infrastructure/MultipleSubscriptions/main.bicep | 12 ++++++------ .../subscription_A5nZSfW0E.bicep} | 2 +- .../subscription_FjgVYijAv.bicep} | 2 +- .../subscription_XJpg02kDp.bicep | 10 ++++++++++ .../subscription_dxHHjqL0S.bicep | 10 ++++++++++ .../Infrastructure/OutputsSpanningModules/main.bicep | 3 +++ .../resources/rg1_TEST/rg1_TEST.bicep | 3 +++ .../resources/rg_TEST/rg_TEST.bicep | 8 ++++---- .../resources/rg_TEST/rg_TEST.bicep | 8 ++++---- .../tests/Infrastructure/WebSiteUsingL1/main.bicep | 2 ++ .../WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep | 2 ++ .../tests/Infrastructure/WebSiteUsingL2/main.bicep | 2 +- .../WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep | 2 +- .../tests/Infrastructure/WebSiteUsingL3/main.bicep | 2 +- .../WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep | 2 +- 16 files changed, 56 insertions(+), 22 deletions(-) rename sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/{subscription_UAtmuuT4I/subscription_UAtmuuT4I.bicep => subscription_A5nZSfW0E/subscription_A5nZSfW0E.bicep} (67%) rename sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/{subscription_YHysOsqvo/subscription_YHysOsqvo.bicep => subscription_FjgVYijAv/subscription_FjgVYijAv.bicep} (67%) create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_XJpg02kDp/subscription_XJpg02kDp.bicep create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_dxHHjqL0S/subscription_dxHHjqL0S.bicep diff --git a/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs b/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs index caa7bd9749f18..d9ffaa14a59a5 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs @@ -54,11 +54,15 @@ public void Build(string? outputPath = null) private void AddOutputsToModules() { - foreach (var construct in Root.Scope.GetConstructs(true)) + // Get all of the user-defined constructs in addition to the Infrastructure construct + foreach (var construct in GetConstructs(true).Where(c => c is not ModuleConstruct).Concat(new[] { this })) { + // ToList to avoid modifying the collection while iterating foreach (var output in construct.GetOutputs(false).ToList()) { - output.Resource.ModuleScope!.AddOutput(output); + var moduleOutput = new Output(output.Name, output.Value, output.Resource.ModuleScope!, + output.Resource, output.IsLiteral, output.IsSecure); + output.Resource.ModuleScope!.AddOutput(moduleOutput); } } } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep index 619bbd880dd21..5c034224852e6 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep @@ -1,12 +1,12 @@ targetScope = 'tenant' -module subscription_YHysOsqvo './resources/subscription_YHysOsqvo/subscription_YHysOsqvo.bicep' = { - name: 'subscription_YHysOsqvo' - scope: subscription('subscription_YHysOsqvo') +module subscription_XJpg02kDp './resources/subscription_XJpg02kDp/subscription_XJpg02kDp.bicep' = { + name: 'subscription_XJpg02kDp' + scope: subscription('subscription_XJpg02kDp') } -module subscription_UAtmuuT4I './resources/subscription_UAtmuuT4I/subscription_UAtmuuT4I.bicep' = { - name: 'subscription_UAtmuuT4I' - scope: subscription('subscription_UAtmuuT4I') +module subscription_A5nZSfW0E './resources/subscription_A5nZSfW0E/subscription_A5nZSfW0E.bicep' = { + name: 'subscription_A5nZSfW0E' + scope: subscription('subscription_A5nZSfW0E') } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_UAtmuuT4I/subscription_UAtmuuT4I.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_A5nZSfW0E/subscription_A5nZSfW0E.bicep similarity index 67% rename from sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_UAtmuuT4I/subscription_UAtmuuT4I.bicep rename to sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_A5nZSfW0E/subscription_A5nZSfW0E.bicep index bc459403f1796..1474599bc37c2 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_UAtmuuT4I/subscription_UAtmuuT4I.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_A5nZSfW0E/subscription_A5nZSfW0E.bicep @@ -1,7 +1,7 @@ targetScope = 'subscription' -resource resourceGroup_chziT9ZEN 'Microsoft.Resources/resourceGroups@2023-07-01' = { +resource resourceGroup_VChnO7L2o 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' location: 'westus' tags: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_YHysOsqvo/subscription_YHysOsqvo.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_FjgVYijAv/subscription_FjgVYijAv.bicep similarity index 67% rename from sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_YHysOsqvo/subscription_YHysOsqvo.bicep rename to sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_FjgVYijAv/subscription_FjgVYijAv.bicep index 6f94802e8bd0c..f8a31e495f3d4 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_YHysOsqvo/subscription_YHysOsqvo.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_FjgVYijAv/subscription_FjgVYijAv.bicep @@ -1,7 +1,7 @@ targetScope = 'subscription' -resource resourceGroup_KzJWnDxbG 'Microsoft.Resources/resourceGroups@2023-07-01' = { +resource resourceGroup_NPo8hmvYM 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' location: 'westus' tags: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_XJpg02kDp/subscription_XJpg02kDp.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_XJpg02kDp/subscription_XJpg02kDp.bicep new file mode 100644 index 0000000000000..6ed49f0440732 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_XJpg02kDp/subscription_XJpg02kDp.bicep @@ -0,0 +1,10 @@ +targetScope = 'subscription' + + +resource resourceGroup_qL54vnxJc 'Microsoft.Resources/resourceGroups@2023-07-01' = { + name: 'rg-TEST' + location: 'westus' + tags: { + azd-env-name: 'TEST' + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_dxHHjqL0S/subscription_dxHHjqL0S.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_dxHHjqL0S/subscription_dxHHjqL0S.bicep new file mode 100644 index 0000000000000..ab987eebe1a28 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_dxHHjqL0S/subscription_dxHHjqL0S.bicep @@ -0,0 +1,10 @@ +targetScope = 'subscription' + + +resource resourceGroup_1aRP1lqm6 'Microsoft.Resources/resourceGroups@2023-07-01' = { + name: 'rg-TEST' + location: 'westus' + tags: { + azd-env-name: 'TEST' + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep index 6b50c5384857f..61669b82ddf22 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep @@ -36,3 +36,6 @@ module rg2_TEST './resources/rg2_TEST/rg2_TEST.bicep' = { LOCATION: LOCATION } } + +output STORAGE_PRINCIPAL_ID string = rg1_TEST.outputs.STORAGE_PRINCIPAL_ID +output LOCATION string = rg1_TEST.outputs.LOCATION diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep index d7c4dd861c9ee..8fd8fce8da3e5 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep @@ -41,3 +41,6 @@ resource applicationSettingsResource_MAMFSSuFs 'Microsoft.Web/sites/config@2021- parent: webSite_dOTaZfna6 name: 'appsettings' } + +output STORAGE_PRINCIPAL_ID string = webSite_dOTaZfna6.identity.principalId +output LOCATION string = webSite_dOTaZfna6.location diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep index 0c6b4c11dae18..ce8b1f079710d 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_iyoTs4lhI 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-122b5075e14f4e' +resource storageAccount_YKJfRyF7O 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-a649dd7d16bb48' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_iyoTs4lhI 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_2AWlCCB4v 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_iyoTs4lhI +resource blobService_baXQKLZ5y 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_YKJfRyF7O name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep index 37a91f1b6d4b7..eb0e79fe260b8 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_3NwCr26bs 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-0a5678be9deb41' +resource storageAccount_QWazYJjM3 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-640857a5e25240' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_3NwCr26bs 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_A6eisTKKC 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_3NwCr26bs +resource blobService_GcXijO1R3 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_QWazYJjM3 name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep index c63d530b60280..a1dceb43a30e4 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep @@ -26,3 +26,5 @@ module rg_TEST './resources/rg_TEST/rg_TEST.bicep' = { appUserPassword: appUserPassword } } + +output SERVICE_API_IDENTITY_PRINCIPAL_ID string = rg_TEST.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep index e9c8b3fb0d43f..536cb6a6e93f7 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep @@ -244,3 +244,5 @@ resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021- ENABLE_ORYX_BUILD: 'True' } } + +output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_W5EweSXEq.identity.principalId diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep index 6d685312630af..a1dceb43a30e4 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep @@ -27,4 +27,4 @@ module rg_TEST './resources/rg_TEST/rg_TEST.bicep' = { } } -output SERVICE_API_IDENTITY_PRINCIPAL_ID string = TestFrontEndWebSite.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID +output SERVICE_API_IDENTITY_PRINCIPAL_ID string = rg_TEST.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep index 90c0e97cb4658..436cd38c95c01 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep @@ -245,4 +245,4 @@ resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021- } } -output SERVICE_API_IDENTITY_PRINCIPAL_ID string = TestFrontEndWebSite.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID +output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_W5EweSXEq.identity.principalId diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep index 6d685312630af..a1dceb43a30e4 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep @@ -27,4 +27,4 @@ module rg_TEST './resources/rg_TEST/rg_TEST.bicep' = { } } -output SERVICE_API_IDENTITY_PRINCIPAL_ID string = TestFrontEndWebSite.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID +output SERVICE_API_IDENTITY_PRINCIPAL_ID string = rg_TEST.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep index 4784e63f4adf4..84c7fd826de43 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep @@ -248,4 +248,4 @@ resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021- } } -output SERVICE_API_IDENTITY_PRINCIPAL_ID string = TestFrontEndWebSite.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID +output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_W5EweSXEq.identity.principalId From 778d52c9a38dc25e98475aecc554b409de1df37e Mon Sep 17 00:00:00 2001 From: jolov Date: Fri, 16 Feb 2024 12:19:37 -0800 Subject: [PATCH 11/32] remove commented code --- sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs b/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs index d9ffaa14a59a5..f8d6ee130d182 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs @@ -144,12 +144,6 @@ private void BuildModuleConstructs(Resource resource, Dictionary Date: Fri, 16 Feb 2024 12:21:00 -0800 Subject: [PATCH 12/32] remove blank refdocs --- sdk/provisioning/Azure.Provisioning/src/Parameter.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sdk/provisioning/Azure.Provisioning/src/Parameter.cs b/sdk/provisioning/Azure.Provisioning/src/Parameter.cs index 395e47f18e07c..e59af538cc0df 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Parameter.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Parameter.cs @@ -31,10 +31,6 @@ public class Parameter internal string? Value { get; set; } internal IConstruct? Source { get; set; } - /// - /// - /// - /// internal Parameter(Output output) { Name = output.Name; From 725e73a8ff7aa360a47e03c4e526a959a52533f6 Mon Sep 17 00:00:00 2001 From: jolov Date: Fri, 16 Feb 2024 12:21:20 -0800 Subject: [PATCH 13/32] using --- sdk/provisioning/Azure.Provisioning/src/Resource.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/provisioning/Azure.Provisioning/src/Resource.cs b/sdk/provisioning/Azure.Provisioning/src/Resource.cs index 5a17dd5f8df8a..a1be0a62ec8d0 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Resource.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Resource.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Runtime.InteropServices.ComTypes; using System.Security.Cryptography; using System.Text; using Azure.Core; From b934c99968481487858ec8992552eaf0490b602e Mon Sep 17 00:00:00 2001 From: jolov Date: Fri, 16 Feb 2024 13:31:44 -0800 Subject: [PATCH 14/32] Pass recursive as true --- sdk/provisioning/Azure.Provisioning/src/Construct.cs | 4 ++-- .../Infrastructure/MultipleSubscriptions/main.bicep | 12 ++++++------ .../subscription_H0zKZmECx.bicep} | 2 +- .../subscription_XJpg02kDp.bicep | 10 ---------- .../subscription_dxHHjqL0S.bicep | 10 ---------- .../subscription_jgR3plaUz.bicep} | 2 +- .../resources/rg_TEST/rg_TEST.bicep | 8 ++++---- .../resources/rg_TEST/rg_TEST.bicep | 8 ++++---- 8 files changed, 18 insertions(+), 38 deletions(-) rename sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/{subscription_A5nZSfW0E/subscription_A5nZSfW0E.bicep => subscription_H0zKZmECx/subscription_H0zKZmECx.bicep} (67%) delete mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_XJpg02kDp/subscription_XJpg02kDp.bicep delete mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_dxHHjqL0S/subscription_dxHHjqL0S.bicep rename sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/{subscription_FjgVYijAv/subscription_FjgVYijAv.bicep => subscription_jgR3plaUz/subscription_jgR3plaUz.bicep} (67%) diff --git a/sdk/provisioning/Azure.Provisioning/src/Construct.cs b/sdk/provisioning/Azure.Provisioning/src/Construct.cs index c05b26d7d53e3..3642f23123366 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Construct.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Construct.cs @@ -132,7 +132,7 @@ public IEnumerable GetParameters(bool recursive = true) IEnumerable result = _parameters; if (recursive) { - result = result.Concat(GetConstructs(false).SelectMany(c => c.GetParameters(false))); + result = result.Concat(GetConstructs(true).SelectMany(c => c.GetParameters(false))); } return result; } @@ -143,7 +143,7 @@ public IEnumerable GetOutputs(bool recursive = true) IEnumerable result = _outputs; if (recursive) { - result = result.Concat(GetConstructs(false).SelectMany(c => c.GetOutputs(false))); + result = result.Concat(GetConstructs(true).SelectMany(c => c.GetOutputs(false))); } return result; } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep index 5c034224852e6..5ba302ee2157a 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep @@ -1,12 +1,12 @@ targetScope = 'tenant' -module subscription_XJpg02kDp './resources/subscription_XJpg02kDp/subscription_XJpg02kDp.bicep' = { - name: 'subscription_XJpg02kDp' - scope: subscription('subscription_XJpg02kDp') +module subscription_H0zKZmECx './resources/subscription_H0zKZmECx/subscription_H0zKZmECx.bicep' = { + name: 'subscription_H0zKZmECx' + scope: subscription('subscription_H0zKZmECx') } -module subscription_A5nZSfW0E './resources/subscription_A5nZSfW0E/subscription_A5nZSfW0E.bicep' = { - name: 'subscription_A5nZSfW0E' - scope: subscription('subscription_A5nZSfW0E') +module subscription_jgR3plaUz './resources/subscription_jgR3plaUz/subscription_jgR3plaUz.bicep' = { + name: 'subscription_jgR3plaUz' + scope: subscription('subscription_jgR3plaUz') } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_A5nZSfW0E/subscription_A5nZSfW0E.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_H0zKZmECx/subscription_H0zKZmECx.bicep similarity index 67% rename from sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_A5nZSfW0E/subscription_A5nZSfW0E.bicep rename to sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_H0zKZmECx/subscription_H0zKZmECx.bicep index 1474599bc37c2..0fb931118d74a 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_A5nZSfW0E/subscription_A5nZSfW0E.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_H0zKZmECx/subscription_H0zKZmECx.bicep @@ -1,7 +1,7 @@ targetScope = 'subscription' -resource resourceGroup_VChnO7L2o 'Microsoft.Resources/resourceGroups@2023-07-01' = { +resource resourceGroup_9ItUYtBq7 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' location: 'westus' tags: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_XJpg02kDp/subscription_XJpg02kDp.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_XJpg02kDp/subscription_XJpg02kDp.bicep deleted file mode 100644 index 6ed49f0440732..0000000000000 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_XJpg02kDp/subscription_XJpg02kDp.bicep +++ /dev/null @@ -1,10 +0,0 @@ -targetScope = 'subscription' - - -resource resourceGroup_qL54vnxJc 'Microsoft.Resources/resourceGroups@2023-07-01' = { - name: 'rg-TEST' - location: 'westus' - tags: { - azd-env-name: 'TEST' - } -} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_dxHHjqL0S/subscription_dxHHjqL0S.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_dxHHjqL0S/subscription_dxHHjqL0S.bicep deleted file mode 100644 index ab987eebe1a28..0000000000000 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_dxHHjqL0S/subscription_dxHHjqL0S.bicep +++ /dev/null @@ -1,10 +0,0 @@ -targetScope = 'subscription' - - -resource resourceGroup_1aRP1lqm6 'Microsoft.Resources/resourceGroups@2023-07-01' = { - name: 'rg-TEST' - location: 'westus' - tags: { - azd-env-name: 'TEST' - } -} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_FjgVYijAv/subscription_FjgVYijAv.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_jgR3plaUz/subscription_jgR3plaUz.bicep similarity index 67% rename from sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_FjgVYijAv/subscription_FjgVYijAv.bicep rename to sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_jgR3plaUz/subscription_jgR3plaUz.bicep index f8a31e495f3d4..36dcafb5c76a1 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_FjgVYijAv/subscription_FjgVYijAv.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_jgR3plaUz/subscription_jgR3plaUz.bicep @@ -1,7 +1,7 @@ targetScope = 'subscription' -resource resourceGroup_NPo8hmvYM 'Microsoft.Resources/resourceGroups@2023-07-01' = { +resource resourceGroup_IPz5q5Tg3 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' location: 'westus' tags: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep index ce8b1f079710d..dab691e3d25fa 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_YKJfRyF7O 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-a649dd7d16bb48' +resource storageAccount_uACxct9wM 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-7721a55fbc0c4a' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_YKJfRyF7O 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_baXQKLZ5y 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_YKJfRyF7O +resource blobService_BUffwV226 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_uACxct9wM name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep index eb0e79fe260b8..ca4cb41159bec 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_QWazYJjM3 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-640857a5e25240' +resource storageAccount_7T9xmsrh2 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-73942c65065844' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_QWazYJjM3 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_GcXijO1R3 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_QWazYJjM3 +resource blobService_dpAXvabvu 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_7T9xmsrh2 name: 'default' properties: { cors: { From 0bee48f5ad9453bc288e4af2337c905065693e25 Mon Sep 17 00:00:00 2001 From: jolov Date: Fri, 16 Feb 2024 14:17:20 -0800 Subject: [PATCH 15/32] revert recursive change --- sdk/provisioning/Azure.Provisioning/src/Construct.cs | 4 ++-- .../Infrastructure/MultipleSubscriptions/main.bicep | 12 ++++++------ .../subscription_WreO15EM7.bicep} | 2 +- .../subscription_s6X0EZsY9.bicep} | 2 +- .../resources/rg_TEST/rg_TEST.bicep | 8 ++++---- .../resources/rg_TEST/rg_TEST.bicep | 8 ++++---- 6 files changed, 18 insertions(+), 18 deletions(-) rename sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/{subscription_H0zKZmECx/subscription_H0zKZmECx.bicep => subscription_WreO15EM7/subscription_WreO15EM7.bicep} (67%) rename sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/{subscription_jgR3plaUz/subscription_jgR3plaUz.bicep => subscription_s6X0EZsY9/subscription_s6X0EZsY9.bicep} (67%) diff --git a/sdk/provisioning/Azure.Provisioning/src/Construct.cs b/sdk/provisioning/Azure.Provisioning/src/Construct.cs index 3642f23123366..c05b26d7d53e3 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Construct.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Construct.cs @@ -132,7 +132,7 @@ public IEnumerable GetParameters(bool recursive = true) IEnumerable result = _parameters; if (recursive) { - result = result.Concat(GetConstructs(true).SelectMany(c => c.GetParameters(false))); + result = result.Concat(GetConstructs(false).SelectMany(c => c.GetParameters(false))); } return result; } @@ -143,7 +143,7 @@ public IEnumerable GetOutputs(bool recursive = true) IEnumerable result = _outputs; if (recursive) { - result = result.Concat(GetConstructs(true).SelectMany(c => c.GetOutputs(false))); + result = result.Concat(GetConstructs(false).SelectMany(c => c.GetOutputs(false))); } return result; } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep index 5ba302ee2157a..b412f511dc7cc 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep @@ -1,12 +1,12 @@ targetScope = 'tenant' -module subscription_H0zKZmECx './resources/subscription_H0zKZmECx/subscription_H0zKZmECx.bicep' = { - name: 'subscription_H0zKZmECx' - scope: subscription('subscription_H0zKZmECx') +module subscription_s6X0EZsY9 './resources/subscription_s6X0EZsY9/subscription_s6X0EZsY9.bicep' = { + name: 'subscription_s6X0EZsY9' + scope: subscription('subscription_s6X0EZsY9') } -module subscription_jgR3plaUz './resources/subscription_jgR3plaUz/subscription_jgR3plaUz.bicep' = { - name: 'subscription_jgR3plaUz' - scope: subscription('subscription_jgR3plaUz') +module subscription_WreO15EM7 './resources/subscription_WreO15EM7/subscription_WreO15EM7.bicep' = { + name: 'subscription_WreO15EM7' + scope: subscription('subscription_WreO15EM7') } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_H0zKZmECx/subscription_H0zKZmECx.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_WreO15EM7/subscription_WreO15EM7.bicep similarity index 67% rename from sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_H0zKZmECx/subscription_H0zKZmECx.bicep rename to sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_WreO15EM7/subscription_WreO15EM7.bicep index 0fb931118d74a..12cad18bfefe2 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_H0zKZmECx/subscription_H0zKZmECx.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_WreO15EM7/subscription_WreO15EM7.bicep @@ -1,7 +1,7 @@ targetScope = 'subscription' -resource resourceGroup_9ItUYtBq7 'Microsoft.Resources/resourceGroups@2023-07-01' = { +resource resourceGroup_uZaTsPn5V 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' location: 'westus' tags: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_jgR3plaUz/subscription_jgR3plaUz.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_s6X0EZsY9/subscription_s6X0EZsY9.bicep similarity index 67% rename from sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_jgR3plaUz/subscription_jgR3plaUz.bicep rename to sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_s6X0EZsY9/subscription_s6X0EZsY9.bicep index 36dcafb5c76a1..109d19bc49149 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_jgR3plaUz/subscription_jgR3plaUz.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_s6X0EZsY9/subscription_s6X0EZsY9.bicep @@ -1,7 +1,7 @@ targetScope = 'subscription' -resource resourceGroup_IPz5q5Tg3 'Microsoft.Resources/resourceGroups@2023-07-01' = { +resource resourceGroup_z2M9YcgTp 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' location: 'westus' tags: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep index dab691e3d25fa..0ebc0de51ad61 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_uACxct9wM 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-7721a55fbc0c4a' +resource storageAccount_BCgLcttHF 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-d1811b9b1d194d' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_uACxct9wM 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_BUffwV226 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_uACxct9wM +resource blobService_pYQLNFbTQ 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_BCgLcttHF name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep index ca4cb41159bec..d78371618932c 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_7T9xmsrh2 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-73942c65065844' +resource storageAccount_bMTglVxrj 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-1d1f34e6a3be44' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_7T9xmsrh2 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_dpAXvabvu 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_7T9xmsrh2 +resource blobService_NXFUDK0Bk 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_bMTglVxrj name: 'default' properties: { cors: { From 8ec68ad54312057744e2de4b8d0162a2410e4054 Mon Sep 17 00:00:00 2001 From: jolov Date: Fri, 16 Feb 2024 22:28:10 -0800 Subject: [PATCH 16/32] PR fb --- .../Azure.Provisioning/Azure.Provisioning.sln | 6 + .../Azure.Provisioning/src/Construct.cs | 19 +- .../Azure.Provisioning/src/Infrastructure.cs | 216 +----------------- .../Azure.Provisioning/src/ModuleConstruct.cs | 57 +++++ .../src/ModuleInfrastructure.cs | 213 +++++++++++++++++ .../Azure.Provisioning/src/ModuleResource.cs | 18 ++ .../tests/Azure.Provisioning.Tests.csproj | 1 + .../MultipleSubscriptions/main.bicep | 12 +- .../subscription_O0vZNnri3.bicep} | 2 +- .../subscription_i7MQMw1U7.bicep} | 2 +- .../resources/rg_TEST/rg_TEST.bicep | 8 +- .../resources/rg_TEST/rg_TEST.bicep | 8 +- .../tests/ProvisioningTests.cs | 8 +- 13 files changed, 332 insertions(+), 238 deletions(-) create mode 100644 sdk/provisioning/Azure.Provisioning/src/ModuleConstruct.cs create mode 100644 sdk/provisioning/Azure.Provisioning/src/ModuleInfrastructure.cs create mode 100644 sdk/provisioning/Azure.Provisioning/src/ModuleResource.cs rename sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/{subscription_WreO15EM7/subscription_WreO15EM7.bicep => subscription_O0vZNnri3/subscription_O0vZNnri3.bicep} (67%) rename sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/{subscription_s6X0EZsY9/subscription_s6X0EZsY9.bicep => subscription_i7MQMw1U7/subscription_i7MQMw1U7.bicep} (67%) diff --git a/sdk/provisioning/Azure.Provisioning/Azure.Provisioning.sln b/sdk/provisioning/Azure.Provisioning/Azure.Provisioning.sln index dfcd7b45d199d..4ae7ebb0e78ff 100644 --- a/sdk/provisioning/Azure.Provisioning/Azure.Provisioning.sln +++ b/sdk/provisioning/Azure.Provisioning/Azure.Provisioning.sln @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Provisioning", "src\A EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Provisioning.Tests", "tests\Azure.Provisioning.Tests.csproj", "{BC884FD9-0973-4FD2-A112-F285F041A3B2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Core.TestFramework", "..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj", "{A93F6964-45B3-4F08-BB85-EBC3BAC40B72}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {BC884FD9-0973-4FD2-A112-F285F041A3B2}.Debug|Any CPU.Build.0 = Debug|Any CPU {BC884FD9-0973-4FD2-A112-F285F041A3B2}.Release|Any CPU.ActiveCfg = Release|Any CPU {BC884FD9-0973-4FD2-A112-F285F041A3B2}.Release|Any CPU.Build.0 = Release|Any CPU + {A93F6964-45B3-4F08-BB85-EBC3BAC40B72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A93F6964-45B3-4F08-BB85-EBC3BAC40B72}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A93F6964-45B3-4F08-BB85-EBC3BAC40B72}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A93F6964-45B3-4F08-BB85-EBC3BAC40B72}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/sdk/provisioning/Azure.Provisioning/src/Construct.cs b/sdk/provisioning/Azure.Provisioning/src/Construct.cs index c05b26d7d53e3..63d633a092468 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Construct.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Construct.cs @@ -50,13 +50,20 @@ public abstract class Construct : IConstruct, IPersistableModel /// The environment name to use. If not passed in will try to load from AZURE_ENV_NAME environment variable. /// is and is null. protected Construct(IConstruct? scope, string name, ConstructScope constructScope = ConstructScope.ResourceGroup, Guid? tenantId = null, Guid? subscriptionId = null, string? envName = null) - : this(scope, name, constructScope, tenantId, subscriptionId, envName, null) + : this(scope, name, constructScope, tenantId, subscriptionId, envName, null, null, null) { } - internal Construct(IConstruct? scope, string name, ConstructScope constructScope = ConstructScope.ResourceGroup, - Guid? tenantId = null, Guid? subscriptionId = null, string? envName = null, - ResourceGroup? resourceGroup = null) + internal Construct( + IConstruct? scope, + string name, + ConstructScope constructScope, + Guid? tenantId = default, + Guid? subscriptionId = default, + string? envName = default, + Tenant? tenant = default, + Subscription? subscription = default, + ResourceGroup? resourceGroup = default) { if (scope is null && constructScope == ConstructScope.ResourceGroup) { @@ -71,7 +78,7 @@ internal Construct(IConstruct? scope, string name, ConstructScope constructScope _constructs = new List(); _existingResources = new List(); Name = name; - Root = scope?.Root ?? new Tenant(this, tenantId); + Root = tenant ?? scope?.Root ?? new Tenant(this, tenantId); ConstructScope = constructScope; if (constructScope == ConstructScope.ResourceGroup) { @@ -79,7 +86,7 @@ internal Construct(IConstruct? scope, string name, ConstructScope constructScope } if (constructScope == ConstructScope.Subscription) { - Subscription = scope is null ? this.GetOrCreateSubscription(subscriptionId) : scope.Subscription ?? scope.GetOrCreateSubscription(subscriptionId); + Subscription = subscription ?? (scope is null ? this.GetOrCreateSubscription(subscriptionId) : scope.Subscription ?? scope.GetOrCreateSubscription(subscriptionId)); } _environmentName = envName; diff --git a/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs b/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs index f8d6ee130d182..742cfa84224eb 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs @@ -2,11 +2,6 @@ // Licensed under the MIT License. using System; -using System.ClientModel.Primitives; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Azure.Provisioning.ResourceManager; namespace Azure.Provisioning { @@ -35,216 +30,9 @@ public Infrastructure(ConstructScope constructScope = ConstructScope.Subscriptio /// Path to put the files. public void Build(string? outputPath = null) { - outputPath ??= $".\\{GetType().Name}"; - outputPath = Path.GetFullPath(outputPath); + var moduleInfrastructure = new ModuleInfrastructure(this); - Dictionary> resourceTree = BuildResourceTree(); - - ModuleConstruct? root = null; - BuildModuleConstructs(Root, resourceTree, null, ref root); - - AddOutputsToModules(); - - WriteBicepFile(root!, outputPath); - - var queue = new Queue(); - queue.Enqueue(root!); - WriteConstructsByLevel(queue, outputPath); - } - - private void AddOutputsToModules() - { - // Get all of the user-defined constructs in addition to the Infrastructure construct - foreach (var construct in GetConstructs(true).Where(c => c is not ModuleConstruct).Concat(new[] { this })) - { - // ToList to avoid modifying the collection while iterating - foreach (var output in construct.GetOutputs(false).ToList()) - { - var moduleOutput = new Output(output.Name, output.Value, output.Resource.ModuleScope!, - output.Resource, output.IsLiteral, output.IsSecure); - output.Resource.ModuleScope!.AddOutput(moduleOutput); - } - } - } - - private Dictionary> BuildResourceTree() - { - var resources = GetResources(true); - Dictionary> resourceTree = new(); - HashSet visited = new(); - foreach (var resource in resources) - { - VisitResource(resource, resourceTree, visited); - } - - return resourceTree; - } - - private void VisitResource(Resource resource, Dictionary> resourceTree, HashSet visited) - { - if (!visited.Add(resource)) - { - return; - } - - if (!resourceTree.ContainsKey(resource)) - { - resourceTree[resource] = new List(); - } - - if (resource.Parent != null) - { - if (!resourceTree.ContainsKey(resource.Parent)) - { - resourceTree[resource.Parent] = new List(); - } - resourceTree[resource.Parent].Add(resource); - VisitResource(resource.Parent, resourceTree, visited); - } - } - - private void BuildModuleConstructs(Resource resource, Dictionary> resourceTree, ModuleConstruct? parentScope, ref ModuleConstruct? root) - { - ModuleConstruct? construct = null; - if (NeedsModuleConstruct(resource, resourceTree)) - { - construct = new ModuleConstruct(resource); - - if (parentScope == null) - { - root = construct; - construct.IsRoot = true; - } - } - - if (construct != null) - { - parentScope?.AddConstruct(construct); - } - - if (parentScope != null) - { - parentScope.AddResource(resource); - resource.ModuleScope = parentScope; - } - - parentScope = parentScope ?? construct; - if (parentScope != null) - { - foreach (var parameter in resource.Parameters) - { - parentScope.AddParameter(parameter); - } - - foreach (var parameterOverrideDictionary in resource.ParameterOverrides) - { - foreach (var parameterOverride in parameterOverrideDictionary.Value) - { - parameterOverride.Value.Source = parentScope; - parameterOverride.Value.Value = GetParameterValue(parameterOverride.Value, parentScope); - } - } - } - - foreach (var child in resourceTree[resource]) - { - BuildModuleConstructs(child, resourceTree, construct ?? parentScope, ref root); - } - } - - private static string GetParameterValue(Parameter parameter, IConstruct scope) - { - // If the parameter is a parameter of the module scope, use the parameter name. - if (scope.GetParameters(false).Contains(parameter)) - { - return parameter.Name; - } - // Otherwise we assume it is an output from the current module. - if ( parameter.Source is null || ReferenceEquals(parameter.Source, scope)) - { - return parameter.Value!; - } - - return $"{parameter.Source.Name}.outputs.{parameter.Name}"; - } - - private static ConstructScope ResourceToConstructScope(Resource resource) - { - return resource switch - { - Tenant => ConstructScope.Tenant, - ResourceManager.Subscription => ConstructScope.Subscription, - //TODO managementgroup support - ResourceManager.ResourceGroup => ConstructScope.ResourceGroup, - _ => throw new InvalidOperationException(), - }; - } - - private bool NeedsModuleConstruct(Resource resource, Dictionary> resourceTree) - { - if (!(resource is Tenant || resource is Subscription || resource is ResourceGroup)) - { - return false; - } - if (resource is Tenant) - { - // TODO add management group check - return resourceTree[resource].Count > 1; - } - if (resource is Subscription || resource is ResourceGroup) - { - // TODO add policy support - return resourceTree[resource].Count > 0; - } - - return false; - } - - private void WriteConstructsByLevel(Queue constructs, string outputPath) - { - while (constructs.Count > 0) - { - var construct = constructs.Dequeue(); - foreach (var child in construct.GetConstructs(false)) - { - constructs.Enqueue((ModuleConstruct)child); - } - WriteBicepFile(construct, outputPath); - } - } - - private string GetFilePath(ModuleConstruct construct, string outputPath) - { - string fileName = construct.IsRoot ? Path.Combine(outputPath, "main.bicep") : Path.Combine(outputPath, "resources", construct.Name, $"{construct.Name}.bicep"); - Directory.CreateDirectory(Path.GetDirectoryName(fileName)!); - return fileName; - } - - private void WriteBicepFile(ModuleConstruct construct, string outputPath) - { - using var stream = new FileStream(GetFilePath(construct, outputPath), FileMode.Create); -#if NET6_0_OR_GREATER - stream.Write(ModelReaderWriter.Write(construct, new ModelReaderWriterOptions("bicep"))); -#else - BinaryData data = ModelReaderWriter.Write(construct, new ModelReaderWriterOptions("bicep")); - var buffer = data.ToArray(); - stream.Write(buffer, 0, buffer.Length); -#endif - } - - private class ModuleConstruct : Construct - { - public ModuleConstruct(Resource resource) - : base( - resource.Scope, - resource is Subscription ? resource.Name : resource.Id.Name.Replace('-', '_'), - ResourceToConstructScope(resource), - subscriptionId: resource is not Tenant ? Guid.Parse(resource.Id.SubscriptionId!) : null, - resourceGroup: resource as ResourceGroup) - { - } - - public bool IsRoot { get; set; } + moduleInfrastructure.Write(outputPath); } } } diff --git a/sdk/provisioning/Azure.Provisioning/src/ModuleConstruct.cs b/sdk/provisioning/Azure.Provisioning/src/ModuleConstruct.cs new file mode 100644 index 0000000000000..d7a962e6af3ae --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/src/ModuleConstruct.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Azure.Provisioning.ResourceManager; + +namespace Azure.Provisioning +{ + internal class ModuleConstruct : Construct + { + public ModuleConstruct(ModuleResource resource) + : base( + resource.Scope, + resource.Resource is Subscription ? resource.Resource.Name : resource.Resource.Id.Name.Replace('-', '_'), + ResourceToConstructScope(resource.Resource), + tenant: GetTenant(resource.Resource), + subscription: GetSubscription(resource.Resource), + resourceGroup: resource.Resource as ResourceGroup) + { + } + + public bool IsRoot { get; set; } + + private static Tenant? GetTenant(Resource resource) + { + return resource switch + { + Tenant tenant => tenant, + Subscription sub => (Tenant) sub.Parent!, + ResourceGroup rg => (Tenant) rg.Parent!.Parent!, + _ => null, + }; + } + + private static Subscription? GetSubscription(Resource resource) + { + return resource switch + { + Subscription subscription => subscription, + ResourceGroup rg => (Subscription) rg.Parent!, + _ => null, + }; + } + + private static ConstructScope ResourceToConstructScope(Resource resource) + { + return resource switch + { + Tenant => ConstructScope.Tenant, + ResourceManager.Subscription => ConstructScope.Subscription, + //TODO managementgroup support + ResourceManager.ResourceGroup => ConstructScope.ResourceGroup, + _ => throw new InvalidOperationException(), + }; + } + } +} diff --git a/sdk/provisioning/Azure.Provisioning/src/ModuleInfrastructure.cs b/sdk/provisioning/Azure.Provisioning/src/ModuleInfrastructure.cs new file mode 100644 index 0000000000000..93c68585ccf2c --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/src/ModuleInfrastructure.cs @@ -0,0 +1,213 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Azure.Provisioning.ResourceManager; + +namespace Azure.Provisioning +{ + internal class ModuleInfrastructure + { + private readonly Infrastructure _infrastructure; + private readonly ModuleConstruct _rootConstruct; + + public ModuleInfrastructure(Infrastructure infrastructure) + { + _infrastructure = infrastructure; + Dictionary> resourceTree = BuildResourceTree(); + + ModuleConstruct? root = null; + BuildModuleConstructs(_infrastructure.Root, resourceTree, null, ref root); + _rootConstruct = root!; + + AddOutputsToModules(); + } + + public void Write(string? outputPath = null) + { + outputPath ??= $".\\{GetType().Name}"; + outputPath = Path.GetFullPath(outputPath); + + WriteBicepFile(_rootConstruct, outputPath); + + var queue = new Queue(); + queue.Enqueue(_rootConstruct); + WriteConstructsByLevel(queue, outputPath); + } + + private void AddOutputsToModules() + { + // Get all of the user-defined constructs in addition to the Infrastructure construct + foreach (var construct in _infrastructure.GetConstructs(true).Concat(new[] { _infrastructure })) + { + // ToList to avoid modifying the collection while iterating + foreach (var output in construct.GetOutputs(false).ToList()) + { + var moduleOutput = new Output( + output.Name, + output.Value, + output.Resource.ModuleScope!, + output.Resource, + output.IsLiteral, + output.IsSecure); + + output.Resource.ModuleScope!.AddOutput(moduleOutput); + } + } + } + + private Dictionary> BuildResourceTree() + { + var resources = _infrastructure.GetResources(true); + Dictionary> resourceTree = new(); + HashSet visited = new(); + foreach (var resource in resources) + { + VisitResource(resource, resourceTree, visited); + } + + return resourceTree; + } + + private void VisitResource(Resource resource, Dictionary> resourceTree, HashSet visited) + { + if (!visited.Add(resource)) + { + return; + } + + if (!resourceTree.ContainsKey(resource)) + { + resourceTree[resource] = new List(); + } + + if (resource.Parent != null) + { + if (!resourceTree.ContainsKey(resource.Parent)) + { + resourceTree[resource.Parent] = new List(); + } + resourceTree[resource.Parent].Add(resource); + VisitResource(resource.Parent, resourceTree, visited); + } + } + + private void BuildModuleConstructs(Resource resource, Dictionary> resourceTree, ModuleConstruct? parentScope, ref ModuleConstruct? root) + { + ModuleConstruct? construct = null; + var moduleResource = new ModuleResource(resource, parentScope); + + if (NeedsModuleConstruct(resource, resourceTree)) + { + construct = new ModuleConstruct(moduleResource); + + if (parentScope == null) + { + root = construct; + construct.IsRoot = true; + parentScope = construct; + } + } + + if (parentScope != null) + { + parentScope.AddResource(resource); + resource.ModuleScope = parentScope; + } + + if (parentScope != null) + { + foreach (var parameter in resource.Parameters) + { + parentScope.AddParameter(parameter); + } + + foreach (var parameterOverrideDictionary in resource.ParameterOverrides) + { + foreach (var parameterOverride in parameterOverrideDictionary.Value) + { + parameterOverride.Value.Source = parentScope; + parameterOverride.Value.Value = GetParameterValue(parameterOverride.Value, parentScope); + } + } + } + + foreach (var child in resourceTree[resource]) + { + BuildModuleConstructs(child, resourceTree, construct ?? parentScope, ref root); + } + } + + private static string GetParameterValue(Parameter parameter, IConstruct scope) + { + // If the parameter is a parameter of the module scope, use the parameter name. + if (scope.GetParameters(false).Contains(parameter)) + { + return parameter.Name; + } + // Otherwise we assume it is an output from the current module. + if ( parameter.Source is null || ReferenceEquals(parameter.Source, scope)) + { + return parameter.Value!; + } + + return $"{parameter.Source.Name}.outputs.{parameter.Name}"; + } + + private bool NeedsModuleConstruct(Resource resource, Dictionary> resourceTree) + { + if (!(resource is Tenant || resource is Subscription || resource is ResourceGroup)) + { + return false; + } + if (resource is Tenant) + { + // TODO add management group check + return resourceTree[resource].Count > 1; + } + if (resource is Subscription || resource is ResourceGroup) + { + // TODO add policy support + return resourceTree[resource].Count > 0; + } + + return false; + } + + private void WriteConstructsByLevel(Queue constructs, string outputPath) + { + while (constructs.Count > 0) + { + var construct = constructs.Dequeue(); + foreach (var child in construct.GetConstructs(false)) + { + constructs.Enqueue((ModuleConstruct)child); + } + WriteBicepFile(construct, outputPath); + } + } + + private string GetFilePath(ModuleConstruct construct, string outputPath) + { + string fileName = construct.IsRoot ? Path.Combine(outputPath, "main.bicep") : Path.Combine(outputPath, "resources", construct.Name, $"{construct.Name}.bicep"); + Directory.CreateDirectory(Path.GetDirectoryName(fileName)!); + return fileName; + } + + private void WriteBicepFile(ModuleConstruct construct, string outputPath) + { + using var stream = new FileStream(GetFilePath(construct, outputPath), FileMode.Create); +#if NET6_0_OR_GREATER + stream.Write(ModelReaderWriter.Write(construct, new ModelReaderWriterOptions("bicep"))); +#else + BinaryData data = ModelReaderWriter.Write(construct, new ModelReaderWriterOptions("bicep")); + var buffer = data.ToArray(); + stream.Write(buffer, 0, buffer.Length); +#endif + } + } +} diff --git a/sdk/provisioning/Azure.Provisioning/src/ModuleResource.cs b/sdk/provisioning/Azure.Provisioning/src/ModuleResource.cs new file mode 100644 index 0000000000000..0ba71b81d4712 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/src/ModuleResource.cs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Azure.Provisioning +{ + internal class ModuleResource + { + public Resource Resource { get; } + + public ModuleConstruct? Scope { get; } + + public ModuleResource(Resource resource, ModuleConstruct? scope) + { + Resource = resource; + Scope = scope; + } + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Azure.Provisioning.Tests.csproj b/sdk/provisioning/Azure.Provisioning/tests/Azure.Provisioning.Tests.csproj index e1fd392f2fe0a..961469ea67ecb 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Azure.Provisioning.Tests.csproj +++ b/sdk/provisioning/Azure.Provisioning/tests/Azure.Provisioning.Tests.csproj @@ -13,6 +13,7 @@ + diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep index b412f511dc7cc..bbd8a186882d6 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/main.bicep @@ -1,12 +1,12 @@ targetScope = 'tenant' -module subscription_s6X0EZsY9 './resources/subscription_s6X0EZsY9/subscription_s6X0EZsY9.bicep' = { - name: 'subscription_s6X0EZsY9' - scope: subscription('subscription_s6X0EZsY9') +module subscription_O0vZNnri3 './resources/subscription_O0vZNnri3/subscription_O0vZNnri3.bicep' = { + name: 'subscription_O0vZNnri3' + scope: subscription('subscription_O0vZNnri3') } -module subscription_WreO15EM7 './resources/subscription_WreO15EM7/subscription_WreO15EM7.bicep' = { - name: 'subscription_WreO15EM7' - scope: subscription('subscription_WreO15EM7') +module subscription_i7MQMw1U7 './resources/subscription_i7MQMw1U7/subscription_i7MQMw1U7.bicep' = { + name: 'subscription_i7MQMw1U7' + scope: subscription('subscription_i7MQMw1U7') } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_WreO15EM7/subscription_WreO15EM7.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_O0vZNnri3/subscription_O0vZNnri3.bicep similarity index 67% rename from sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_WreO15EM7/subscription_WreO15EM7.bicep rename to sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_O0vZNnri3/subscription_O0vZNnri3.bicep index 12cad18bfefe2..b5a56e206b2e6 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_WreO15EM7/subscription_WreO15EM7.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_O0vZNnri3/subscription_O0vZNnri3.bicep @@ -1,7 +1,7 @@ targetScope = 'subscription' -resource resourceGroup_uZaTsPn5V 'Microsoft.Resources/resourceGroups@2023-07-01' = { +resource resourceGroup_grHjXx8QF 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' location: 'westus' tags: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_s6X0EZsY9/subscription_s6X0EZsY9.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_i7MQMw1U7/subscription_i7MQMw1U7.bicep similarity index 67% rename from sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_s6X0EZsY9/subscription_s6X0EZsY9.bicep rename to sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_i7MQMw1U7/subscription_i7MQMw1U7.bicep index 109d19bc49149..deaf9f44d800b 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_s6X0EZsY9/subscription_s6X0EZsY9.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_i7MQMw1U7/subscription_i7MQMw1U7.bicep @@ -1,7 +1,7 @@ targetScope = 'subscription' -resource resourceGroup_z2M9YcgTp 'Microsoft.Resources/resourceGroups@2023-07-01' = { +resource resourceGroup_U95xWHMzX 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' location: 'westus' tags: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep index 0ebc0de51ad61..75f2538f52571 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_BCgLcttHF 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-d1811b9b1d194d' +resource storageAccount_GGbBhjSY6 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-805a47f9e27440' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_BCgLcttHF 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_pYQLNFbTQ 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_BCgLcttHF +resource blobService_aH4lyE35l 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_GGbBhjSY6 name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep index d78371618932c..acfd33a5d4e69 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_bMTglVxrj 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-1d1f34e6a3be44' +resource storageAccount_gzXK780Fx 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-4341cc8e997a46' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_bMTglVxrj 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_NXFUDK0Bk 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_bMTglVxrj +resource blobService_SjmRxBBDk 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_gzXK780Fx name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs index 9a72ebf54aa1d..1c805fbb91036 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs +++ b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs @@ -6,6 +6,8 @@ using System; using System.IO; using System.Diagnostics; +using Azure.Core.TestFramework; +using Azure.Core.Tests.TestFramework; using Azure.Provisioning.AppService; using Azure.Provisioning.KeyVaults; using Azure.Provisioning.Sql; @@ -143,9 +145,11 @@ public void AppConfiguration() [Test] public void MultipleSubscriptions() { + // ensure deterministic subscription names and directories + var random = new TestRandom(RecordedTestMode.Playback, 1); var infra = new TestSubscriptionInfrastructure(); - var sub1 = new Subscription(infra, Guid.NewGuid()); - var sub2 = new Subscription(infra, Guid.NewGuid()); + var sub1 = new Subscription(infra, random.NewGuid()); + var sub2 = new Subscription(infra, random.NewGuid()); _ = new ResourceGroup(infra, parent: sub1); _ = new ResourceGroup(infra, parent: sub2); infra.Build(GetOutputPath()); From 613d5067e24ad3dbf3941d8a529700df377ecc48 Mon Sep 17 00:00:00 2001 From: jolov Date: Fri, 16 Feb 2024 22:31:05 -0800 Subject: [PATCH 17/32] pass true as recursive arg --- sdk/provisioning/Azure.Provisioning/src/Construct.cs | 6 +++--- .../StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep | 8 ++++---- .../StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sdk/provisioning/Azure.Provisioning/src/Construct.cs b/sdk/provisioning/Azure.Provisioning/src/Construct.cs index 63d633a092468..eaeef066a2444 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Construct.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Construct.cs @@ -128,7 +128,7 @@ public IEnumerable GetConstructs(bool recursive = true) IEnumerable result = _constructs; if (recursive) { - result = result.Concat(GetConstructs(false).SelectMany(c => c.GetConstructs(false))); + result = result.Concat(GetConstructs(true).SelectMany(c => c.GetConstructs(false))); } return result; } @@ -139,7 +139,7 @@ public IEnumerable GetParameters(bool recursive = true) IEnumerable result = _parameters; if (recursive) { - result = result.Concat(GetConstructs(false).SelectMany(c => c.GetParameters(false))); + result = result.Concat(GetConstructs(true).SelectMany(c => c.GetParameters(false))); } return result; } @@ -150,7 +150,7 @@ public IEnumerable GetOutputs(bool recursive = true) IEnumerable result = _outputs; if (recursive) { - result = result.Concat(GetConstructs(false).SelectMany(c => c.GetOutputs(false))); + result = result.Concat(GetConstructs(true).SelectMany(c => c.GetOutputs(false))); } return result; } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep index 75f2538f52571..709ac262f5ad3 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_GGbBhjSY6 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-805a47f9e27440' +resource storageAccount_09oO2xkqI 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-bfa7580cfd5449' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_GGbBhjSY6 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_aH4lyE35l 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_GGbBhjSY6 +resource blobService_fWKBSsxJN 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_09oO2xkqI name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep index acfd33a5d4e69..06d2516d5ce6a 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_gzXK780Fx 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-4341cc8e997a46' +resource storageAccount_8bHLfyPqi 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-8886a0cd521940' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_gzXK780Fx 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_SjmRxBBDk 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_gzXK780Fx +resource blobService_XWfhyHJIP 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_8bHLfyPqi name: 'default' properties: { cors: { From 925b3131dd0505db0bf2907b3b968d98b8e59dd9 Mon Sep 17 00:00:00 2001 From: jolov Date: Sat, 17 Feb 2024 09:38:40 -0800 Subject: [PATCH 18/32] Fix recursive call and don't mutate Parameter --- .../Azure.Provisioning/src/Construct.cs | 8 ++++---- .../src/ModuleInfrastructure.cs | 18 ++++++++++++------ .../Azure.Provisioning/src/Parameter.cs | 16 +++++++++++++--- .../Azure.Provisioning/src/Resource.cs | 19 ++++++++++++++++++- .../resources/rg_TEST/rg_TEST.bicep | 8 ++++---- .../resources/rg_TEST/rg_TEST.bicep | 8 ++++---- 6 files changed, 55 insertions(+), 22 deletions(-) diff --git a/sdk/provisioning/Azure.Provisioning/src/Construct.cs b/sdk/provisioning/Azure.Provisioning/src/Construct.cs index eaeef066a2444..c199ba59b2a6b 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Construct.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Construct.cs @@ -117,7 +117,7 @@ public IEnumerable GetResources(bool recursive = true) IEnumerable result = _resources; if (recursive) { - result = result.Concat(GetConstructs(true).SelectMany(c => c.GetResources(false))); + result = result.Concat(GetConstructs(false).SelectMany(c => c.GetResources(true))); } return result; } @@ -128,7 +128,7 @@ public IEnumerable GetConstructs(bool recursive = true) IEnumerable result = _constructs; if (recursive) { - result = result.Concat(GetConstructs(true).SelectMany(c => c.GetConstructs(false))); + result = result.Concat(GetConstructs(false).SelectMany(c => c.GetConstructs(true))); } return result; } @@ -139,7 +139,7 @@ public IEnumerable GetParameters(bool recursive = true) IEnumerable result = _parameters; if (recursive) { - result = result.Concat(GetConstructs(true).SelectMany(c => c.GetParameters(false))); + result = result.Concat(GetConstructs(false).SelectMany(c => c.GetParameters(true))); } return result; } @@ -150,7 +150,7 @@ public IEnumerable GetOutputs(bool recursive = true) IEnumerable result = _outputs; if (recursive) { - result = result.Concat(GetConstructs(true).SelectMany(c => c.GetOutputs(false))); + result = result.Concat(GetConstructs(false).SelectMany(c => c.GetOutputs(true))); } return result; } diff --git a/sdk/provisioning/Azure.Provisioning/src/ModuleInfrastructure.cs b/sdk/provisioning/Azure.Provisioning/src/ModuleInfrastructure.cs index 93c68585ccf2c..bec8243077748 100644 --- a/sdk/provisioning/Azure.Provisioning/src/ModuleInfrastructure.cs +++ b/sdk/provisioning/Azure.Provisioning/src/ModuleInfrastructure.cs @@ -126,12 +126,18 @@ private void BuildModuleConstructs(Resource resource, Dictionary p.Name == parameter.Name)) { return parameter.Name; } // Otherwise we assume it is an output from the current module. - if ( parameter.Source is null || ReferenceEquals(parameter.Source, scope)) + if (parameter.Source is null || ReferenceEquals(parameter.Source, scope)) { return parameter.Value!; } diff --git a/sdk/provisioning/Azure.Provisioning/src/Parameter.cs b/sdk/provisioning/Azure.Provisioning/src/Parameter.cs index e59af538cc0df..ba353a551ab60 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Parameter.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Parameter.cs @@ -7,7 +7,7 @@ namespace Azure.Provisioning /// Represents a parameter of an . /// #pragma warning disable AZC0012 // Avoid single word type names - public class Parameter + public struct Parameter #pragma warning restore AZC0012 // Avoid single word type names { /// @@ -28,8 +28,8 @@ public class Parameter public bool IsSecure { get; } internal bool IsFromOutput { get; } internal bool IsLiteral { get; } - internal string? Value { get; set; } - internal IConstruct? Source { get; set; } + internal string? Value { get; } + internal IConstruct? Source { get; } internal Parameter(Output output) { @@ -41,6 +41,16 @@ internal Parameter(Output output) Source = output.Source; } + internal Parameter(string name, string? description, object? defaultValue, bool isSecure, IConstruct source, string? value) + { + Name = name; + Description = description; + DefaultValue = defaultValue; + IsSecure = isSecure; + Source = source; + Value = value; + } + /// /// Initializes a new instance of the . /// diff --git a/sdk/provisioning/Azure.Provisioning/src/Resource.cs b/sdk/provisioning/Azure.Provisioning/src/Resource.cs index a1be0a62ec8d0..70a65917e9d30 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Resource.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Resource.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq; using System.Security.Cryptography; using System.Text; using Azure.Core; @@ -240,7 +241,7 @@ private BinaryData SerializeModule(ModelReaderWriterOptions options) var dict = new Dictionary(); foreach (var kvp in parameter.Value) { - dict.Add(kvp.Key, kvp.Value.Value!); + dict.Add(kvp.Key, GetParameterString(kvp.Value, ModuleScope!)); } bicepOptions.ParameterOverrides.Add(parameter.Key, dict); } @@ -272,6 +273,22 @@ private bool NeedsScope() } } + private static string GetParameterString(Parameter parameter, IConstruct scope) + { + // If the parameter is a parameter of the module scope, use the parameter name. + if (scope.GetParameters(false).Any(p => p.Name == parameter.Name)) + { + return parameter.Name; + } + // Otherwise we assume it is an output from the current module. + if (parameter.Source is null || ReferenceEquals(parameter.Source, scope)) + { + return parameter.Value!; + } + + return $"{parameter.Source.Name}.outputs.{parameter.Name}"; + } + private static void WriteLines(int depth, BinaryData data, MemoryStream stream, Resource resource) { string indent = new string(' ', depth * 2); diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep index 709ac262f5ad3..117d48df51d1f 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_09oO2xkqI 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-bfa7580cfd5449' +resource storageAccount_e0WVEoLUA 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-84ab8d2397fc43' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_09oO2xkqI 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_fWKBSsxJN 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_09oO2xkqI +resource blobService_srpkzSrZI 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_e0WVEoLUA name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep index 06d2516d5ce6a..78ac9d0b1cd1e 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_8bHLfyPqi 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-8886a0cd521940' +resource storageAccount_w0IyPyjWx 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-40c65c3529144b' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_8bHLfyPqi 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_XWfhyHJIP 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_8bHLfyPqi +resource blobService_n5wAMCYIG 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_w0IyPyjWx name: 'default' properties: { cors: { From ceceb89c0edf0ac2630db38d31202182b5d5d5a3 Mon Sep 17 00:00:00 2001 From: jolov Date: Sat, 17 Feb 2024 09:39:03 -0800 Subject: [PATCH 19/32] API --- .../Azure.Provisioning/api/Azure.Provisioning.net6.0.cs | 7 +++++-- .../api/Azure.Provisioning.netstandard2.0.cs | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) 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 6bcb94897c340..2da63f018c313 100644 --- a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs +++ b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs @@ -66,9 +66,12 @@ internal Output() { } public string Name { get { throw null; } } public string Value { get { throw null; } } } - public partial class Parameter + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public partial struct Parameter { - public Parameter(string name, string? description = null, object? defaultValue = null, bool isSecure = false) { } + private object _dummy; + private int _dummyPrimitive; + public Parameter(string name, string? description = null, object? defaultValue = null, bool isSecure = false) { throw null; } public object? DefaultValue { get { throw null; } } public string? Description { get { throw null; } } public bool IsSecure { get { throw null; } } 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 6bcb94897c340..2da63f018c313 100644 --- a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs +++ b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs @@ -66,9 +66,12 @@ internal Output() { } public string Name { get { throw null; } } public string Value { get { throw null; } } } - public partial class Parameter + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public partial struct Parameter { - public Parameter(string name, string? description = null, object? defaultValue = null, bool isSecure = false) { } + private object _dummy; + private int _dummyPrimitive; + public Parameter(string name, string? description = null, object? defaultValue = null, bool isSecure = false) { throw null; } public object? DefaultValue { get { throw null; } } public string? Description { get { throw null; } } public bool IsSecure { get { throw null; } } From beb046b17c667ed99f1509cfd3aaf1c89c77adad Mon Sep 17 00:00:00 2001 From: jolov Date: Sat, 17 Feb 2024 09:41:02 -0800 Subject: [PATCH 20/32] fix comments --- .../src/ModuleInfrastructure.cs | 16 ---------------- .../Azure.Provisioning/src/Resource.cs | 3 ++- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/sdk/provisioning/Azure.Provisioning/src/ModuleInfrastructure.cs b/sdk/provisioning/Azure.Provisioning/src/ModuleInfrastructure.cs index bec8243077748..a7f15bff159e5 100644 --- a/sdk/provisioning/Azure.Provisioning/src/ModuleInfrastructure.cs +++ b/sdk/provisioning/Azure.Provisioning/src/ModuleInfrastructure.cs @@ -148,22 +148,6 @@ private void BuildModuleConstructs(Resource resource, Dictionary p.Name == parameter.Name)) - { - return parameter.Name; - } - // Otherwise we assume it is an output from the current module. - if (parameter.Source is null || ReferenceEquals(parameter.Source, scope)) - { - return parameter.Value!; - } - - return $"{parameter.Source.Name}.outputs.{parameter.Name}"; - } - private bool NeedsModuleConstruct(Resource resource, Dictionary> resourceTree) { if (!(resource is Tenant || resource is Subscription || resource is ResourceGroup)) diff --git a/sdk/provisioning/Azure.Provisioning/src/Resource.cs b/sdk/provisioning/Azure.Provisioning/src/Resource.cs index 70a65917e9d30..08f4cd1d6a9e0 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Resource.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Resource.cs @@ -280,12 +280,13 @@ private static string GetParameterString(Parameter parameter, IConstruct scope) { return parameter.Name; } - // Otherwise we assume it is an output from the current module. + // If the parameter is an output from the current scope, use its Value. if (parameter.Source is null || ReferenceEquals(parameter.Source, scope)) { return parameter.Value!; } + // Otherwise it is an output from a different scope, use the full reference. return $"{parameter.Source.Name}.outputs.{parameter.Name}"; } From 9b82c3810db29934dd2a7bd34096023dd745d6d8 Mon Sep 17 00:00:00 2001 From: jolov Date: Sat, 17 Feb 2024 09:42:14 -0800 Subject: [PATCH 21/32] readonly --- .../Azure.Provisioning/api/Azure.Provisioning.net6.0.cs | 6 +++--- .../api/Azure.Provisioning.netstandard2.0.cs | 6 +++--- sdk/provisioning/Azure.Provisioning/src/Parameter.cs | 2 +- .../StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep | 8 ++++---- .../StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep | 8 ++++---- 5 files changed, 15 insertions(+), 15 deletions(-) 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 2da63f018c313..0d7dc504f9831 100644 --- a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs +++ b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs @@ -67,10 +67,10 @@ internal Output() { } public string Value { get { throw null; } } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public partial struct Parameter + public readonly partial struct Parameter { - private object _dummy; - private int _dummyPrimitive; + private readonly object _dummy; + private readonly int _dummyPrimitive; public Parameter(string name, string? description = null, object? defaultValue = null, bool isSecure = false) { throw null; } public object? DefaultValue { get { throw null; } } public string? Description { get { throw null; } } 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 2da63f018c313..0d7dc504f9831 100644 --- a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs +++ b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs @@ -67,10 +67,10 @@ internal Output() { } public string Value { get { throw null; } } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public partial struct Parameter + public readonly partial struct Parameter { - private object _dummy; - private int _dummyPrimitive; + private readonly object _dummy; + private readonly int _dummyPrimitive; public Parameter(string name, string? description = null, object? defaultValue = null, bool isSecure = false) { throw null; } public object? DefaultValue { get { throw null; } } public string? Description { get { throw null; } } diff --git a/sdk/provisioning/Azure.Provisioning/src/Parameter.cs b/sdk/provisioning/Azure.Provisioning/src/Parameter.cs index ba353a551ab60..99e56f6de521f 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Parameter.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Parameter.cs @@ -7,7 +7,7 @@ namespace Azure.Provisioning /// Represents a parameter of an . /// #pragma warning disable AZC0012 // Avoid single word type names - public struct Parameter + public readonly struct Parameter #pragma warning restore AZC0012 // Avoid single word type names { /// diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep index 117d48df51d1f..e3dccdf93eb6d 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_e0WVEoLUA 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-84ab8d2397fc43' +resource storageAccount_ZdNhg6fih 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-bd564493a58542' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_e0WVEoLUA 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_srpkzSrZI 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_e0WVEoLUA +resource blobService_sgstFalhm 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_ZdNhg6fih name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep index 78ac9d0b1cd1e..5487226d7fa01 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_w0IyPyjWx 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-40c65c3529144b' +resource storageAccount_cvRbpW6Kf 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-f05b13cb20c645' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_w0IyPyjWx 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_n5wAMCYIG 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_w0IyPyjWx +resource blobService_WE1CCaoav 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_cvRbpW6Kf name: 'default' properties: { cors: { From 2d4b7b09fd168b0d0d57a6b1055fad73d5fb735d Mon Sep 17 00:00:00 2001 From: jolov Date: Sat, 17 Feb 2024 15:43:43 -0800 Subject: [PATCH 22/32] add construct tests --- .../tests/ConstructTests.cs | 84 +++++++++++++++++++ .../resources/rg_TEST/rg_TEST.bicep | 8 +- .../resources/rg_TEST/rg_TEST.bicep | 8 +- .../tests/ProvisioningTests.cs | 11 --- 4 files changed, 92 insertions(+), 19 deletions(-) create mode 100644 sdk/provisioning/Azure.Provisioning/tests/ConstructTests.cs diff --git a/sdk/provisioning/Azure.Provisioning/tests/ConstructTests.cs b/sdk/provisioning/Azure.Provisioning/tests/ConstructTests.cs new file mode 100644 index 0000000000000..e31a0057b842f --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/ConstructTests.cs @@ -0,0 +1,84 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Linq; +using Azure.Provisioning.ResourceManager; +using NUnit.Framework; + +namespace Azure.Provisioning.Tests +{ + public class ConstructTests + { + [Test] + [TestCase(true)] + [TestCase(false)] + public void GetConstructsNoChildConstructs(bool recursive) + { + var infra = new TestInfrastructure(); + var constructs = infra.GetConstructs(recursive); + + // the only construct is the infrastructure itself which doesn't get included in GetConstructs + Assert.AreEqual(0, constructs.Count()); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void GetConstructsChildConstructs(bool recursive) + { + var infra = new TestInfrastructure(); + infra.AddFrontEndWebSite(); + var constructs = infra.GetConstructs(recursive); + + Assert.AreEqual(1, constructs.Count()); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void GetConstructsGrandchildConstructs(bool recursive) + { + var infra = new TestInfrastructure(); + + var childScope = new TestInfrastructure(); + childScope.AddConstruct(new TestInfrastructure()); + infra.AddConstruct(childScope); + + var constructs = infra.GetConstructs(recursive); + + var expected = recursive ? 2 : 1; + Assert.AreEqual(expected, constructs.Count()); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void GetResourcesNoChildConstructs(bool recursive) + { + var infra = new TestInfrastructure(); + _ = new ResourceGroup(infra, "rg1"); + _ = new ResourceGroup(infra, "rg2"); + + var resources = infra.GetResources(recursive); + + Assert.AreEqual(4, resources.Count()); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void GetResourcesChildConstructs(bool recursive) + { + var infra = new TestInfrastructure(); + _ = new ResourceGroup(infra, "rg1"); + + var childScope = infra.AddFrontEndWebSite(); + _ = new ResourceGroup(childScope, "rg2"); + + var expected = recursive ? 10 : 6; + var resources = infra.GetResources(recursive); + + Assert.AreEqual(expected, resources.Count()); + } + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep index e3dccdf93eb6d..636f7213221fd 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_ZdNhg6fih 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-bd564493a58542' +resource storageAccount_DTVt1E5E0 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-aefbd255b6c64f' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_ZdNhg6fih 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_sgstFalhm 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_ZdNhg6fih +resource blobService_MUZ5umq8q 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_DTVt1E5E0 name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep index 5487226d7fa01..20e307ffd0cd2 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_cvRbpW6Kf 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-f05b13cb20c645' +resource storageAccount_VxW2VK5mj 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-db11bfaa1d4440' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_cvRbpW6Kf 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_WE1CCaoav 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_cvRbpW6Kf +resource blobService_PVuPa9ZJY 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_VxW2VK5mj name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs index 1c805fbb91036..e7f9b94550ada 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs +++ b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs @@ -68,17 +68,6 @@ public void WebSiteUsingL1() WebSiteConfigLogs logs = new WebSiteConfigLogs(infra, "logs", frontEnd); infra.Build(GetOutputPath()); - // var client = new ArmClient(new DefaultAzureCredential()); - // var sub = client.GetSubscriptions() - // .Where(s => s.Data.SubscriptionId == "faa080af-c1d8-40ad-9cce-e1a450ca5b57").Single(); - // var identifier = ArmDeploymentResource.CreateResourceIdentifier(sub.Id, "test"); - // var resource = client.GetArmDeploymentResource(identifier); - // resource.Validate(WaitUntil.Completed, - // new ArmDeploymentContent( - // new ArmDeploymentProperties(ArmDeploymentMode.Complete) - // { - // Template = new BinaryData((object)File.ReadAllText(Path.Combine(GetOutputPath(), "main.bicep"))), - // })); } [Test] From dc25978b51b36ad4236cd576552abf698a8ab2a3 Mon Sep 17 00:00:00 2001 From: jolov Date: Sat, 17 Feb 2024 15:48:26 -0800 Subject: [PATCH 23/32] Fix enumeration --- .../Azure.Provisioning/src/ModuleInfrastructure.cs | 3 ++- .../StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep | 8 ++++---- .../StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep | 8 ++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/sdk/provisioning/Azure.Provisioning/src/ModuleInfrastructure.cs b/sdk/provisioning/Azure.Provisioning/src/ModuleInfrastructure.cs index a7f15bff159e5..16860c2b566d0 100644 --- a/sdk/provisioning/Azure.Provisioning/src/ModuleInfrastructure.cs +++ b/sdk/provisioning/Azure.Provisioning/src/ModuleInfrastructure.cs @@ -128,7 +128,8 @@ private void BuildModuleConstructs(Resource resource, Dictionary Date: Sat, 17 Feb 2024 16:09:33 -0800 Subject: [PATCH 24/32] Add parameter and outputs tests --- .../Azure.Provisioning/src/Construct.cs | 2 +- .../tests/ConstructTests.cs | 69 +++++++++++++++++++ .../resources/rg_TEST/rg_TEST.bicep | 8 +-- .../resources/rg_TEST/rg_TEST.bicep | 8 +-- 4 files changed, 78 insertions(+), 9 deletions(-) diff --git a/sdk/provisioning/Azure.Provisioning/src/Construct.cs b/sdk/provisioning/Azure.Provisioning/src/Construct.cs index c199ba59b2a6b..1a9a63f7956a6 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Construct.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Construct.cs @@ -139,7 +139,7 @@ public IEnumerable GetParameters(bool recursive = true) IEnumerable result = _parameters; if (recursive) { - result = result.Concat(GetConstructs(false).SelectMany(c => c.GetParameters(true))); + result = result.Concat(GetResources(true).SelectMany(c => c.Parameters)); } return result; } diff --git a/sdk/provisioning/Azure.Provisioning/tests/ConstructTests.cs b/sdk/provisioning/Azure.Provisioning/tests/ConstructTests.cs index e31a0057b842f..47293f20ed839 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/ConstructTests.cs +++ b/sdk/provisioning/Azure.Provisioning/tests/ConstructTests.cs @@ -3,6 +3,7 @@ using System.Linq; using Azure.Provisioning.ResourceManager; +using Azure.Provisioning.Storage; using NUnit.Framework; namespace Azure.Provisioning.Tests @@ -80,5 +81,73 @@ public void GetResourcesChildConstructs(bool recursive) Assert.AreEqual(expected, resources.Count()); } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void GetParametersNoChildConstructs(bool recursive) + { + var infra = new TestInfrastructure(); + var rg1 = new ResourceGroup(infra, "rg1"); + + rg1.AssignParameter(r => r.Location, new Parameter("location")); + + var parameters = infra.GetParameters(recursive); + var expected = recursive ? 1 : 0; + Assert.AreEqual(expected, parameters.Count()); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void GetParametersChildConstructs(bool recursive) + { + var infra = new TestInfrastructure(); + var rg1 = new ResourceGroup(infra, "rg1"); + rg1.AssignParameter(r => r.Location, new Parameter("location")); + + var childScope = infra.AddFrontEndWebSite(); + var rg2 = new ResourceGroup(childScope, "rg2"); + rg2.AssignParameter(r => r.Location, new Parameter("location")); + + var expected = recursive ? 2 : 0; + var parameters = infra.GetParameters(recursive); + + Assert.AreEqual(expected, parameters.Count()); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void GetOutputsNoChildConstructs(bool recursive) + { + var infra = new TestInfrastructure(); + var rg1 = new ResourceGroup(infra, "rg1"); + + rg1.AddOutput(r => r.Location, "location"); + + var outputs = infra.GetOutputs(recursive); + Assert.AreEqual(1, outputs.Count()); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void GetOutputsChildConstructs(bool recursive) + { + var infra = new TestInfrastructure(); + var rg1 = new ResourceGroup(infra, "rg1"); + rg1.AddOutput(r => r.Location, "location"); + + var childScope = infra.AddFrontEndWebSite(); + var rg2 = new ResourceGroup(childScope, "rg2"); + rg2.AddOutput(r => r.Location, "location"); + + // front end website has an output + var expected = recursive ? 3 : 1; + var outputs = infra.GetOutputs(recursive); + + Assert.AreEqual(expected, outputs.Count()); + } } } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep index 75c7aaa05ea7b..9dddb252f40d6 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_KexecArjZ 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-ffa0e09008ef43' +resource storageAccount_ndlcNKBxw 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-7a12b0a522d940' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_KexecArjZ 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_tgFa0LTtj 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_KexecArjZ +resource blobService_LdjAyjFPX 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_ndlcNKBxw name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep index 97190affe7289..b14b8185b3d5c 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_GZYFQDrQ7 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-93297634c2184e' +resource storageAccount_ueMvHVxRn 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-745e82f87b8643' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_GZYFQDrQ7 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_zYYZUU0bM 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_GZYFQDrQ7 +resource blobService_LNZp3bela 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_ueMvHVxRn name: 'default' properties: { cors: { From 975fe8f2802fb455407e2fede7ca48e8a28493cd Mon Sep 17 00:00:00 2001 From: jolov Date: Mon, 19 Feb 2024 15:38:24 -0800 Subject: [PATCH 25/32] save --- .../Azure.Provisioning/src/Construct.cs | 5 +- .../Azure.Provisioning/src/Infrastructure.cs | 2 +- .../Azure.Provisioning/src/Parameter.cs | 6 +- .../src/keyvault/KeyVault.cs | 5 +- .../src/keyvault/KeyVaultExtensions.cs | 6 +- .../OutputsSpanningModules/main.bicep | 25 +++- .../resources/rg1_TEST/rg1_TEST.bicep | 34 ++++++ .../resources/rg3_TEST/rg3_TEST.bicep | 59 +++++++++ .../resources/rg_TEST/rg_TEST.bicep | 8 +- .../resources/rg_TEST/rg_TEST.bicep | 8 +- .../Infrastructure/WebSiteUsingL3/main.bicep | 16 +++ .../resources/rg_TEST/rg_TEST.bicep | 115 ------------------ .../tests/ProvisioningTests.cs | 10 +- .../tests/TestFrontEndWebSite.cs | 9 +- 14 files changed, 163 insertions(+), 145 deletions(-) create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg3_TEST/rg3_TEST.bicep diff --git a/sdk/provisioning/Azure.Provisioning/src/Construct.cs b/sdk/provisioning/Azure.Provisioning/src/Construct.cs index 1a9a63f7956a6..b0811c8baaf25 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Construct.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Construct.cs @@ -48,9 +48,10 @@ public abstract class Construct : IConstruct, IPersistableModel /// 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 in will try to load from AZURE_SUBSCRIPTION_ID environment variable. /// The environment name to use. If not passed in will try to load from AZURE_ENV_NAME environment variable. + /// /// is and is null. - protected Construct(IConstruct? scope, string name, ConstructScope constructScope = ConstructScope.ResourceGroup, Guid? tenantId = null, Guid? subscriptionId = null, string? envName = null) - : this(scope, name, constructScope, tenantId, subscriptionId, envName, null, null, null) + protected Construct(IConstruct? scope, string name, ConstructScope constructScope = ConstructScope.ResourceGroup, Guid? tenantId = null, Guid? subscriptionId = null, string? envName = null, ResourceGroup? resourceGroup = null) + : this(scope, name, constructScope, tenantId, subscriptionId, envName, null, null, resourceGroup) { } diff --git a/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs b/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs index 742cfa84224eb..6b26702e18cde 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs @@ -20,7 +20,7 @@ public abstract class Infrastructure : Construct /// The subscription id to use. If not passed in will try to load from AZURE_SUBSCRIPTION_ID environment variable. /// The environment name to use. If not passed in will try to load from AZURE_ENV_NAME environment variable. public Infrastructure(ConstructScope constructScope = ConstructScope.Subscription, Guid? tenantId = null, Guid? subscriptionId = null, string? envName = null) - : base(null, "default", constructScope, tenantId, subscriptionId, envName ?? Environment.GetEnvironmentVariable("AZURE_ENV_NAME") ?? throw new Exception("No environment variable found named 'AZURE_ENV_NAME'")) + : 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) { } diff --git a/sdk/provisioning/Azure.Provisioning/src/Parameter.cs b/sdk/provisioning/Azure.Provisioning/src/Parameter.cs index 99e56f6de521f..c876ddf9eb773 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Parameter.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Parameter.cs @@ -31,7 +31,11 @@ public readonly struct Parameter internal string? Value { get; } internal IConstruct? Source { get; } - internal Parameter(Output output) + /// + /// + /// + /// + public Parameter(Output output) { Name = output.Name; IsSecure = output.IsSecure; diff --git a/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVault.cs b/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVault.cs index a9886757edfbc..b9636402c17eb 100644 --- a/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVault.cs +++ b/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVault.cs @@ -24,8 +24,9 @@ public class KeyVault : Resource /// The name. /// The version. /// The location. - public KeyVault(IConstruct scope, string name = "kv", string version = "2023-02-01", AzureLocation? location = default) - : base(scope, null, name, ResourceTypeName, version, (name) => ArmKeyVaultModelFactory.KeyVaultData( + /// + public KeyVault(IConstruct scope, string name = "kv", string version = "2023-02-01", AzureLocation? location = default, ResourceGroup? resourceGroup = default) + : base(scope, resourceGroup, name, ResourceTypeName, version, (name) => ArmKeyVaultModelFactory.KeyVaultData( name: name, resourceType: ResourceTypeName, location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS, diff --git a/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVaultExtensions.cs b/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVaultExtensions.cs index 95073c439965a..ddb6582902af5 100644 --- a/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVaultExtensions.cs +++ b/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVaultExtensions.cs @@ -15,12 +15,12 @@ public static class KeyVaultExtensions /// Adds a to the construct. /// /// The construct. - /// The parent. + /// The parent. /// The name. /// - public static KeyVault AddKeyVault(this IConstruct construct, ResourceGroup? parent = null, string name = "kv") + public static KeyVault AddKeyVault(this IConstruct construct, ResourceGroup? resourceGroup = null, string name = "kv") { - return new KeyVault(construct, name); + return new KeyVault(construct, name, resourceGroup: resourceGroup); } /// diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep index 61669b82ddf22..fde21662993d2 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep @@ -1,10 +1,10 @@ targetScope = 'subscription' @description('') -param STORAGE_PRINCIPAL_ID string +param LOCATION string @description('') -param LOCATION string +param STORAGE_PRINCIPAL_ID string resource resourceGroup_AVG5HpqPz 'Microsoft.Resources/resourceGroups@2023-07-01' = { @@ -23,19 +23,36 @@ resource resourceGroup_hu2r8JaSi 'Microsoft.Resources/resourceGroups@2023-07-01' } } +resource resourceGroup_Q4i0lpa1h 'Microsoft.Resources/resourceGroups@2023-07-01' = { + name: 'rg3-TEST' + location: 'westus' + tags: { + azd-env-name: 'TEST' + } +} + module rg1_TEST './resources/rg1_TEST/rg1_TEST.bicep' = { name: 'rg1_TEST' scope: resourceGroup_AVG5HpqPz + params: { + LOCATION: webSite_dOTaZfna6.location + } } module rg2_TEST './resources/rg2_TEST/rg2_TEST.bicep' = { name: 'rg2_TEST' scope: resourceGroup_hu2r8JaSi params: { - STORAGE_PRINCIPAL_ID: STORAGE_PRINCIPAL_ID - LOCATION: LOCATION + STORAGE_PRINCIPAL_ID: webSite_dOTaZfna6.identity.principalId + LOCATION: webSite_dOTaZfna6.location } } +module rg3_TEST './resources/rg3_TEST/rg3_TEST.bicep' = { + name: 'rg3_TEST' + scope: resourceGroup_Q4i0lpa1h +} + output STORAGE_PRINCIPAL_ID string = rg1_TEST.outputs.STORAGE_PRINCIPAL_ID output LOCATION string = rg1_TEST.outputs.LOCATION +output SERVICE_API_IDENTITY_PRINCIPAL_ID string = rg3_TEST.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep index 8fd8fce8da3e5..464b04f599ef9 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep @@ -1,3 +1,6 @@ +@description('') +param LOCATION string + resource appServicePlan_viooTTlOI 'Microsoft.Web/serverfarms@2021-02-01' = { name: 'appServicePlan-TEST' @@ -42,5 +45,36 @@ resource applicationSettingsResource_MAMFSSuFs 'Microsoft.Web/sites/config@2021- name: 'appsettings' } +resource keyVault_BRsYQF4qT 'Microsoft.KeyVault/vaults@2023-02-01' = { + name: 'kv-TEST' + location: LOCATION + properties: { + tenantId: '00000000-0000-0000-0000-000000000000' + sku: { + name: 'standard' + family: 'A' + } + } +} + +resource keyVaultAddAccessPolicy_lQ2z7dHpX 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { + parent: keyVault_BRsYQF4qT + name: 'add' + properties: { + accessPolicies: [ + { + tenantId: '00000000-0000-0000-0000-000000000000' + objectId: webSite_Y34mQ7HgU.identity.principalId + permissions: { + secrets: [ + 'get' + 'list' + ] + } + } + ] + } +} + output STORAGE_PRINCIPAL_ID string = webSite_dOTaZfna6.identity.principalId output LOCATION string = webSite_dOTaZfna6.location diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg3_TEST/rg3_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg3_TEST/rg3_TEST.bicep new file mode 100644 index 0000000000000..3e6eecdefdca1 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg3_TEST/rg3_TEST.bicep @@ -0,0 +1,59 @@ + +resource webSite_Y34mQ7HgU 'Microsoft.Web/sites@2021-02-01' = { + name: 'frontEnd-TEST' + location: 'westus' + identity: { + } + kind: 'app,linux' + properties: { + serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' + siteConfig: { + linuxFxVersion: 'node|18-lts' + alwaysOn: true + appCommandLine: './entrypoint.sh -o ./env-config.js && pm2 serve /home/site/wwwroot --no-daemon --spa' + experiments: { + } + cors: { + allowedOrigins: [ + 'https://portal.azure.com' + 'https://ms.portal.azure.com' + ] + } + minTlsVersion: '1.2' + ftpsState: 'FtpsOnly' + } + httpsOnly: true + } +} + +resource applicationSettingsResource_1XX3wQExf 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_Y34mQ7HgU + name: 'appsettings' +} + +resource webSiteConfigLogs_vhJa9LaNc 'Microsoft.Web/sites/config@2021-02-01' = { + parent: webSite_Y34mQ7HgU + name: 'logs' + properties: { + applicationLogs: { + fileSystem: { + level: 'Verbose' + } + } + httpLogs: { + fileSystem: { + retentionInMb: 35 + retentionInDays: 1 + enabled: true + } + } + failedRequestsTracing: { + enabled: true + } + detailedErrorMessages: { + enabled: true + } + } +} + +output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_Y34mQ7HgU.identity.principalId diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep index 9dddb252f40d6..137f2dc8a6fe4 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_ndlcNKBxw 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-7a12b0a522d940' +resource storageAccount_C1jU1QLp9 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-9cc6fa9880e244' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_ndlcNKBxw 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_LdjAyjFPX 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_ndlcNKBxw +resource blobService_ZPAVRcajy 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_C1jU1QLp9 name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep index b14b8185b3d5c..9ee78cb18ada9 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_ueMvHVxRn 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-745e82f87b8643' +resource storageAccount_aGAXQLBaz 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-61b2effa884d46' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_ueMvHVxRn 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_LNZp3bela 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_ueMvHVxRn +resource blobService_kKgWTY9gk 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_aGAXQLBaz name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep index a1dceb43a30e4..32331f85f2056 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep @@ -18,6 +18,22 @@ resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' } } +resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { + name: 'rg-TEST' + location: 'westus' + tags: { + azd-env-name: 'TEST' + } +} + +module rg_TEST './resources/rg_TEST/rg_TEST.bicep' = { + name: 'rg_TEST' + scope: resourceGroup_I6QNkoPsb + params: { + sqlAdminPassword: sqlAdminPassword + } +} + module rg_TEST './resources/rg_TEST/rg_TEST.bicep' = { name: 'rg_TEST' scope: resourceGroup_I6QNkoPsb diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep index 84c7fd826de43..0d658e2baa6d2 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep @@ -133,119 +133,4 @@ resource webSiteConfigLogs_giqxapQs0 'Microsoft.Web/sites/config@2021-02-01' = { } } -resource sqlServer_zjdvvB2wl 'Microsoft.Sql/servers@2022-08-01-preview' = { - name: 'sqlserver-TEST' - location: 'westus' - properties: { - administratorLogin: 'sqladmin' - administratorLoginPassword: sqlAdminPassword - version: '12.0' - minimalTlsVersion: '1.2' - publicNetworkAccess: 'Enabled' - } -} - -resource sqlDatabase_U7NzorRJT 'Microsoft.Sql/servers/databases@2022-08-01-preview' = { - parent: sqlServer_zjdvvB2wl - name: 'db-TEST' - location: 'westus' - properties: { - } -} - -resource sqlFirewallRule_eS4m8st65 'Microsoft.Sql/servers/firewallRules@2020-11-01-preview' = { - parent: sqlServer_zjdvvB2wl - name: 'firewallRule-TEST' - properties: { - startIpAddress: '0.0.0.1' - endIpAddress: '255.255.255.254' - } -} - -resource deploymentScript_3Zq2Pl8xa 'Microsoft.Resources/deploymentScripts@2020-10-01' = { - name: 'cliScript-TEST' - location: 'westus' - kind: 'AzureCLI' - properties: { - cleanupPreference: 'OnSuccess' - scriptContent: ''' -wget https://github.com/microsoft/go-sqlcmd/releases/download/v0.8.1/sqlcmd-v0.8.1-linux-x64.tar.bz2 -tar x -f sqlcmd-v0.8.1-linux-x64.tar.bz2 -C . -cat < ./initDb.sql -drop user ${APPUSERNAME} -go -create user ${APPUSERNAME} with password = '${APPUSERPASSWORD}' -go -alter role db_owner add member ${APPUSERNAME} -go -SCRIPT_END -./sqlcmd -S ${DBSERVER} -d ${DBNAME} -U ${SQLADMIN} -i ./initDb.sql''' - environmentVariables: [ - { - name: 'APPUSERNAME' - value: 'appUser' - } - { - name: 'APPUSERPASSWORD' - secureValue: '_p_.appUserPassword' - } - { - name: 'DBNAME' - value: '_p_.sqlDatabase_U7NzorRJT.name' - } - { - name: 'DBSERVER' - value: '_p_.sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName' - } - { - name: 'SQLCMDPASSWORD' - secureValue: '_p_.sqlAdminPassword' - } - { - name: 'SQLADMIN' - value: 'sqlAdmin' - } - ] - retentionInterval: 'PT1H' - timeout: 'PT5M' - azCliVersion: '2.37.0' - } -} - -resource webSite_4pzZqR2OO 'Microsoft.Web/sites@2021-02-01' = { - name: 'backEnd-TEST' - location: 'westus' - identity: { - } - kind: 'app,linux' - properties: { - serverFarmId: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-TEST/providers/Microsoft.Web/serverfarms/appServicePlan-TEST' - siteConfig: { - linuxFxVersion: 'dotnetcore|6.0' - alwaysOn: true - appCommandLine: '' - experiments: { - } - cors: { - allowedOrigins: [ - 'https://portal.azure.com' - 'https://ms.portal.azure.com' - ] - } - minTlsVersion: '1.2' - ftpsState: 'FtpsOnly' - } - httpsOnly: true - } -} - -resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021-02-01' = { - parent: webSite_4pzZqR2OO - name: 'appsettings' - properties: { - SCM_DO_BUILD_DURING_DEPLOYMENT: 'False' - ENABLE_ORYX_BUILD: 'True' - } -} - output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_W5EweSXEq.identity.principalId diff --git a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs index e7f9b94550ada..f7e724fbaf9e6 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs +++ b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs @@ -150,16 +150,22 @@ public void OutputsSpanningModules() var infra = new TestInfrastructure(); var rg1 = new ResourceGroup(infra, "rg1"); var rg2 = new ResourceGroup(infra, "rg2"); + var rg3 = new ResourceGroup(infra, "rg3"); var appServicePlan = infra.AddAppServicePlan(parent: rg1); WebSite frontEnd1 = new WebSite(infra, "frontEnd", appServicePlan, WebSiteRuntime.Node, "18-lts", parent: rg1); var output1 = frontEnd1.AddOutput(data => data.Identity.PrincipalId, "STORAGE_PRINCIPAL_ID"); var output2 = frontEnd1.AddOutput(data => data.Location, "LOCATION"); + KeyVault keyVault = infra.AddKeyVault(resourceGroup: rg1); + keyVault.AssignParameter(data => data.Location, new Parameter(output2)); + WebSite frontEnd2 = new WebSite(infra, "frontEnd", appServicePlan, WebSiteRuntime.Node, "18-lts", parent: rg2); - frontEnd2.AssignParameter(data => data.Identity.PrincipalId, new Parameter(output1.Name)); - frontEnd2.AssignParameter(data => data.Location, new Parameter(output2.Name)); + frontEnd2.AssignParameter(data => data.Identity.PrincipalId, new Parameter(output1)); + frontEnd2.AssignParameter(data => data.Location, new Parameter(output2)); + + _ = new TestFrontEndWebSite(infra, parent: rg3); infra.Build(GetOutputPath()); } diff --git a/sdk/provisioning/Azure.Provisioning/tests/TestFrontEndWebSite.cs b/sdk/provisioning/Azure.Provisioning/tests/TestFrontEndWebSite.cs index 30053d1eb4aa7..75cb43dd64a5c 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/TestFrontEndWebSite.cs +++ b/sdk/provisioning/Azure.Provisioning/tests/TestFrontEndWebSite.cs @@ -9,14 +9,9 @@ namespace Azure.Provisioning.Tests { public class TestFrontEndWebSite : Construct { - public TestFrontEndWebSite(IConstruct scope, KeyVault? keyVault = null, AppServicePlan? appServicePlan = null) - : base(scope, nameof(TestFrontEndWebSite)) + public TestFrontEndWebSite(IConstruct scope, KeyVault? keyVault = null, AppServicePlan? appServicePlan = null, ResourceGroup? parent = null) + : base(scope, nameof(TestFrontEndWebSite), resourceGroup: parent ?? new ResourceGroup(scope, "rg")) { - if (ResourceGroup is null) - { - ResourceGroup = new ResourceGroup(scope, "rg"); - } - appServicePlan = UseExistingResource(appServicePlan, () => scope.AddAppServicePlan(ResourceGroup)); keyVault = UseExistingResource(keyVault, () => scope.AddKeyVault(ResourceGroup)); From 92dc0f5f681d29576567dc04564753b73f4cc15c Mon Sep 17 00:00:00 2001 From: m-nash <64171366+m-nash@users.noreply.github.com> Date: Mon, 19 Feb 2024 18:00:05 -0800 Subject: [PATCH 26/32] update get parameters --- sdk/provisioning/Azure.Provisioning/src/Construct.cs | 2 +- sdk/provisioning/Azure.Provisioning/src/Resource.cs | 5 ++++- sdk/provisioning/Azure.Provisioning/tests/ConstructTests.cs | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/sdk/provisioning/Azure.Provisioning/src/Construct.cs b/sdk/provisioning/Azure.Provisioning/src/Construct.cs index 1a9a63f7956a6..c199ba59b2a6b 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Construct.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Construct.cs @@ -139,7 +139,7 @@ public IEnumerable GetParameters(bool recursive = true) IEnumerable result = _parameters; if (recursive) { - result = result.Concat(GetResources(true).SelectMany(c => c.Parameters)); + result = result.Concat(GetConstructs(false).SelectMany(c => c.GetParameters(true))); } return result; } diff --git a/sdk/provisioning/Azure.Provisioning/src/Resource.cs b/sdk/provisioning/Azure.Provisioning/src/Resource.cs index 08f4cd1d6a9e0..8ba3d02b7b5e9 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Resource.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Resource.cs @@ -59,7 +59,7 @@ internal void AddDependency(Resource resource) /// /// Gets the parameters of the resource. /// - public IList Parameters { get; } + internal IList Parameters { get; } internal IConstruct? ModuleScope { get; set; } @@ -155,6 +155,9 @@ private protected void AssignParameter(object instance, string propertyName, Par { ParameterOverrides.Add(instance, new Dictionary { { propertyName, parameter } }); } + Scope.AddParameter(parameter); + //TODO: We should not need this instead a parameter should have a reference to the resource it is associated with but belong to the construct only. + //https://github.com/Azure/azure-sdk-for-net/issues/42066 Parameters.Add(parameter); } diff --git a/sdk/provisioning/Azure.Provisioning/tests/ConstructTests.cs b/sdk/provisioning/Azure.Provisioning/tests/ConstructTests.cs index 47293f20ed839..0f8362e0f6b00 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/ConstructTests.cs +++ b/sdk/provisioning/Azure.Provisioning/tests/ConstructTests.cs @@ -93,7 +93,7 @@ public void GetParametersNoChildConstructs(bool recursive) rg1.AssignParameter(r => r.Location, new Parameter("location")); var parameters = infra.GetParameters(recursive); - var expected = recursive ? 1 : 0; + var expected = recursive ? 1 : 1; Assert.AreEqual(expected, parameters.Count()); } @@ -110,7 +110,7 @@ public void GetParametersChildConstructs(bool recursive) var rg2 = new ResourceGroup(childScope, "rg2"); rg2.AssignParameter(r => r.Location, new Parameter("location")); - var expected = recursive ? 2 : 0; + var expected = recursive ? 2 : 1; var parameters = infra.GetParameters(recursive); Assert.AreEqual(expected, parameters.Count()); From 7d6dc2e1241536eaf4fe13ca40690c70b999c0af Mon Sep 17 00:00:00 2001 From: m-nash <64171366+m-nash@users.noreply.github.com> Date: Mon, 19 Feb 2024 18:07:08 -0800 Subject: [PATCH 27/32] update api --- .../Azure.Provisioning/api/Azure.Provisioning.net6.0.cs | 1 - .../Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs | 1 - 2 files changed, 2 deletions(-) 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 0d7dc504f9831..eae7c1fb51698 100644 --- a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs +++ b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs @@ -82,7 +82,6 @@ public abstract partial class Resource : System.ClientModel.Primitives.IPersista protected Resource(Azure.Provisioning.IConstruct scope, Azure.Provisioning.Resource? parent, string resourceName, Azure.Core.ResourceType resourceType, string version, System.Func createProperties) { } public Azure.Core.ResourceIdentifier Id { get { throw null; } } public string Name { get { throw null; } } - public System.Collections.Generic.IList Parameters { get { throw null; } } public Azure.Provisioning.Resource? Parent { get { throw null; } } public Azure.Provisioning.IConstruct Scope { get { throw null; } } public string Version { get { throw null; } } 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 0d7dc504f9831..eae7c1fb51698 100644 --- a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs +++ b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs @@ -82,7 +82,6 @@ public abstract partial class Resource : System.ClientModel.Primitives.IPersista protected Resource(Azure.Provisioning.IConstruct scope, Azure.Provisioning.Resource? parent, string resourceName, Azure.Core.ResourceType resourceType, string version, System.Func createProperties) { } public Azure.Core.ResourceIdentifier Id { get { throw null; } } public string Name { get { throw null; } } - public System.Collections.Generic.IList Parameters { get { throw null; } } public Azure.Provisioning.Resource? Parent { get { throw null; } } public Azure.Provisioning.IConstruct Scope { get { throw null; } } public string Version { get { throw null; } } From ec6c624b610fe65ea8d6e3b2d0e84800161ff01d Mon Sep 17 00:00:00 2001 From: m-nash <64171366+m-nash@users.noreply.github.com> Date: Mon, 19 Feb 2024 19:22:51 -0800 Subject: [PATCH 28/32] update after merge --- .../Azure.Provisioning/src/Resource.cs | 2 +- .../AppConfiguration/main.bicep | 2 +- .../resources/rg_TEST/rg_TEST.bicep | 2 ++ .../subscription_O0vZNnri3.bicep | 2 +- .../subscription_i7MQMw1U7.bicep | 2 +- .../OutputsSpanningModules/main.bicep | 4 +-- .../StorageBlobDefaults/main.bicep | 22 +++------------- .../resources/rg_TEST/rg_TEST.bicep | 8 +++--- .../StorageBlobDropDown/main.bicep | 25 +++---------------- .../resources/rg_TEST/rg_TEST.bicep | 8 +++--- .../Infrastructure/WebSiteUsingL1/main.bicep | 4 +-- .../resources/rg_TEST/rg_TEST.bicep | 4 +-- .../resources/rg_TEST/rg_TEST.bicep | 4 +-- .../resources/rg_TEST/rg_TEST.bicep | 6 ++--- 14 files changed, 31 insertions(+), 64 deletions(-) diff --git a/sdk/provisioning/Azure.Provisioning/src/Resource.cs b/sdk/provisioning/Azure.Provisioning/src/Resource.cs index c281af8837453..26061e769f19f 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Resource.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Resource.cs @@ -174,7 +174,7 @@ private protected void AssignParameter(object instance, string propertyName, Par /// If the is not found on the resources properties. private protected Output AddOutput(string name, object instance, string propertyName, string expression, bool isLiteral = false, bool isSecure = false) { - var result = new Output(name, $"{Name}.{expression}", Scope, isLiteral, isSecure); + var result = new Output(name, $"{Name}.{expression}", Scope, this, isLiteral, isSecure); Scope.AddOutput(result); return result; } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/main.bicep index d9072eb5485f4..163f0ff9d1c26 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/main.bicep @@ -14,4 +14,4 @@ module rg_TEST './resources/rg_TEST/rg_TEST.bicep' = { scope: resourceGroup_I6QNkoPsb } -output appConfigurationStore_sgecYnln3_endpoint string = appConfigurationStore_sgecYnln3.properties.endpoint +output appConfigurationStore_sgecYnln3_endpoint string = rg_TEST.outputs.appConfigurationStore_sgecYnln3_endpoint diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/resources/rg_TEST/rg_TEST.bicep index 31221f07fe431..12efbf2dc8b00 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/AppConfiguration/resources/rg_TEST/rg_TEST.bicep @@ -8,3 +8,5 @@ resource appConfigurationStore_sgecYnln3 'Microsoft.AppConfiguration/configurati properties: { } } + +output appConfigurationStore_sgecYnln3_endpoint string = appConfigurationStore_sgecYnln3.properties.endpoint diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_O0vZNnri3/subscription_O0vZNnri3.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_O0vZNnri3/subscription_O0vZNnri3.bicep index b5a56e206b2e6..ebb9a61118abd 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_O0vZNnri3/subscription_O0vZNnri3.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_O0vZNnri3/subscription_O0vZNnri3.bicep @@ -5,6 +5,6 @@ resource resourceGroup_grHjXx8QF 'Microsoft.Resources/resourceGroups@2023-07-01' name: 'rg-TEST' location: 'westus' tags: { - azd-env-name: 'TEST' + 'azd-env-name': 'TEST' } } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_i7MQMw1U7/subscription_i7MQMw1U7.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_i7MQMw1U7/subscription_i7MQMw1U7.bicep index deaf9f44d800b..34344c2dc39a9 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_i7MQMw1U7/subscription_i7MQMw1U7.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/MultipleSubscriptions/resources/subscription_i7MQMw1U7/subscription_i7MQMw1U7.bicep @@ -5,6 +5,6 @@ resource resourceGroup_U95xWHMzX 'Microsoft.Resources/resourceGroups@2023-07-01' name: 'rg-TEST' location: 'westus' tags: { - azd-env-name: 'TEST' + 'azd-env-name': 'TEST' } } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep index 61669b82ddf22..3567c829d5385 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep @@ -11,7 +11,7 @@ resource resourceGroup_AVG5HpqPz 'Microsoft.Resources/resourceGroups@2023-07-01' name: 'rg1-TEST' location: 'westus' tags: { - azd-env-name: 'TEST' + 'azd-env-name': 'TEST' } } @@ -19,7 +19,7 @@ resource resourceGroup_hu2r8JaSi 'Microsoft.Resources/resourceGroups@2023-07-01' name: 'rg2-TEST' location: 'westus' tags: { - azd-env-name: 'TEST' + 'azd-env-name': 'TEST' } } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/main.bicep index efd8c4f974fdf..da7e83d582e03 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/main.bicep @@ -1,4 +1,4 @@ -targetScope = subscription +targetScope = 'subscription' resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { @@ -9,23 +9,7 @@ resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' } } -resource storageAccount_8fTaUIzOg 'Microsoft.Storage/storageAccounts@2022-09-01' = { +module rg_TEST './resources/rg_TEST/rg_TEST.bicep' = { + name: 'rg_TEST' scope: resourceGroup_I6QNkoPsb - name: 'photoacct2af3506bedd4415' - location: 'westus' - sku: { - name: 'Premium_LRS' - } - kind: 'StorageV2' - properties: { - } -} - -resource blobService_1iUqwyvnt 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_8fTaUIzOg - name: 'default' - properties: { - cors: { - } - } } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep index 9dddb252f40d6..d342cca74337c 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_ndlcNKBxw 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-7a12b0a522d940' +resource storageAccount_EeYr88hbi 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoacct23213e49bdeb4ac' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_ndlcNKBxw 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_LdjAyjFPX 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_ndlcNKBxw +resource blobService_Xk3xn7f19 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_EeYr88hbi name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/main.bicep index 7994d65dcd582..da7e83d582e03 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/main.bicep @@ -1,4 +1,4 @@ -targetScope = subscription +targetScope = 'subscription' resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { @@ -9,26 +9,7 @@ resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' } } -resource storageAccount_VpeHv8O32 'Microsoft.Storage/storageAccounts@2022-09-01' = { +module rg_TEST './resources/rg_TEST/rg_TEST.bicep' = { + name: 'rg_TEST' scope: resourceGroup_I6QNkoPsb - name: 'photoacct414ad12f6b9c4a2' - location: 'westus' - sku: { - name: 'Premium_LRS' - } - kind: 'StorageV2' - properties: { - } -} - -resource blobService_6SRi2s6Pf 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_VpeHv8O32 - name: 'default' - properties: { - cors: { - } - deleteRetentionPolicy: { - enabled: true - } - } } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep index b14b8185b3d5c..1f556e622b373 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_ueMvHVxRn 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-745e82f87b8643' +resource storageAccount_qyiy38jjE 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoacct4e2c754458594ab' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_ueMvHVxRn 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_LNZp3bela 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_ueMvHVxRn +resource blobService_ChZGQnE2Y 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_qyiy38jjE name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep index a1dceb43a30e4..8ab036a1810a9 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep @@ -13,8 +13,8 @@ resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' name: 'rg-TEST' location: 'westus' tags: { - azd-env-name: 'TEST' - key: 'value' + 'azd-env-name': 'TEST' + 'key': 'value' } } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep index 536cb6a6e93f7..5ba5df6c13cc0 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep @@ -240,8 +240,8 @@ resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021- parent: webSite_4pzZqR2OO name: 'appsettings' properties: { - SCM_DO_BUILD_DURING_DEPLOYMENT: 'False' - ENABLE_ORYX_BUILD: 'True' + 'SCM_DO_BUILD_DURING_DEPLOYMENT': 'False' + 'ENABLE_ORYX_BUILD': 'True' } } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep index 436cd38c95c01..c18ad56f04516 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep @@ -240,8 +240,8 @@ resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021- parent: webSite_4pzZqR2OO name: 'appsettings' properties: { - SCM_DO_BUILD_DURING_DEPLOYMENT: 'False' - ENABLE_ORYX_BUILD: 'True' + 'SCM_DO_BUILD_DURING_DEPLOYMENT': 'False' + 'ENABLE_ORYX_BUILD': 'True' } } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep index 84c7fd826de43..bc5dd78cefb27 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep @@ -22,7 +22,7 @@ resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' = { name: 'kv-TEST' location: 'westus' tags: { - key: 'value' + 'key': 'value' } properties: { tenantId: '00000000-0000-0000-0000-000000000000' @@ -243,8 +243,8 @@ resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021- parent: webSite_4pzZqR2OO name: 'appsettings' properties: { - SCM_DO_BUILD_DURING_DEPLOYMENT: 'False' - ENABLE_ORYX_BUILD: 'True' + 'SCM_DO_BUILD_DURING_DEPLOYMENT': 'False' + 'ENABLE_ORYX_BUILD': 'True' } } From 84a449437a896d265cfa9b1af0c735e764aa905b Mon Sep 17 00:00:00 2001 From: jolov Date: Mon, 19 Feb 2024 19:47:58 -0800 Subject: [PATCH 29/32] Fix outputs/parameters --- .../Azure.Provisioning/src/Construct.cs | 41 +++++++++++++------ .../src/ModuleInfrastructure.cs | 11 +---- .../Azure.Provisioning/src/Output.cs | 1 + .../Azure.Provisioning/src/Parameter.cs | 22 ++++++++++ .../Azure.Provisioning/src/Resource.cs | 19 +-------- .../OutputsSpanningModules/main.bicep | 13 +----- .../resources/rg1_TEST/rg1_TEST.bicep | 5 +-- .../resources/rg2_TEST/rg2_TEST.bicep | 6 +++ .../resources/rg_TEST/rg_TEST.bicep | 8 ++-- .../resources/rg_TEST/rg_TEST.bicep | 8 ++-- .../Infrastructure/WebSiteUsingL1/main.bicep | 4 ++ .../resources/rg_TEST/rg_TEST.bicep | 18 +++++++- .../Infrastructure/WebSiteUsingL2/main.bicep | 4 ++ .../resources/rg_TEST/rg_TEST.bicep | 18 +++++++- .../Infrastructure/WebSiteUsingL3/main.bicep | 4 ++ .../resources/rg_TEST/rg_TEST.bicep | 10 ++++- 16 files changed, 126 insertions(+), 66 deletions(-) diff --git a/sdk/provisioning/Azure.Provisioning/src/Construct.cs b/sdk/provisioning/Azure.Provisioning/src/Construct.cs index b0811c8baaf25..ed521197e52bd 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Construct.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Construct.cs @@ -7,6 +7,7 @@ using System.IO; using System.Linq; using Azure.Provisioning.ResourceManager; +using Microsoft.Extensions.Azure; namespace Azure.Provisioning { @@ -193,18 +194,21 @@ private BinaryData SerializeModuleReference(ModelReaderWriterOptions options) stream.WriteLine($" scope: {GetScopeName()}"); var parametersToWrite = new HashSet(); - GetAllParametersRecursive(this, parametersToWrite, false); - if (parametersToWrite.Count() > 0) + var outputs = new HashSet(GetOutputs()); + foreach (var p in GetParameters(false)) + { + if (!ShouldExposeParameter(p, outputs)) + { + continue; + } + parametersToWrite.Add(p); + } + if (parametersToWrite.Count > 0) { stream.WriteLine($" params: {{"); foreach (var parameter in parametersToWrite) { - var value = parameter.IsFromOutput - ? parameter.IsLiteral - ? $"'{parameter.Value}'" - : parameter.Value - : parameter.Name; - stream.WriteLine($" {parameter.Name}: {value}"); + stream.WriteLine($" {parameter.Name}: {parameter.GetParameterString(Scope!)}"); } stream.WriteLine($" }}"); } @@ -275,13 +279,13 @@ internal void WriteOutputs(MemoryStream stream) foreach (var output in outputsToWrite) { string value; - if (output.IsLiteral || output.Source.Equals(this)) + if (output.IsLiteral || ReferenceEquals(this, output.ModuleSource)) { value = output.IsLiteral ? $"'{output.Value}'" : output.Value; } else { - value = $"{output.Source.Name}.outputs.{output.Name}"; + value = $"{output.ModuleSource!.Name}.outputs.{output.Name}"; } string name = output.Name; stream.WriteLine($"output {name} string = {value}"); @@ -304,10 +308,15 @@ private void GetAllOutputsRecursive(IConstruct construct, HashSet visite private void WriteParameters(MemoryStream stream) { - var parametersToWrite = new HashSet(); - GetAllParametersRecursive(this, parametersToWrite, false); - foreach (var parameter in parametersToWrite) + // var parametersToWrite = new HashSet(); + // GetAllParametersRecursive(this, parametersToWrite, false); + var outputs = new HashSet(GetOutputs()); + foreach (var parameter in GetParameters(true)) { + if (!ShouldExposeParameter(parameter, outputs)) + { + continue; + } string defaultValue = parameter.DefaultValue is null ? string.Empty : $" = '{parameter.DefaultValue}'"; if (parameter.IsSecure) @@ -318,6 +327,12 @@ private void WriteParameters(MemoryStream stream) } } + private bool ShouldExposeParameter(Parameter parameter, HashSet outputs) + { + // Don't expose the parameter if the output that was used to create the parameter is already in scope. + return parameter.Output == null || !outputs.Contains(parameter.Output); + } + private void GetAllParametersRecursive(IConstruct construct, HashSet visited, bool isChild) { if (!isChild) diff --git a/sdk/provisioning/Azure.Provisioning/src/ModuleInfrastructure.cs b/sdk/provisioning/Azure.Provisioning/src/ModuleInfrastructure.cs index 16860c2b566d0..4f50bbe45ad26 100644 --- a/sdk/provisioning/Azure.Provisioning/src/ModuleInfrastructure.cs +++ b/sdk/provisioning/Azure.Provisioning/src/ModuleInfrastructure.cs @@ -47,15 +47,8 @@ private void AddOutputsToModules() // ToList to avoid modifying the collection while iterating foreach (var output in construct.GetOutputs(false).ToList()) { - var moduleOutput = new Output( - output.Name, - output.Value, - output.Resource.ModuleScope!, - output.Resource, - output.IsLiteral, - output.IsSecure); - - output.Resource.ModuleScope!.AddOutput(moduleOutput); + output.ModuleSource = output.Resource.ModuleScope!; + output.Resource.ModuleScope!.AddOutput(output); } } } diff --git a/sdk/provisioning/Azure.Provisioning/src/Output.cs b/sdk/provisioning/Azure.Provisioning/src/Output.cs index 2da64556a6b1a..181090508992b 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Output.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Output.cs @@ -27,6 +27,7 @@ public class Output /// public bool IsSecure { get; } internal IConstruct Source { get; } + internal IConstruct? ModuleSource { get; set; } internal Resource Resource { get; } diff --git a/sdk/provisioning/Azure.Provisioning/src/Parameter.cs b/sdk/provisioning/Azure.Provisioning/src/Parameter.cs index c876ddf9eb773..10d197c054973 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Parameter.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Parameter.cs @@ -1,6 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System.Collections.Generic; +using System.Linq; + namespace Azure.Provisioning { /// @@ -30,6 +33,7 @@ public readonly struct Parameter internal bool IsLiteral { get; } internal string? Value { get; } internal IConstruct? Source { get; } + internal Output? Output { get; } /// /// @@ -43,6 +47,7 @@ public Parameter(Output output) IsLiteral = output.IsLiteral; Value = output.Value; Source = output.Source; + Output = output; } internal Parameter(string name, string? description, object? defaultValue, bool isSecure, IConstruct source, string? value) @@ -69,5 +74,22 @@ public Parameter(string name, string? description = default, object? defaultValu DefaultValue = defaultValue; IsSecure = isSecure; } + + internal string GetParameterString(IConstruct parentScope) + { + // If the parameter is not from an output, use the parameter name. + if (Output == null) + { + return Name; + } + // If the parameter is an output from the current scope, use its Value. + if (ReferenceEquals(Output!.ModuleSource, parentScope)) + { + return Value!; + } + + // Otherwise it is an output from a different scope, use the full reference. + return $"{Output!.ModuleSource!.Name}.outputs.{Name}"; + } } } diff --git a/sdk/provisioning/Azure.Provisioning/src/Resource.cs b/sdk/provisioning/Azure.Provisioning/src/Resource.cs index 08f4cd1d6a9e0..6f1ce75d33f6f 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Resource.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Resource.cs @@ -241,7 +241,7 @@ private BinaryData SerializeModule(ModelReaderWriterOptions options) var dict = new Dictionary(); foreach (var kvp in parameter.Value) { - dict.Add(kvp.Key, GetParameterString(kvp.Value, ModuleScope!)); + dict.Add(kvp.Key, kvp.Value.GetParameterString(ModuleScope!)); } bicepOptions.ParameterOverrides.Add(parameter.Key, dict); } @@ -273,23 +273,6 @@ private bool NeedsScope() } } - private static string GetParameterString(Parameter parameter, IConstruct scope) - { - // If the parameter is a parameter of the module scope, use the parameter name. - if (scope.GetParameters(false).Any(p => p.Name == parameter.Name)) - { - return parameter.Name; - } - // If the parameter is an output from the current scope, use its Value. - if (parameter.Source is null || ReferenceEquals(parameter.Source, scope)) - { - return parameter.Value!; - } - - // Otherwise it is an output from a different scope, use the full reference. - return $"{parameter.Source.Name}.outputs.{parameter.Name}"; - } - private static void WriteLines(int depth, BinaryData data, MemoryStream stream, Resource resource) { string indent = new string(' ', depth * 2); diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep index fde21662993d2..d576884a41a81 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep @@ -1,11 +1,5 @@ targetScope = 'subscription' -@description('') -param LOCATION string - -@description('') -param STORAGE_PRINCIPAL_ID string - resource resourceGroup_AVG5HpqPz 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg1-TEST' @@ -34,17 +28,14 @@ resource resourceGroup_Q4i0lpa1h 'Microsoft.Resources/resourceGroups@2023-07-01' module rg1_TEST './resources/rg1_TEST/rg1_TEST.bicep' = { name: 'rg1_TEST' scope: resourceGroup_AVG5HpqPz - params: { - LOCATION: webSite_dOTaZfna6.location - } } module rg2_TEST './resources/rg2_TEST/rg2_TEST.bicep' = { name: 'rg2_TEST' scope: resourceGroup_hu2r8JaSi params: { - STORAGE_PRINCIPAL_ID: webSite_dOTaZfna6.identity.principalId - LOCATION: webSite_dOTaZfna6.location + STORAGE_PRINCIPAL_ID: rg1_TEST.outputs.STORAGE_PRINCIPAL_ID + LOCATION: rg1_TEST.outputs.LOCATION } } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep index 464b04f599ef9..a067a8e757d48 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep @@ -1,6 +1,3 @@ -@description('') -param LOCATION string - resource appServicePlan_viooTTlOI 'Microsoft.Web/serverfarms@2021-02-01' = { name: 'appServicePlan-TEST' @@ -64,7 +61,7 @@ resource keyVaultAddAccessPolicy_lQ2z7dHpX 'Microsoft.KeyVault/vaults/accessPoli accessPolicies: [ { tenantId: '00000000-0000-0000-0000-000000000000' - objectId: webSite_Y34mQ7HgU.identity.principalId + objectId: SERVICE_API_IDENTITY_PRINCIPAL_ID permissions: { secrets: [ 'get' diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg2_TEST/rg2_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg2_TEST/rg2_TEST.bicep index b506f40b2de1a..78523067b5232 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg2_TEST/rg2_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg2_TEST/rg2_TEST.bicep @@ -4,6 +4,12 @@ param STORAGE_PRINCIPAL_ID string @description('') param LOCATION string +@description('') +param STORAGE_PRINCIPAL_ID string + +@description('') +param LOCATION string + resource webSite_80I4ejz5T 'Microsoft.Web/sites@2021-02-01' = { name: 'frontEnd-TEST' diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep index 137f2dc8a6fe4..641aeb8fe0c14 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_C1jU1QLp9 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-9cc6fa9880e244' +resource storageAccount_erCuJ7Pw9 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-1815add998a44a' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_C1jU1QLp9 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_ZPAVRcajy 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_C1jU1QLp9 +resource blobService_U1fNgMXv7 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_erCuJ7Pw9 name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep index 9ee78cb18ada9..5b3de65c2f7e8 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_aGAXQLBaz 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-61b2effa884d46' +resource storageAccount_dRf5fGWqc 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoAcct-2c6cc8edf26e46' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_aGAXQLBaz 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_kKgWTY9gk 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_aGAXQLBaz +resource blobService_HqqKb1LF5 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_dRf5fGWqc name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep index a1dceb43a30e4..83fc7712d55b7 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep @@ -8,6 +8,10 @@ param sqlAdminPassword string @description('Application user password') param appUserPassword string +@secure() +@description('SQL Server administrator password') +param sqlAdminPassword string + resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep index 536cb6a6e93f7..46cb7c37a28fe 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep @@ -6,6 +6,22 @@ param sqlAdminPassword string @description('Application user password') param appUserPassword string +@secure() +@description('SQL Server administrator password') +param sqlAdminPassword string + +@secure() +@description('SQL Server administrator password') +param sqlAdminPassword string + +@secure() +@description('Application user password') +param appUserPassword string + +@secure() +@description('SQL Server administrator password') +param sqlAdminPassword string + resource appServicePlan_kjMZSF1FP 'Microsoft.Web/serverfarms@2021-02-01' = { name: 'appServicePlan-TEST' @@ -94,7 +110,7 @@ resource keyVaultAddAccessPolicy_NWCGclP20 'Microsoft.KeyVault/vaults/accessPoli accessPolicies: [ { tenantId: '00000000-0000-0000-0000-000000000000' - objectId: webSite_W5EweSXEq.identity.principalId + objectId: SERVICE_API_IDENTITY_PRINCIPAL_ID permissions: { secrets: [ 'get' diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep index a1dceb43a30e4..83fc7712d55b7 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep @@ -8,6 +8,10 @@ param sqlAdminPassword string @description('Application user password') param appUserPassword string +@secure() +@description('SQL Server administrator password') +param sqlAdminPassword string + resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep index 436cd38c95c01..8197e1d732b31 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep @@ -6,6 +6,22 @@ param sqlAdminPassword string @description('Application user password') param appUserPassword string +@secure() +@description('SQL Server administrator password') +param sqlAdminPassword string + +@secure() +@description('SQL Server administrator password') +param sqlAdminPassword string + +@secure() +@description('Application user password') +param appUserPassword string + +@secure() +@description('SQL Server administrator password') +param sqlAdminPassword string + resource appServicePlan_kjMZSF1FP 'Microsoft.Web/serverfarms@2021-02-01' = { name: 'appServicePlan-TEST' @@ -37,7 +53,7 @@ resource keyVaultAddAccessPolicy_NWCGclP20 'Microsoft.KeyVault/vaults/accessPoli accessPolicies: [ { tenantId: '00000000-0000-0000-0000-000000000000' - objectId: webSite_W5EweSXEq.identity.principalId + objectId: SERVICE_API_IDENTITY_PRINCIPAL_ID permissions: { secrets: [ 'get' diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep index 32331f85f2056..f5c79c11127b3 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep @@ -4,6 +4,10 @@ targetScope = 'subscription' @description('SQL Server administrator password') param sqlAdminPassword string +@secure() +@description('SQL Server administrator password') +param sqlAdminPassword string + @secure() @description('Application user password') param appUserPassword string diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep index 0d658e2baa6d2..6b8aee8058d82 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep @@ -6,6 +6,14 @@ param sqlAdminPassword string @description('Application user password') param appUserPassword string +@secure() +@description('SQL Server administrator password') +param sqlAdminPassword string + +@secure() +@description('Application user password') +param appUserPassword string + resource appServicePlan_kjMZSF1FP 'Microsoft.Web/serverfarms@2021-02-01' = { name: 'appServicePlan-TEST' @@ -40,7 +48,7 @@ resource keyVaultAddAccessPolicy_NWCGclP20 'Microsoft.KeyVault/vaults/accessPoli accessPolicies: [ { tenantId: '00000000-0000-0000-0000-000000000000' - objectId: webSite_W5EweSXEq.identity.principalId + objectId: SERVICE_API_IDENTITY_PRINCIPAL_ID permissions: { secrets: [ 'get' From e6e32b7ca2a4382ca1d71d9e945534463e617ee0 Mon Sep 17 00:00:00 2001 From: jolov Date: Mon, 19 Feb 2024 19:53:06 -0800 Subject: [PATCH 30/32] avoid dupes --- .../Azure.Provisioning/src/Construct.cs | 6 +++--- .../OutputsSpanningModules/main.bicep | 2 +- .../resources/rg2_TEST/rg2_TEST.bicep | 6 ------ .../resources/rg_TEST/rg_TEST.bicep | 8 ++++---- .../resources/rg_TEST/rg_TEST.bicep | 8 ++++---- .../Infrastructure/WebSiteUsingL1/main.bicep | 4 ---- .../resources/rg_TEST/rg_TEST.bicep | 16 ---------------- .../Infrastructure/WebSiteUsingL2/main.bicep | 4 ---- .../resources/rg_TEST/rg_TEST.bicep | 16 ---------------- .../Infrastructure/WebSiteUsingL3/main.bicep | 6 +----- .../resources/rg_TEST/rg_TEST.bicep | 10 +--------- 11 files changed, 14 insertions(+), 72 deletions(-) diff --git a/sdk/provisioning/Azure.Provisioning/src/Construct.cs b/sdk/provisioning/Azure.Provisioning/src/Construct.cs index bc3257ec18ec1..7a5f2be994cae 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Construct.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Construct.cs @@ -308,10 +308,10 @@ private void GetAllOutputsRecursive(IConstruct construct, HashSet visite private void WriteParameters(MemoryStream stream) { - // var parametersToWrite = new HashSet(); - // GetAllParametersRecursive(this, parametersToWrite, false); + var parametersToWrite = new HashSet(); + GetAllParametersRecursive(this, parametersToWrite, false); var outputs = new HashSet(GetOutputs()); - foreach (var parameter in GetParameters(true)) + foreach (var parameter in parametersToWrite) { if (!ShouldExposeParameter(parameter, outputs)) { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep index 1d605efe159a9..df4929f7b2eee 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/main.bicep @@ -21,7 +21,7 @@ resource resourceGroup_Q4i0lpa1h 'Microsoft.Resources/resourceGroups@2023-07-01' name: 'rg3-TEST' location: 'westus' tags: { - azd-env-name: 'TEST' + 'azd-env-name': 'TEST' } } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg2_TEST/rg2_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg2_TEST/rg2_TEST.bicep index 78523067b5232..b506f40b2de1a 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg2_TEST/rg2_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg2_TEST/rg2_TEST.bicep @@ -4,12 +4,6 @@ param STORAGE_PRINCIPAL_ID string @description('') param LOCATION string -@description('') -param STORAGE_PRINCIPAL_ID string - -@description('') -param LOCATION string - resource webSite_80I4ejz5T 'Microsoft.Web/sites@2021-02-01' = { name: 'frontEnd-TEST' diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep index 641aeb8fe0c14..4fd8ed1fb0729 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_erCuJ7Pw9 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-1815add998a44a' +resource storageAccount_o16OWzTQE 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoacct985209930ac24f6' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_erCuJ7Pw9 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_U1fNgMXv7 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_erCuJ7Pw9 +resource blobService_b1lTObtBZ 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_o16OWzTQE name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep index 5b3de65c2f7e8..84adbe11a46b6 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep @@ -1,6 +1,6 @@ -resource storageAccount_dRf5fGWqc 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoAcct-2c6cc8edf26e46' +resource storageAccount_xlURFCc5A 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoaccte6de904bc2d5415' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_dRf5fGWqc 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_HqqKb1LF5 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_dRf5fGWqc +resource blobService_AhHMDPJzw 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_xlURFCc5A name: 'default' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep index 5af00acbe5e01..8ab036a1810a9 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep @@ -8,10 +8,6 @@ param sqlAdminPassword string @description('Application user password') param appUserPassword string -@secure() -@description('SQL Server administrator password') -param sqlAdminPassword string - resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep index 471fed11df5ac..fd18134828a04 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep @@ -6,22 +6,6 @@ param sqlAdminPassword string @description('Application user password') param appUserPassword string -@secure() -@description('SQL Server administrator password') -param sqlAdminPassword string - -@secure() -@description('SQL Server administrator password') -param sqlAdminPassword string - -@secure() -@description('Application user password') -param appUserPassword string - -@secure() -@description('SQL Server administrator password') -param sqlAdminPassword string - resource appServicePlan_kjMZSF1FP 'Microsoft.Web/serverfarms@2021-02-01' = { name: 'appServicePlan-TEST' diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep index 5af00acbe5e01..8ab036a1810a9 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep @@ -8,10 +8,6 @@ param sqlAdminPassword string @description('Application user password') param appUserPassword string -@secure() -@description('SQL Server administrator password') -param sqlAdminPassword string - resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { name: 'rg-TEST' diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep index d5d79753211d3..ba408adc23da3 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST/rg_TEST.bicep @@ -6,22 +6,6 @@ param sqlAdminPassword string @description('Application user password') param appUserPassword string -@secure() -@description('SQL Server administrator password') -param sqlAdminPassword string - -@secure() -@description('SQL Server administrator password') -param sqlAdminPassword string - -@secure() -@description('Application user password') -param appUserPassword string - -@secure() -@description('SQL Server administrator password') -param sqlAdminPassword string - resource appServicePlan_kjMZSF1FP 'Microsoft.Web/serverfarms@2021-02-01' = { name: 'appServicePlan-TEST' diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep index 757c36712d32e..c7f95043cdce2 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep @@ -4,10 +4,6 @@ targetScope = 'subscription' @description('SQL Server administrator password') param sqlAdminPassword string -@secure() -@description('SQL Server administrator password') -param sqlAdminPassword string - @secure() @description('Application user password') param appUserPassword string @@ -26,7 +22,7 @@ resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' name: 'rg-TEST' location: 'westus' tags: { - azd-env-name: 'TEST' + 'azd-env-name': 'TEST' } } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep index 6b8aee8058d82..6b4d6c508815d 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST/rg_TEST.bicep @@ -6,14 +6,6 @@ param sqlAdminPassword string @description('Application user password') param appUserPassword string -@secure() -@description('SQL Server administrator password') -param sqlAdminPassword string - -@secure() -@description('Application user password') -param appUserPassword string - resource appServicePlan_kjMZSF1FP 'Microsoft.Web/serverfarms@2021-02-01' = { name: 'appServicePlan-TEST' @@ -30,7 +22,7 @@ resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' = { name: 'kv-TEST' location: 'westus' tags: { - key: 'value' + 'key': 'value' } properties: { tenantId: '00000000-0000-0000-0000-000000000000' From c7ffffe278f9aadd4dfd036771df9689e77e7321 Mon Sep 17 00:00:00 2001 From: jolov Date: Mon, 19 Feb 2024 20:08:57 -0800 Subject: [PATCH 31/32] fix test --- sdk/provisioning/Azure.Provisioning/tests/ConstructTests.cs | 4 ++-- sdk/provisioning/Azure.Provisioning/tests/TestExtensions.cs | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/sdk/provisioning/Azure.Provisioning/tests/ConstructTests.cs b/sdk/provisioning/Azure.Provisioning/tests/ConstructTests.cs index 0f8362e0f6b00..9552f32c7d008 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/ConstructTests.cs +++ b/sdk/provisioning/Azure.Provisioning/tests/ConstructTests.cs @@ -71,9 +71,9 @@ public void GetResourcesNoChildConstructs(bool recursive) public void GetResourcesChildConstructs(bool recursive) { var infra = new TestInfrastructure(); - _ = new ResourceGroup(infra, "rg1"); + var rg1 = new ResourceGroup(infra, "rg1"); - var childScope = infra.AddFrontEndWebSite(); + var childScope = infra.AddFrontEndWebSite(resourceGroup: rg1); _ = new ResourceGroup(childScope, "rg2"); var expected = recursive ? 10 : 6; diff --git a/sdk/provisioning/Azure.Provisioning/tests/TestExtensions.cs b/sdk/provisioning/Azure.Provisioning/tests/TestExtensions.cs index d277b2111c1c3..2d322e530c850 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/TestExtensions.cs +++ b/sdk/provisioning/Azure.Provisioning/tests/TestExtensions.cs @@ -3,14 +3,15 @@ using Azure.Provisioning.AppService; using Azure.Provisioning.KeyVaults; +using Azure.Provisioning.ResourceManager; namespace Azure.Provisioning.Tests { public static class TestExtensions { - public static TestFrontEndWebSite AddFrontEndWebSite(this IConstruct construct, KeyVault? keyVault = null, AppServicePlan? appServicePlan = null) + public static TestFrontEndWebSite AddFrontEndWebSite(this IConstruct construct, KeyVault? keyVault = null, AppServicePlan? appServicePlan = null, ResourceGroup? resourceGroup = null) { - return new TestFrontEndWebSite(construct, keyVault, appServicePlan); + return new TestFrontEndWebSite(construct, keyVault, appServicePlan, resourceGroup); } public static TestCommonSqlDatabase AddCommonSqlDatabase(this IConstruct construct, KeyVault? keyVault = null) From 1cd0b5a37291871622aab789206054153a9bc695 Mon Sep 17 00:00:00 2001 From: jolov Date: Mon, 19 Feb 2024 20:29:31 -0800 Subject: [PATCH 32/32] api --- .../Azure.Provisioning/api/Azure.Provisioning.net6.0.cs | 9 +++++---- .../api/Azure.Provisioning.netstandard2.0.cs | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) 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 eae7c1fb51698..d8cd9d9097b9b 100644 --- a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs +++ b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs @@ -7,7 +7,7 @@ public static partial class CdkExtensions } public abstract partial class Construct : Azure.Provisioning.IConstruct, System.ClientModel.Primitives.IPersistableModel { - 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) { } + 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.ConstructScope ConstructScope { get { throw null; } } public string EnvironmentName { get { throw null; } } public string Name { get { throw null; } } @@ -55,7 +55,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) : base (default(Azure.Provisioning.IConstruct), default(string), default(Azure.Provisioning.ConstructScope), default(System.Guid?), default(System.Guid?), default(string)) { } + 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) : 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 @@ -71,6 +71,7 @@ public readonly partial struct Parameter { private readonly object _dummy; private readonly int _dummyPrimitive; + public Parameter(Azure.Provisioning.Output output) { throw null; } public Parameter(string name, string? description = null, object? defaultValue = null, bool isSecure = false) { throw null; } public object? DefaultValue { get { throw null; } } public string? Description { get { throw null; } } @@ -149,13 +150,13 @@ namespace Azure.Provisioning.KeyVaults { public partial class KeyVault : Azure.Provisioning.Resource { - public KeyVault(Azure.Provisioning.IConstruct scope, string name = "kv", string version = "2023-02-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } + public KeyVault(Azure.Provisioning.IConstruct scope, string name = "kv", string version = "2023-02-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?), Azure.Provisioning.ResourceManager.ResourceGroup? resourceGroup = null) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } public void AddAccessPolicy(Azure.Provisioning.Output output) { } protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; } } public static partial class KeyVaultExtensions { - public static Azure.Provisioning.KeyVaults.KeyVault AddKeyVault(this Azure.Provisioning.IConstruct construct, Azure.Provisioning.ResourceManager.ResourceGroup? parent = null, string name = "kv") { throw null; } + public static Azure.Provisioning.KeyVaults.KeyVault AddKeyVault(this Azure.Provisioning.IConstruct construct, Azure.Provisioning.ResourceManager.ResourceGroup? resourceGroup = null, string name = "kv") { throw null; } public static System.Collections.Generic.IEnumerable GetSecrets(this Azure.Provisioning.IConstruct construct) { throw null; } } public partial class KeyVaultSecret : Azure.Provisioning.Resource 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 eae7c1fb51698..d8cd9d9097b9b 100644 --- a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs +++ b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs @@ -7,7 +7,7 @@ public static partial class CdkExtensions } public abstract partial class Construct : Azure.Provisioning.IConstruct, System.ClientModel.Primitives.IPersistableModel { - 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) { } + 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.ConstructScope ConstructScope { get { throw null; } } public string EnvironmentName { get { throw null; } } public string Name { get { throw null; } } @@ -55,7 +55,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) : base (default(Azure.Provisioning.IConstruct), default(string), default(Azure.Provisioning.ConstructScope), default(System.Guid?), default(System.Guid?), default(string)) { } + 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) : 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 @@ -71,6 +71,7 @@ public readonly partial struct Parameter { private readonly object _dummy; private readonly int _dummyPrimitive; + public Parameter(Azure.Provisioning.Output output) { throw null; } public Parameter(string name, string? description = null, object? defaultValue = null, bool isSecure = false) { throw null; } public object? DefaultValue { get { throw null; } } public string? Description { get { throw null; } } @@ -149,13 +150,13 @@ namespace Azure.Provisioning.KeyVaults { public partial class KeyVault : Azure.Provisioning.Resource { - public KeyVault(Azure.Provisioning.IConstruct scope, string name = "kv", string version = "2023-02-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } + public KeyVault(Azure.Provisioning.IConstruct scope, string name = "kv", string version = "2023-02-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?), Azure.Provisioning.ResourceManager.ResourceGroup? resourceGroup = null) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } public void AddAccessPolicy(Azure.Provisioning.Output output) { } protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; } } public static partial class KeyVaultExtensions { - public static Azure.Provisioning.KeyVaults.KeyVault AddKeyVault(this Azure.Provisioning.IConstruct construct, Azure.Provisioning.ResourceManager.ResourceGroup? parent = null, string name = "kv") { throw null; } + public static Azure.Provisioning.KeyVaults.KeyVault AddKeyVault(this Azure.Provisioning.IConstruct construct, Azure.Provisioning.ResourceManager.ResourceGroup? resourceGroup = null, string name = "kv") { throw null; } public static System.Collections.Generic.IEnumerable GetSecrets(this Azure.Provisioning.IConstruct construct) { throw null; } } public partial class KeyVaultSecret : Azure.Provisioning.Resource