Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write bicep into modules based on scope hierarchy rather than user constructs #42029

Merged
merged 35 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
635c7ec
Write bicep into modules based on scope hierarchy rather than user co…
JoshLove-msft Feb 16, 2024
54ad6d3
Clean up
JoshLove-msft Feb 16, 2024
b6a49f0
Merge branch 'feature/cdk' of https://github.com/Azure/azure-sdk-for-…
JoshLove-msft Feb 16, 2024
410f372
remove dead code
JoshLove-msft Feb 16, 2024
5c41e5a
Add override logic for ManagedService
JoshLove-msft Feb 16, 2024
c9add63
PR fb
JoshLove-msft Feb 16, 2024
fdd2d5e
deleted files
JoshLove-msft Feb 16, 2024
ee33dee
API
JoshLove-msft Feb 16, 2024
f5a7d2b
Fix getResources
JoshLove-msft Feb 16, 2024
16e0e5d
tests
JoshLove-msft Feb 16, 2024
78251ad
Fix outputs
JoshLove-msft Feb 16, 2024
778d52c
remove commented code
JoshLove-msft Feb 16, 2024
bd35f78
remove blank refdocs
JoshLove-msft Feb 16, 2024
725e73a
using
JoshLove-msft Feb 16, 2024
b934c99
Pass recursive as true
JoshLove-msft Feb 16, 2024
0bee48f
revert recursive change
JoshLove-msft Feb 16, 2024
8ec68ad
PR fb
JoshLove-msft Feb 17, 2024
613d506
pass true as recursive arg
JoshLove-msft Feb 17, 2024
925b313
Fix recursive call and don't mutate Parameter
JoshLove-msft Feb 17, 2024
ceceb89
API
JoshLove-msft Feb 17, 2024
beb046b
fix comments
JoshLove-msft Feb 17, 2024
9b82c38
readonly
JoshLove-msft Feb 17, 2024
2d4b7b0
add construct tests
JoshLove-msft Feb 17, 2024
dc25978
Fix enumeration
JoshLove-msft Feb 17, 2024
1521c9b
Add parameter and outputs tests
JoshLove-msft Feb 18, 2024
975fe8f
save
JoshLove-msft Feb 19, 2024
92dc0f5
update get parameters
m-nash Feb 20, 2024
7d6dc2e
update api
m-nash Feb 20, 2024
80cc65c
merge upstream feature/cdk
m-nash Feb 20, 2024
ec6c624
update after merge
m-nash Feb 20, 2024
84a4494
Fix outputs/parameters
JoshLove-msft Feb 20, 2024
499bf89
Merge branch 'module-reorganization' of https://github.com/JoshLove-m…
JoshLove-msft Feb 20, 2024
e6e32b7
avoid dupes
JoshLove-msft Feb 20, 2024
c7ffffe
fix test
JoshLove-msft Feb 20, 2024
1cd0b5a
api
JoshLove-msft Feb 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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; } }
Expand Down Expand Up @@ -116,7 +113,7 @@ namespace Azure.Provisioning.AppService
{
public partial class AppServicePlan : Azure.Provisioning.Resource<Azure.ResourceManager.AppService.AppServicePlanData>
{
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<string, Azure.ResourceManager.AppService.AppServicePlanData>)) { }
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<string, Azure.ResourceManager.AppService.AppServicePlanData>)) { }
protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; }
}
public static partial class AppServicesExtensions
Expand All @@ -125,7 +122,7 @@ public static partial class AppServicesExtensions
}
public partial class WebSite : Azure.Provisioning.Resource<Azure.ResourceManager.AppService.WebSiteData>
{
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<string, Azure.ResourceManager.AppService.WebSiteData>)) { }
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<string, Azure.ResourceManager.AppService.WebSiteData>)) { }
public void AddApplicationSetting(string key, Azure.Provisioning.Parameter value) { }
public void AddApplicationSetting(string key, string value) { }
public void AddLogConfig(string resourceName) { }
Expand Down Expand Up @@ -170,7 +167,7 @@ namespace Azure.Provisioning.ResourceManager
{
public partial class ResourceGroup : Azure.Provisioning.Resource<Azure.ResourceManager.Resources.ResourceGroupData>
{
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<string, Azure.ResourceManager.Resources.ResourceGroupData>)) { }
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<string, Azure.ResourceManager.Resources.ResourceGroupData>)) { }
protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; }
}
public static partial class ResourceManagerExtensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; } }
Expand Down Expand Up @@ -116,7 +113,7 @@ namespace Azure.Provisioning.AppService
{
public partial class AppServicePlan : Azure.Provisioning.Resource<Azure.ResourceManager.AppService.AppServicePlanData>
{
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<string, Azure.ResourceManager.AppService.AppServicePlanData>)) { }
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<string, Azure.ResourceManager.AppService.AppServicePlanData>)) { }
protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; }
}
public static partial class AppServicesExtensions
Expand All @@ -125,7 +122,7 @@ public static partial class AppServicesExtensions
}
public partial class WebSite : Azure.Provisioning.Resource<Azure.ResourceManager.AppService.WebSiteData>
{
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<string, Azure.ResourceManager.AppService.WebSiteData>)) { }
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<string, Azure.ResourceManager.AppService.WebSiteData>)) { }
public void AddApplicationSetting(string key, Azure.Provisioning.Parameter value) { }
public void AddApplicationSetting(string key, string value) { }
public void AddLogConfig(string resourceName) { }
Expand Down Expand Up @@ -170,7 +167,7 @@ namespace Azure.Provisioning.ResourceManager
{
public partial class ResourceGroup : Azure.Provisioning.Resource<Azure.ResourceManager.Resources.ResourceGroupData>
{
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<string, Azure.ResourceManager.Resources.ResourceGroupData>)) { }
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<string, Azure.ResourceManager.Resources.ResourceGroupData>)) { }
protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; }
}
public static partial class ResourceManagerExtensions
Expand Down
15 changes: 11 additions & 4 deletions sdk/provisioning/Azure.Provisioning/src/Construct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public abstract class Construct : IConstruct, IPersistableModel<Construct>
/// <param name="envName">The environment name to use. If not passed in will try to load from AZURE_ENV_NAME environment variable.</param>
/// <exception cref="ArgumentException"><paramref name="constructScope"/> is <see cref="ConstructScope.ResourceGroup"/> and <paramref name="scope"/> is null.</exception>
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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -103,7 +110,7 @@ public IEnumerable<Resource> GetResources(bool recursive = true)
IEnumerable<Resource> result = _resources;
if (recursive)
{
result = result.Concat(GetConstructs(false).SelectMany(c => c.GetResources(false)));
result = result.Concat(GetConstructs(true).SelectMany(c => c.GetResources(false)));
JoshLove-msft marked this conversation as resolved.
Show resolved Hide resolved
}
return result;
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}");
}
}

Expand Down
Loading