8000 Make AddDependency public and use project ref for ease of testing (#4… · Azure/azure-sdk-for-net@3f4a495 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f4a495

Browse files
Make AddDependency public and use project ref for ease of testing (#43257)
* Make AddDependency public and use project ref for ease of testing * Handle empty construct
1 parent 0e30d39 commit 3f4a495

File tree

18 files changed

+293
-7
lines changed

18 files changed

+293
-7
lines changed

sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net461.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ protected Resource(Azure.Provisioning.IConstruct scope, Azure.Provisioning.Resou
100100
protected object ResourceData { get { throw null; } }
101101
public Azure.Provisioning.IConstruct Scope { get { throw null; } }
102102
public string Version { get { throw null; } }
103+
public void AddDependency(Azure.Provisioning.Resource resource) { }
103104
public Azure.Provisioning.RoleAssignment AssignRole(Azure.Provisioning.RoleDefinition roleDefinition, System.Guid? principalId = default(System.Guid?), Azure.ResourceManager.Authorization.Models.RoleManagementPrincipalType? principalType = default(Azure.ResourceManager.Authorization.Models.RoleManagementPrincipalType?)) { throw null; }
104105
protected virtual Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; }
105106
protected virtual string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; }

sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net472.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ protected Resource(Azure.Provisioning.IConstruct scope, Azure.Provisioning.Resou
100100
protected object ResourceData { get { throw null; } }
101101
public Azure.Provisioning.IConstruct Scope { get { throw null; } }
102102
public string Version { get { throw null; } }
103+
public void AddDependency(Azure.Provisioning.Resource resource) { }
103104
public Azure.Provisioning.RoleAssignment AssignRole(Azure.Provisioning.RoleDefinition roleDefinition, System.Guid? principalId = default(System.Guid?), Azure.ResourceManager.Authorization.Models.RoleManagementPrincipalType? principalType = default(Azure.ResourceManager.Authorization.Models.RoleManagementPrincipalType?)) { throw null; }
104105
protected virtual Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; }
105106
protected virtual string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; }

sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ protected Resource(Azure.Provisioning.IConstruct scope, Azure.Provisioning.Resou
100100
protected object ResourceData { get { throw null; } }
101101
public Azure.Provisioning.IConstruct Scope { get { throw null; } }
102102
public string Version { get { throw null; } }
103+
public void AddDependency(Azure.Provisioning.Resource resource) { }
103104
public Azure.Provisioning.RoleAssignment AssignRole(Azure.Provisioning.RoleDefinition roleDefinition, System.Guid? principalId = default(System.Guid?), Azure.ResourceManager.Authorization.Models.RoleManagementPrincipalType? principalType = default(Azure.ResourceManager.Authorization.Models.RoleManagementPrincipalType?)) { throw null; }
104105
protected virtual Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; }
105106
protected virtual string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; }

sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ protected Resource(Azure.Provisioning.IConstruct scope, Azure.Provisioning.Resou
100100
protected object ResourceData { get { throw null; } }
101101
public Azure.Provisioning.IConstruct Scope { get { throw null; } }
102102
public string Version { get { throw null; } }
103+
public void AddDependency(Azure.Provisioning.Resource resource) { }
103104
public Azure.Provisioning.RoleAssignment AssignRole(Azure.Provisioning.RoleDefinition roleDefinition, System.Guid? principalId = default(System.Guid?), Azure.ResourceManager.Authorization.Models.RoleManagementPrincipalType? principalType = default(Azure.ResourceManager.Authorization.Models.RoleManagementPrincipalType?)) { throw null; }
104105
protected virtual Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; }
105106
protected virtual string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; }

sdk/provisioning/Azure.Provisioning/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "net",
44
"TagPrefix": "net/provisioning/Azure.Provisioning",
5-
"Tag": "net/provisioning/Azure.Provisioning_6da137c164"
5+
"Tag": "net/provisioning/Azure.Provisioning_3336ebb5fd"
66
}

sdk/provisioning/Azure.Provisioning/src/ModuleInfrastructure.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ public void Write(string? outputPath = null)
3030
outputPath ??= $".\\{GetType().Name}";
3131
outputPath = Path.GetFullPath(outputPath);
3232

