Skip to content

Commit 910632f

Browse files
Fix parameter issues (#42070)
1 parent a17e403 commit 910632f

File tree

13 files changed

+48
-26
lines changed

13 files changed

+48
-26
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,13 @@ internal void WriteOutputs(MemoryStream stream)
279279
foreach (var output in outputsToWrite)
280280
{
281281
string value;
282-
if (output.IsLiteral || ReferenceEquals(this, output.ModuleSource))
282+
if (output.IsLiteral || ReferenceEquals(this, output.Resource.ModuleScope))
283283
{
284284
value = output.IsLiteral ? $"'{output.Value}'" : output.Value;
285285
}
286286
else
287287
{
288-
value = $"{output.ModuleSource!.Name}.outputs.{output.Name}";
288+
value = $"{output.Resource.ModuleScope!.Name}.outputs.{output.Name}";
289289
}
290290
string name = output.Name;
291291
stream.WriteLine($"output {name} string = {value}");

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ private void AddOutputsToModules()
4747
// ToList to avoid modifying the collection while iterating
4848
foreach (var output in construct.GetOutputs(false).ToList())
4949
{
50-
output.ModuleSource = output.Resource.ModuleScope!;
5150
output.Resource.ModuleScope!.AddOutput(output);
5251
}
5352
}
@@ -102,7 +101,6 @@ private void BuildModuleConstructs(Resource resource, Dictionary<Resource, List<
102101
{
103102
root = construct;
104103
construct.IsRoot = true;
105-
parentScope = construct;
106104
}
107105
}
108106

@@ -112,6 +110,8 @@ private void BuildModuleConstructs(Resource resource, Dictionary<Resource, List<
112110
resource.ModuleScope = parentScope;
113111
}
114112

113+
parentScope ??= construct;
114+
115115
if (parentScope != null)
116116
{
117117
foreach (var parameter in resource.Parameters)
@@ -131,7 +131,8 @@ private void BuildModuleConstructs(Resource resource, Dictionary<Resource, List<
131131
parameterToCopy.DefaultValue,
132132
parameterToCopy.IsSecure,
133133
parentScope,
134-
parameterToCopy.Value);
134+
parameterToCopy.Value,
135+
parameterToCopy.Output);
135136
}
136137
}
137138
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public class Output
2727
/// </summary>
2828
public bool IsSecure { get; }
2929
internal IConstruct Source { get; }
30-
internal IConstruct? ModuleSource { get; set; }
3130

3231
internal Resource Resource { get; }
3332

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ public readonly struct Parameter
2929
/// Gets a value indicating whether the parameter is secure.
3030
/// </summary>
3131
public bool IsSecure { get; }
32-
internal bool IsFromOutput { get; }
33-
internal bool IsLiteral { get; }
32+
33+
internal bool IsFromOutput => Output != null;
34+
internal bool IsLiteral => Output?.IsLiteral ?? false;
3435
internal string? Value { get; }
3536
internal IConstruct? Source { get; }
3637
internal Output? Output { get; }
@@ -43,21 +44,20 @@ public Parameter(Output output)
4344
{
4445
Name = output.Name;
4546
IsSecure = output.IsSecure;
46-
IsFromOutput = true;
47-
IsLiteral = output.IsLiteral;
4847
Value = output.Value;
4948
Source = output.Source;
5049
Output = output;
5150
}
5251

53-
internal Parameter(string name, string? description, object? defaultValue, bool isSecure, IConstruct source, string? value)
52+
internal Parameter(string name, string? description, object? defaultValue, bool isSecure, IConstruct source, string? value, Output? output)
5453
{
5554
Name = name;
5655
Description = description;
5756
DefaultValue = defaultValue;
5857
IsSecure = isSecure;
5958
Source = source;
6059
Value = value;
60+
Output = output;
6161
}
6262

6363
/// <summary>
@@ -82,14 +82,21 @@ internal string GetParameterString(IConstruct parentScope)
8282
{
8383
return Name;
8484
}
85+
86+
// If the parameter is from an output that is not in the current scope, use the parameter name.
87+
if (!parentScope.GetOutputs().Contains(Output))
88+
{
89+
return Name;
90+
}
91+
8592
// If the parameter is an output from the current scope, use its Value.
86-
if (ReferenceEquals(Output!.ModuleSource, parentScope))
93+
if (ReferenceEquals(Output!.Resource.ModuleScope, parentScope))
8794
{
8895
return Value!;
8996
}
9097

