Skip to content

Commit 7a065af

Browse files
authored
Extension config default values constraint fixes. (#18606)
## Description Updates the validation of extension config default values to align with the current backend implementation. Mainly, it blocks non-deploy-time constants (`resource.properties.xyz`). To use reference calls, the user must use module extension configs. ## Example Usage ```bicep resource r1 '...' = { // ... } extension 'br:...' with { configOne: r1.properties.abc // blocked configTwo: r1.id // OK } as contoso ``` ## Checklist - [x] I have read and adhere to the [contribution guide](https://github.com/Azure/bicep/blob/main/CONTRIBUTING.md). ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/18606)
1 parent debf068 commit 7a065af

20 files changed

Lines changed: 759 additions & 26 deletions

src/Bicep.Core.Samples/Files/baselines/Extensions_CRLF/main.bicep

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ param boolParam1 bool
1212
// BEGIN: Variables
1313

1414
var strVar1 = 'strVar1Value'
15+
var strParamVar1 = strParam1
1516

1617
// END: Variables
1718

@@ -21,6 +22,18 @@ extension az
2122
extension kubernetes as k8s
2223
extension 'br:mcr.microsoft.com/bicep/extensions/hasoptionalconfig/v1:1.2.3' as extWithOptionalConfig1
2324
extension 'br:mcr.microsoft.com/bicep/extensions/hasoptionalconfig/v1:1.2.3' as extWithOptionalConfig2
25+
extension 'br:mcr.microsoft.com/bicep/extensions/hasoptionalconfig/v1:1.2.3' with {
26+
optionalString: strParam1
27+
} as extWithOptionalConfig3
28+
extension 'br:mcr.microsoft.com/bicep/extensions/hassecureconfig/v1:1.2.3' with {
29+
requiredSecureString: secureStrParam1
30+
} as extWithSecureStr1
31+
extension 'br:mcr.microsoft.com/bicep/extensions/hasconfig/v1:1.2.3' with {
32+
requiredString: testResource1.id
33+
} as extWithConfig1
34+
extension 'br:mcr.microsoft.com/bicep/extensions/hasconfig/v1:1.2.3' with {
35+
requiredString: boolParam1 ? strParamVar1 : strParam1
36+
} as extWithConfig2
2437

2538
// END: Extension declarations
2639

src/Bicep.Core.Samples/Files/baselines/Extensions_CRLF/main.diagnostics.bicep

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ param boolParam1 bool
1212
// BEGIN: Variables
1313

1414
var strVar1 = 'strVar1Value'
15+
var strParamVar1 = strParam1
1516

1617
// END: Variables
1718

@@ -21,6 +22,19 @@ extension az
2122
extension kubernetes as k8s
2223
extension 'br:mcr.microsoft.com/bicep/extensions/hasoptionalconfig/v1:1.2.3' as extWithOptionalConfig1
2324
extension 'br:mcr.microsoft.com/bicep/extensions/hasoptionalconfig/v1:1.2.3' as extWithOptionalConfig2
25+
extension 'br:mcr.microsoft.com/bicep/extensions/hasoptionalconfig/v1:1.2.3' with {
26+
optionalString: strParam1
27+
} as extWithOptionalConfig3
28+
extension 'br:mcr.microsoft.com/bicep/extensions/hassecureconfig/v1:1.2.3' with {
29+
requiredSecureString: secureStrParam1
30+
//@[24:39) [stacks-extensibility-compat (Info)] Secure config property values must be a key vault reference to be valid for Deployment stack deployments. (bicep core linter https://aka.ms/bicep/linter-diagnostics#stacks-extensibility-compat) |secureStrParam1|
31+
} as extWithSecureStr1
32+
extension 'br:mcr.microsoft.com/bicep/extensions/hasconfig/v1:1.2.3' with {
33+
requiredString: testResource1.id
34+
} as extWithConfig1
35+
extension 'br:mcr.microsoft.com/bicep/extensions/hasconfig/v1:1.2.3' with {
36+
requiredString: boolParam1 ? strParamVar1 : strParam1
37+
} as extWithConfig2
2438

2539
// END: Extension declarations
2640

src/Bicep.Core.Samples/Files/baselines/Extensions_CRLF/main.formatted.bicep

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ param boolParam1 bool
1212
// BEGIN: Variables
1313

1414
var strVar1 = 'strVar1Value'
15+
var strParamVar1 = strParam1
1516

1617
// END: Variables
1718

@@ -21,6 +22,18 @@ extension az
2122
extension kubernetes as k8s
2223
extension 'br:mcr.microsoft.com/bicep/extensions/hasoptionalconfig/v1:1.2.3' as extWithOptionalConfig1
2324
extension 'br:mcr.microsoft.com/bicep/extensions/hasoptionalconfig/v1:1.2.3' as extWithOptionalConfig2
25+
extension 'br:mcr.microsoft.com/bicep/extensions/hasoptionalconfig/v1:1.2.3' with {
26+
optionalString: strParam1
27+
} as extWithOptionalConfig3
28+
extension 'br:mcr.microsoft.com/bicep/extensions/hassecureconfig/v1:1.2.3' with {
29+
requiredSecureString: secureStrParam1
30+
} as extWithSecureStr1
31+
extension 'br:mcr.microsoft.com/bicep/extensions/hasconfig/v1:1.2.3' with {
32+
requiredString: testResource1.id
33+
} as extWithConfig1
34+
extension 'br:mcr.microsoft.com/bicep/extensions/hasconfig/v1:1.2.3' with {
35+
requiredString: boolParam1 ? strParamVar1 : strParam1
36+
} as extWithConfig2
2437

2538
// END: Extension declarations
2639

src/Bicep.Core.Samples/Files/baselines/Extensions_CRLF/main.ir.bicep

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// BEGIN: Parameters
2-
//@[000:3754) ProgramExpression
2+
//@[000:4364) ProgramExpression
33
//@[000:0000) | | └─ObjectPropertyExpression [UNPARENTED]
44
//@[000:0000) | | ├─StringLiteralExpression { Value = name } [UNPARENTED]
55
//@[000:0000) | | └─FunctionCallExpression { Name = format } [UNPARENTED]
@@ -106,6 +106,9 @@ param boolParam1 bool
106106
var strVar1 = 'strVar1Value'
107107
//@[000:0028) ├─DeclaredVariableExpression { Name = strVar1 }
108108
//@[014:0028) | └─StringLiteralExpression { Value = strVar1Value }
109+
var strParamVar1 = strParam1
110+
//@[000:0028) ├─DeclaredVariableExpression { Name = strParamVar1 }
111+
//@[019:0028) | └─ParametersReferenceExpression { Parameter = strParam1 }
109112

110113
// END: Variables
111114

@@ -119,6 +122,42 @@ extension 'br:mcr.microsoft.com/bicep/extensions/hasoptionalconfig/v1:1.2.3' as
119122
//@[000:0102) ├─ExtensionExpression { Name = extWithOptionalConfig1 }
120123
extension 'br:mcr.microsoft.com/bicep/extensions/hasoptionalconfig/v1:1.2.3' as extWithOptionalConfig2
121124
//@[000:0102) ├─ExtensionExpression { Name = extWithOptionalConfig2 }
125+
extension 'br:mcr.microsoft.com/bicep/extensions/hasoptionalconfig/v1:1.2.3' with {
126+
//@[000:0141) ├─ExtensionExpression { Name = extWithOptionalConfig3 }
127+
//@[082:0115) | └─ObjectExpression
128+
optionalString: strParam1
129+
//@[002:0027) | └─ObjectPropertyExpression
130+
//@[002:0016) | ├─StringLiteralExpression { Value = optionalString }
131+
//@[018:0027) | └─ParametersReferenceExpression { Parameter = strParam1 }
132+
} as extWithOptionalConfig3
133+
extension 'br:mcr.microsoft.com/bicep/extensions/hassecureconfig/v1:1.2.3' with {
134+
//@[000:0146) ├─ExtensionExpression { Name = extWithSecureStr1 }
135+
//@[080:0125) | └─ObjectExpression
136+
requiredSecureString: secureStrParam1
137+
//@[002:0039) | └─ObjectPropertyExpression
138+
//@[002:0022) | ├─StringLiteralExpression { Value = requiredSecureString }
139+
//@[024:0039) | └─ParametersReferenceExpression { Parameter = secureStrParam1 }
140+
} as extWithSecureStr1
141+
extension 'br:mcr.microsoft.com/bicep/extensions/hasconfig/v1:1.2.3' with {
142+
//@[000:0132) ├─ExtensionExpression { Name = extWithConfig1 }
143+
//@[074:0114) | └─ObjectExpression
144+
requiredString: testResource1.id
145+
//@[002:0034) | └─ObjectPropertyExpression
146+
//@[002:0016) | ├─StringLiteralExpression { Value = requiredString }
147+
//@[018:0034) | └─PropertyAccessExpression { PropertyName = id }
148+
//@[018:0031) | └─ResourceReferenceExpression
149+
} as extWithConfig1
150+
extension 'br:mcr.microsoft.com/bicep/extensions/hasconfig/v1:1.2.3' with {
151+
//@[000:0153) ├─ExtensionExpression { Name = extWithConfig2 }
152+
//@[074:0135) | └─ObjectExpression
153+
requiredString: boolParam1 ? strParamVar1 : strParam1
154+
//@[002:0055) | └─ObjectPropertyExpression
155+
//@[002:0016) | ├─StringLiteralExpression { Value = requiredString }
156+
//@[018:0055) | └─TernaryExpression
157+
//@[018:0028) | ├─ParametersReferenceExpression { Parameter = boolParam1 }
158+
//@[031:0043) | ├─VariableReferenceExpression { Variable = strParamVar1 }
159+
//@[046:0055) | └─ParametersReferenceExpression { Parameter = strParam1 }
160+
} as extWithConfig2
122161

123162
// END: Extension declarations
124163

src/Bicep.Core.Samples/Files/baselines/Extensions_CRLF/main.json

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"_generator": {
1111
"name": "bicep",
1212
"version": "dev",
13-
"templateHash": "10760791355972060746"
13+
"templateHash": "2332865048346148420"
1414
}
1515
},
1616
"parameters": {
@@ -25,7 +25,8 @@
2525
}
2626
},
2727
"variables": {
28-
"strVar1": "strVar1Value"
28+
"strVar1": "strVar1Value",
29+
"strParamVar1": "[parameters('strParam1')]"
2930
},
3031
"extensions": {
3132
"az": {
@@ -43,6 +44,42 @@
4344
"extWithOptionalConfig2": {
4445
"name": "hasoptionalconfig",
4546
"version": "1.2.3"
47+
},
48+
"extWithOptionalConfig3": {
49+
"name": "hasoptionalconfig",
50+
"version": "1.2.3",
51+
"config": {
52+
"optionalString": {
53+
"defaultValue": "[parameters('strParam1')]"
54+
}
55+
}
56+
},
57+
"extWithSecureStr1": {
58+
"name": "hassecureconfig",
59+
"version": "1.2.3",
60+
"config": {
61+
"requiredSecureString": {
62+
"defaultValue": "[parameters('secureStrParam1')]"
63+
}
64+
}
65+
},
66+
"extWithConfig1": {
67+
"name": "hasconfig",
68+
"version": "1.2.3",
69+
"config": {
70+
"requiredString": {
71+
"defaultValue": "[resourceId('My.Rp/TestType', 'testResource1')]"
72+
}
73+
}
74+
},
75+
"extWithConfig2": {
76+
"name": "hasconfig",
77+
"version": "1.2.3",
78+
"config": {
79+
"requiredString": {
80+
"defaultValue": "[if(parameters('boolParam1'), variables('strParamVar1'), parameters('strParam1'))]"
81+
}
82+
}
4683
}
4784
},
4885
"resources": {

src/Bicep.Core.Samples/Files/baselines/Extensions_CRLF/main.sourcemap.bicep

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ param boolParam1 bool
2121
// BEGIN: Variables
2222

2323
var strVar1 = 'strVar1Value'
24-
//@ "strVar1": "strVar1Value"
24+
//@ "strVar1": "strVar1Value",
25+
var strParamVar1 = strParam1
26+
//@ "strParamVar1": "[parameters('strParam1')]"
2527

2628
// END: Variables
2729

@@ -46,7 +48,55 @@ extension 'br:mcr.microsoft.com/bicep/extensions/hasoptionalconfig/v1:1.2.3' as
4648
//@ "extWithOptionalConfig2": {
4749
//@ "name": "hasoptionalconfig",
4850
//@ "version": "1.2.3"
51+
//@ },
52+
extension 'br:mcr.microsoft.com/bicep/extensions/hasoptionalconfig/v1:1.2.3' with {
53+
//@ "extWithOptionalConfig3": {
54+
//@ "name": "hasoptionalconfig",
55+
//@ "version": "1.2.3",
56+
//@ "config": {
57+
//@ "optionalString": {
58+
//@ }
59+
//@ }
60+
//@ },
61+
optionalString: strParam1
62+
//@ "defaultValue": "[parameters('strParam1')]"
63+
} as extWithOptionalConfig3
64+
extension 'br:mcr.microsoft.com/bicep/extensions/hassecureconfig/v1:1.2.3' with {
65+
//@ "extWithSecureStr1": {
66+
//@ "name": "hassecureconfig",
67+
//@ "version": "1.2.3",
68+
//@ "config": {
69+
//@ "requiredSecureString": {
70+
//@ }
71+
//@ }
72+
//@ },
73+
requiredSecureString: secureStrParam1
74+
//@ "defaultValue": "[parameters('secureStrParam1')]"
75+
} as extWithSecureStr1
76+
extension 'br:mcr.microsoft.com/bicep/extensions/hasconfig/v1:1.2.3' with {
77+
//@ "extWithConfig1": {
78+
//@ "name": "hasconfig",
79+
//@ "version": "1.2.3",
80+
//@ "config": {
81+
//@ "requiredString": {
82+
//@ }
83+
//@ }
84+
//@ },
85+
requiredString: testResource1.id
86+
//@ "defaultValue": "[resourceId('My.Rp/TestType', 'testResource1')]"
87+
} as extWithConfig1
88+
extension 'br:mcr.microsoft.com/bicep/extensions/hasconfig/v1:1.2.3' with {
89+
//@ "extWithConfig2": {
90+
//@ "name": "hasconfig",
91+
//@ "version": "1.2.3",
92+
//@ "config": {
93+
//@ "requiredString": {
94+
//@ }
95+
//@ }
4996
//@ }
97+
requiredString: boolParam1 ? strParamVar1 : strParam1
98+
//@ "defaultValue": "[if(parameters('boolParam1'), variables('strParamVar1'), parameters('strParam1'))]"
99+
} as extWithConfig2
50100

51101
// END: Extension declarations
52102

src/Bicep.Core.Samples/Files/baselines/Extensions_CRLF/main.symbolicnames.json

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"_generator": {
1111
"name": "bicep",
1212
"version": "dev",
13-
"templateHash": "10760791355972060746"
13+
"templateHash": "2332865048346148420"
1414
}
1515
},
1616
"parameters": {
@@ -25,7 +25,8 @@
2525
}
2626
},
2727
"variables": {
28-
"strVar1": "strVar1Value"
28+
"strVar1": "strVar1Value",
29+
"strParamVar1": "[parameters('strParam1')]"
2930
},
3031
"extensions": {
3132
"az": {
@@ -43,6 +44,42 @@
4344
"extWithOptionalConfig2": {
4445
"name": "hasoptionalconfig",
4546
"version": "1.2.3"
47+
},
48+
"extWithOptionalConfig3": {
49+
"name": "hasoptionalconfig",
50+
"version": "1.2.3",
51+
"config": {
52+
"optionalString": {
53+
"defaultValue": "[parameters('strParam1')]"
54+
}
55+
}
56+
},
57+
"extWithSecureStr1": {
58+
"name": "hassecureconfig",
59+
"version": "1.2.3",
60+
"config": {
61+
"requiredSecureString": {
62+
"defaultValue": "[parameters('secureStrParam1')]"
63+
}
64+
}
65+
},
66+
"extWithConfig1": {
67+
"name": "hasconfig",
68+
"version": "1.2.3",
69+
"config": {
70+
"requiredString": {
71+
"defaultValue": "[resourceId('My.Rp/TestType', 'testResource1')]"
72+
}
73+
}
74+
},
75+
"extWithConfig2": {
76+
"name": "hasconfig",
77+
"version": "1.2.3",
78+
"config": {
79+
"requiredString": {
80+
"defaultValue": "[if(parameters('boolParam1'), variables('strParamVar1'), parameters('strParam1'))]"
81+
}
82+
}
4683
}
4784
},
4885
"resources": {

src/Bicep.Core.Samples/Files/baselines/Extensions_CRLF/main.symbols.bicep

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ param boolParam1 bool
1616

1717
var strVar1 = 'strVar1Value'
1818
//@[004:011) Variable strVar1. Type: 'strVar1Value'. Declaration start char: 0, length: 28
19+
var strParamVar1 = strParam1
20+
//@[004:016) Variable strParamVar1. Type: string. Declaration start char: 0, length: 28
1921

2022
// END: Variables
2123

@@ -29,6 +31,22 @@ extension 'br:mcr.microsoft.com/bicep/extensions/hasoptionalconfig/v1:1.2.3' as
2931
//@[080:102) ImportedNamespace extWithOptionalConfig1. Type: extWithOptionalConfig1. Declaration start char: 0, length: 102
3032
extension 'br:mcr.microsoft.com/bicep/extensions/hasoptionalconfig/v1:1.2.3' as extWithOptionalConfig2
3133
//@[080:102) ImportedNamespace extWithOptionalConfig2. Type: extWithOptionalConfig2. Declaration start char: 0, length: 102
34+
extension 'br:mcr.microsoft.com/bicep/extensions/hasoptionalconfig/v1:1.2.3' with {
35+
optionalString: strParam1
36+
} as extWithOptionalConfig3
37+
//@[005:027) ImportedNamespace extWithOptionalConfig3. Type: extWithOptionalConfig3. Declaration start char: 0, length: 141
38+
extension 'br:mcr.microsoft.com/bicep/extensions/hassecureconfig/v1:1.2.3' with {
39+
requiredSecureString: secureStrParam1
40+
} as extWithSecureStr1
41+
//@[005:022) ImportedNamespace extWithSecureStr1. Type: extWithSecureStr1. Declaration start char: 0, length: 146
42+
extension 'br:mcr.microsoft.com/bicep/extensions/hasconfig/v1:1.2.3' with {
43+
requiredString: testResource1.id
44+
} as extWithConfig1
45+
//@[005:019) ImportedNamespace extWithConfig1. Type: extWithConfig1. Declaration start char: 0, length: 132
46+
extension 'br:mcr.microsoft.com/bicep/extensions/hasconfig/v1:1.2.3' with {
47+
requiredString: boolParam1 ? strParamVar1 : strParam1
48+
} as extWithConfig2
49+
//@[005:019) ImportedNamespace extWithConfig2. Type: extWithConfig2. Declaration start char: 0, length: 153
3250

3351
// END: Extension declarations
3452

0 commit comments

Comments
 (0)