33-
WriteBicepFile(_rootConstruct!, outputPath);
33+
WriteBicepFile(_rootConstruct, outputPath);
34+
if (_rootConstruct == null)
35+
{
36+
return;
37+
}
3438

3539
var queue = new Queue<ModuleConstruct>();
3640
queue.Enqueue(_rootConstruct!);
@@ -190,16 +194,21 @@ private void WriteConstructsByLevel(Queue<ModuleConstruct> constructs, string ou
190194
}
191195
}
192196

193-
private string GetFilePath(ModuleConstruct construct, string outputPath)
197+
private string GetFilePath(ModuleConstruct? construct, string outputPath)
194198
{
195-
string fileName = construct.IsRoot ? Path.Combine(outputPath, "main.bicep") : Path.Combine(outputPath, "resources", construct.Name, $"{construct.Name}.bicep");
199+
string fileName = construct == null || construct.IsRoot ? Path.Combine(outputPath, "main.bicep") : Path.Combine(outputPath, "resources", construct.Name, $"{construct.Name}.bicep");
196200
Directory.CreateDirectory(Path.GetDirectoryName(fileName)!);
197201
return fileName;
198202
}
199203

200-
private void WriteBicepFile(ModuleConstruct construct, string outputPath)
204+
private void WriteBicepFile(ModuleConstruct? construct, string outputPath)
201205
{
202206
using var stream = new FileStream(GetFilePath(construct, outputPath), FileMode.Create);
207+
// just create an empty file if there is no construct
208+
if (construct == null)
209+
{
210+
return;
211+
}
203212
#if NET6_0_OR_GREATER
204213
stream.Write(construct.SerializeModule());
205214
#else

sdk/provisioning/Azure.Provisioning/src/Resource.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ public abstract class Resource : IPersistableModel<Resource>
2626

2727
private IList<Resource> Dependencies { get; }
2828

29-
internal void AddDependency(Resource resource)
29+
/// <summary>
30+
/// Adds a dependency to the resource.
31+
/// </summary>
32+
/// <param name="resource">The dependency for this resource.</param>
33+
public void AddDependency(Resource resource)
3034
{
3135
Dependencies.Add(resource);
3236
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
targetScope = 'resourceGroup'
2+
3+
@description('')
4+
param location string = resourceGroup().location
5+
6+
7+
resource storageAccount_7EH24TZOS 'Microsoft.Storage/storageAccounts@2022-09-01' = {
8+
name: toLower(take('photoAcct${uniqueString(resourceGroup().id)}', 24))
9+
location: location
10+
sku: {
11+
name: 'Premium_LRS'
12+
}
13+
kind: 'BlockBlobStorage'
14+
properties: {
15+
networkAcls: {
16+
defaultAction: 'Deny'
17+
}
18+
}
19+
}
20+
21+
resource storageAccount_GoC2YPRJs 'Microsoft.Storage/storageAccounts@2022-09-01' = {
22+
dependsOn: [
23+
storageAccount_7EH24TZOS
24+
]
25+
name: toLower(take('photoAcct2${uniqueString(resourceGroup().id)}', 24))
26+
location: location
27+
sku: {
28+
name: 'Premium_LRS'
29+
}
30+
kind: 'BlockBlobStorage'
31+
properties: {
32+
networkAcls: {
33+
defaultAction: 'Deny'
34+
}
35+
}
36+
}

sdk/provisioning/Azure.Provisioning/tests/Infrastructure/EmptyConstructDoesNotThrow/main.bicep

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
targetScope = 'subscription'
2+
3+
4+
resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = {
5+
name: 'rg-TEST'
6+
location: 'westus'
7+
tags: {
8+
'azd-env-name': 'TEST'
9+
}
10+
}
11+
12+
module rg_TEST_module './resources/rg_TEST_module/rg_TEST_module.bicep' = {
13+
name: 'rg_TEST_module'
14+
scope: resourceGroup_I6QNkoPsb
15+
}

0 commit comments

Comments
 (0)
0