9198
// Otherwise it is an output from a different scope, use the full reference.
92-
return $"{Output!.ModuleSource!.Name}.outputs.{Name}";
99+
return $"{Output!.Resource.ModuleScope!.Name}.outputs.{Name}";
93100
}
94101
}
95102
}

sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVaultAddAccessPolicy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public KeyVaultAddAccessPolicy(IConstruct scope, Parameter principalIdParameter,
3333
}))
3434
{
3535
ParameterOverrides.Add(Properties.AccessPolicies[0], new Dictionary<string, Parameter> { { nameof(KeyVaultAccessPolicy.ObjectId), principalIdParameter } });
36+
Parameters.Add(principalIdParameter);
3637
}
3738

3839
private static string GetParamValue(Parameter principalIdParameter, IConstruct scope)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ resource resourceGroup_Q4i0lpa1h 'Microsoft.Resources/resourceGroups@2023-07-01'
2828
module rg1_TEST './resources/rg1_TEST/rg1_TEST.bicep' = {
2929
name: 'rg1_TEST'
3030
scope: resourceGroup_AVG5HpqPz
31+
params: {
32+
SERVICE_API_IDENTITY_PRINCIPAL_ID: rg3_TEST.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID
33+
}
3134
}
3235

3336
module rg2_TEST './resources/rg2_TEST/rg2_TEST.bicep' = {

sdk/provisioning/Azure.Provisioning/tests/Infrastructure/OutputsSpanningModules/resources/rg1_TEST/rg1_TEST.bicep

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
@secure()
2+
@description('')
3+
param SERVICE_API_IDENTITY_PRINCIPAL_ID string
4+
15

26
resource appServicePlan_viooTTlOI 'Microsoft.Web/serverfarms@2021-02-01' = {
37
name: 'appServicePlan-TEST'
@@ -44,7 +48,7 @@ resource applicationSettingsResource_MAMFSSuFs 'Microsoft.Web/sites/config@2021-
4448

4549
resource keyVault_BRsYQF4qT 'Microsoft.KeyVault/vaults@2023-02-01' = {
4650
name: 'kv-TEST'
47-
location: LOCATION
51+
location: webSite_dOTaZfna6.location
4852
properties: {
4953
tenantId: '00000000-0000-0000-0000-000000000000'
5054
sku: {

sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST/rg_TEST.bicep

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
resource storageAccount_o16OWzTQE 'Microsoft.Storage/storageAccounts@2022-09-01' = {
3-
name: 'photoacct985209930ac24f6'
2+
resource storageAccount_7Spem00ph 'Microsoft.Storage/storageAccounts@2022-09-01' = {
3+
name: 'photoacct4aa56e7da51149b'
44
location: 'westus'
55
sku: {
66
name: 'Premium_LRS'
@@ -10,8 +10,8 @@ resource storageAccount_o16OWzTQE 'Microsoft.Storage/storageAccounts@2022-09-01'
1010
}
1111
}
1212

13-
resource blobService_b1lTObtBZ 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = {
14-
parent: storageAccount_o16OWzTQE
13+
resource blobService_Al1mntjNG 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = {
14+
parent: storageAccount_7Spem00ph
1515
name: 'default'
1616
properties: {
1717
cors: {

sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST/rg_TEST.bicep

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
resource storageAccount_xlURFCc5A 'Microsoft.Storage/storageAccounts@2022-09-01' = {
3-
name: 'photoaccte6de904bc2d5415'
2+
resource storageAccount_xksvj6bLA 'Microsoft.Storage/storageAccounts@2022-09-01' = {
3+
name: 'photoacct420f4454773442c'
44
location: 'westus'
55
sku: {
66
name: 'Premium_LRS'
@@ -10,8 +10,8 @@ resource storageAccount_xlURFCc5A 'Microsoft.Storage/storageAccounts@2022-09-01'
1010
}
1111
}
1212

13-
resource blobService_AhHMDPJzw 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = {
14-
parent: storageAccount_xlURFCc5A
13+
resource blobService_OX8Ox5p80 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = {
14+
parent: storageAccount_xksvj6bLA
1515
name: 'default'
1616
properties: {
1717
cors: {

sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST/rg_TEST.bicep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ resource keyVaultAddAccessPolicy_NWCGclP20 'Microsoft.KeyVault/vaults/accessPoli
9494
accessPolicies: [
9595
{
9696
tenantId: '00000000-0000-0000-0000-000000000000'
97-
objectId: SERVICE_API_IDENTITY_PRINCIPAL_ID
97+
objectId: webSite_W5EweSXEq.identity.principalId
9898
permissions: {
9999
secrets: [
100100
'get'

0 commit comments

Comments
 (0)