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 1 commit
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
2 changes: 1 addition & 1 deletion sdk/provisioning/Azure.Provisioning/src/Construct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public IEnumerable<Parameter> GetParameters(bool recursive = true)
IEnumerable<Parameter> result = _parameters;
if (recursive)
{
result = result.Concat(GetConstructs(false).SelectMany(c => c.GetParameters(true)));
result = result.Concat(GetResources(true).SelectMany(c => c.Parameters));
JoshLove-msft marked this conversation as resolved.
Show resolved Hide resolved
}
return result;
}
Expand Down
69 changes: 69 additions & 0 deletions sdk/provisioning/Azure.Provisioning/tests/ConstructTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Linq;
using Azure.Provisioning.ResourceManager;
using Azure.Provisioning.Storage;
using NUnit.Framework;

namespace Azure.Provisioning.Tests
Expand Down Expand Up @@ -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());
}
}
}
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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: {
Expand Down