Skip to content

Commit bc5e0bf

Browse files
authored
Remove onlyIfNotExists experimental feature (#17996)
## Description Remove onlyIfNotExists experimental feature to make decorator GA. Updated EmitterSettings.cs to emit template language 2.0 when onlyIfNotExists() decorator is used. ## 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/17996)
1 parent e350617 commit bc5e0bf

File tree

16 files changed

+81
-111
lines changed

16 files changed

+81
-111
lines changed

docs/experimental-features.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,6 @@ Enables Bicep to run deployments locally, so that you can run Bicep extensions w
3838
Moves defining extension configurations to the module level rather than from within a template. The feature also
3939
includes enhancements for Deployment stacks extensibility integration. This feature is not ready for use.
4040

41-
### `onlyIfNotExists`
42-
The feature introduces the onlyIfNotExists decorator on a resource. The decorator will only deploy the resource if it does not exist. (Note: This feature will not work until the backend service support has been deployed)
43-
```
44-
@onlyIfNotExists()
45-
resource onlyDeployIfNotExists 'Microsoft...' = {
46-
name: 'example'
47-
location: 'eastus'
48-
properties: {
49-
...
50-
}
51-
}
52-
```
53-
5441
### `resourceInfoCodegen`
5542

5643
Enables the 'resourceInfo' function for simplified code generation.

src/Bicep.Core.IntegrationTests/Decorators/OnlyIfNotExistsDecoratorTests.cs

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class OnlyIfNotExistsDecoratorTests
2323
[TestMethod]
2424
public void OnlyIfNotExistsDecorator_ValidScenario()
2525
{
26-
var services = new ServiceBuilder().WithFeatureOverrides(new FeatureProviderOverrides(TestContext, OnlyIfNotExistsEnabled: true));
26+
var services = new ServiceBuilder().WithFeatureOverrides(new FeatureProviderOverrides(TestContext));
2727
var (template, diagnostics, _) = CompilationHelper.Compile(services, @"
2828
@onlyIfNotExists()
2929
resource sqlServer 'Microsoft.Sql/servers@2021-11-01' = {
@@ -40,13 +40,15 @@ public void OnlyIfNotExistsDecorator_ValidScenario()
4040

4141
template.Should().NotBeNull()
4242
.And.HaveValueAtPath("$.resources['sqlServer'][email protected]", onlyIfNotExistsJObject);
43+
template.Should().NotBeNull()
44+
.And.HaveValueAtPath("$.languageVersion", "2.0");
4345
}
4446
}
4547

4648
[TestMethod]
4749
public void OnlyIfNotExistsAndRetryOnDecorator_ValidScenario()
4850
{
49-
var services = new ServiceBuilder().WithFeatureOverrides(new FeatureProviderOverrides(TestContext, OnlyIfNotExistsEnabled: true, WaitAndRetryEnabled: true));
51+
var services = new ServiceBuilder().WithFeatureOverrides(new FeatureProviderOverrides(TestContext, WaitAndRetryEnabled: true));
5052
var (template, diagnostics, _) = CompilationHelper.Compile(services, @"
5153
@onlyIfNotExists()
5254
@retryOn(['ResourceNotFound', 'ServerError'], 1)
@@ -79,7 +81,7 @@ public void OnlyIfNotExistsAndRetryOnDecorator_ValidScenario()
7981
[TestMethod]
8082
public void OnlyIfNotExistsDecorator_WithModuleDeclaration_ShouldFail()
8183
{
82-
var services = new ServiceBuilder().WithFeatureOverrides(new FeatureProviderOverrides(TestContext, OnlyIfNotExistsEnabled: true));
84+
var services = new ServiceBuilder().WithFeatureOverrides(new FeatureProviderOverrides(TestContext));
8385

8486
var mainUri = new Uri("file:///main.bicep");
8587
var moduleUri = new Uri("file:///module.bicep");
@@ -119,7 +121,7 @@ param inputb string
119121
[TestMethod]
120122
public void OnlyIfNotExistsDecorator_ExpectedResourceDeclaration()
121123
{
122-
var services = new ServiceBuilder().WithFeatureOverrides(new FeatureProviderOverrides(TestContext, OnlyIfNotExistsEnabled: true));
124+
var services = new ServiceBuilder().WithFeatureOverrides(new FeatureProviderOverrides(TestContext));
123125
var (template, diagnostics, _) = CompilationHelper.Compile(services, @"
124126
@onlyIfNotExists()
125127
");
@@ -135,7 +137,7 @@ public void OnlyIfNotExistsDecorator_ExpectedResourceDeclaration()
135137
[TestMethod]
136138
public void OnlyIfNotExistsDecoratorWithCollections_ValidScenario()
137139
{
138-
var services = new ServiceBuilder().WithFeatureOverrides(new FeatureProviderOverrides(TestContext, OnlyIfNotExistsEnabled: true));
140+
var services = new ServiceBuilder().WithFeatureOverrides(new FeatureProviderOverrides(TestContext));
139141
var (template, diagnostics, _) = CompilationHelper.Compile(services, @"
140142
@onlyIfNotExists()
141143
resource sqlServer 'Microsoft.Sql/servers@2021-11-01' = [for i in range(1, 2):{
@@ -157,26 +159,6 @@ public void OnlyIfNotExistsDecoratorWithCollections_ValidScenario()
157159

158160
[TestMethod]
159161
public void OnlyIfNotExistsDecorator_Arguments_ShouldFail()
160-
{
161-
var services = new ServiceBuilder().WithFeatureOverrides(new FeatureProviderOverrides(TestContext, OnlyIfNotExistsEnabled: true));
162-
var (template, diagnostics, _) = CompilationHelper.Compile(services, @"
163-
@onlyIfNotExists(1)
164-
resource sqlServer 'Microsoft.Sql/servers@2021-11-01' = {
165-
name: 'sql-server-name'
166-
location: 'polandcentral'
167-
}
168-
");
169-
using (new AssertionScope())
170-
{
171-
template.Should().NotHaveValue();
172-
diagnostics.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[] {
173-
("BCP071", DiagnosticLevel.Error, "Expected 0 arguments, but got 1."),
174-
});
175-
}
176-
}
177-
178-
[TestMethod]
179-
public void OnlyIfNotExistsDecorator_NotEnabled_ShouldFail()
180162
{
181163
var services = new ServiceBuilder().WithFeatureOverrides(new FeatureProviderOverrides(TestContext));
182164
var (template, diagnostics, _) = CompilationHelper.Compile(services, @"
@@ -190,7 +172,7 @@ public void OnlyIfNotExistsDecorator_NotEnabled_ShouldFail()
190172
{
191173
template.Should().NotHaveValue();
192174
diagnostics.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[] {
193-
("BCP057", DiagnosticLevel.Error, "The name \"onlyIfNotExists\" does not exist in the current context."),
175+
("BCP071", DiagnosticLevel.Error, "Expected 0 arguments, but got 1."),
194176
});
195177
}
196178
}

src/Bicep.Core.Samples/Files/baselines/InvalidOutputs_CRLF/Completions/decorators.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,23 @@
205205
"command": "editor.action.triggerParameterHints"
206206
}
207207
},
208+
{
209+
"label": "onlyIfNotExists",
210+
"kind": "function",
211+
"documentation": {
212+
"kind": "markdown",
213+
"value": "```bicep\nonlyIfNotExists(): any\n\n``` \n \n"
214+
},
215+
"deprecated": false,
216+
"preselect": false,
217+
"sortText": "3_onlyIfNotExists",
218+
"insertTextFormat": "snippet",
219+
"insertTextMode": "adjustIndentation",
220+
"textEdit": {
221+
"range": {},
222+
"newText": "onlyIfNotExists()$0"
223+
}
224+
},
208225
{
209226
"label": "sealed",
210227
"kind": "function",

src/Bicep.Core.Samples/Files/baselines/InvalidOutputs_CRLF/Completions/decoratorsPlusNamespace.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,23 @@
205205
"command": "editor.action.triggerParameterHints"
206206
}
207207
},
208+
{
209+
"label": "onlyIfNotExists",
210+
"kind": "function",
211+
"documentation": {
212+
"kind": "markdown",
213+
"value": "```bicep\nonlyIfNotExists(): any\n\n``` \n \n"
214+
},
215+
"deprecated": false,
216+
"preselect": false,
217+
"sortText": "3_onlyIfNotExists",
218+
"insertTextFormat": "snippet",
219+
"insertTextMode": "adjustIndentation",
220+
"textEdit": {
221+
"range": {},
222+
"newText": "onlyIfNotExists()$0"
223+
}
224+
},
208225
{
209226
"label": "sealed",
210227
"kind": "function",

src/Bicep.Core.UnitTests/Configuration/ConfigurationManagerTests.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ public void GetBuiltInConfiguration_NoParameter_ReturnsBuiltInConfigurationWithA
111111
"localDeploy": false,
112112
"resourceInfoCodegen": false,
113113
"desiredStateConfiguration": false,
114-
"onlyIfNotExists": false,
115114
"userDefinedConstraints": false,
116115
"deployCommands": false
117116
},
@@ -195,7 +194,6 @@ public void GetBuiltInConfiguration_DisableAllAnalyzers_ReturnsBuiltInConfigurat
195194
"resourceInfoCodegen": false,
196195
"moduleExtensionConfigs": false,
197196
"desiredStateConfiguration": false,
198-
"onlyIfNotExists": false,
199197
"userDefinedConstraints": false,
200198
"deployCommands": false
201199
},
@@ -301,7 +299,6 @@ public void GetBuiltInConfiguration_DisableAnalyzers_ReturnsBuiltInConfiguration
301299
"resourceInfoCodegen": false,
302300
"moduleExtensionConfigs": false,
303301
"desiredStateConfiguration": false,
304-
"onlyIfNotExists": false,
305302
"userDefinedConstraints": false,
306303
"deployCommands": false
307304
},
@@ -388,7 +385,6 @@ public void GetBuiltInConfiguration_EnableExperimentalFeature_ReturnsBuiltInConf
388385
ResourceInfoCodegen: false,
389386
ModuleExtensionConfigs: false,
390387
DesiredStateConfiguration: false,
391-
OnlyIfNotExists: false,
392388
UserDefinedConstraints: false,
393389
DeployCommands: false);
394390

@@ -473,7 +469,6 @@ public void GetBuiltInConfiguration_EnableExperimentalFeature_ReturnsBuiltInConf
473469
"resourceInfoCodegen": false,
474470
"moduleExtensionConfigs": false,
475471
"desiredStateConfiguration": false,
476-
"onlyIfNotExists": false,
477472
"userDefinedConstraints": false,
478473
"deployCommands": false
479474
},
@@ -825,7 +820,6 @@ public void GetConfiguration_ValidCustomConfiguration_OverridesBuiltInConfigurat
825820
"resourceInfoCodegen": false,
826821
"moduleExtensionConfigs": false,
827822
"desiredStateConfiguration": false,
828-
"onlyIfNotExists": false,
829823
"userDefinedConstraints": false,
830824
"deployCommands": false
831825
},

src/Bicep.Core.UnitTests/Features/FeatureProviderOverrides.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public record FeatureProviderOverrides(
2424
string? AssemblyVersion = BicepTestConstants.DevAssemblyFileVersion,
2525
bool? ModuleExtensionConfigsEnabled = default,
2626
bool? DesiredStateConfigurationEnabled = default,
27-
bool? OnlyIfNotExistsEnabled = default,
2827
bool? UserDefinedConstraintsEnabled = default,
2928
bool? DeployCommandsEnabled = default)
3029
{
@@ -45,7 +44,6 @@ public FeatureProviderOverrides(
4544
string? AssemblyVersion = BicepTestConstants.DevAssemblyFileVersion,
4645
bool? ModuleExtensionConfigsEnabled = default,
4746
bool? DesiredStateConfigurationEnabled = default,
48-
bool? OnlyIfNotExistsEnabled = default,
4947
bool? UserDefinedConstraintsEnabled = default,
5048
bool? DeployCommandsEnabled = default) : this(
5149
FileHelper.GetCacheRootDirectory(testContext),
@@ -64,7 +62,6 @@ public FeatureProviderOverrides(
6462
AssemblyVersion,
6563
ModuleExtensionConfigsEnabled,
6664
DesiredStateConfigurationEnabled,
67-
OnlyIfNotExistsEnabled,
6865
UserDefinedConstraintsEnabled,
6966
DeployCommandsEnabled)
7067
{ }

src/Bicep.Core.UnitTests/Features/OverriddenFeatureProvider.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ public OverriddenFeatureProvider(IFeatureProvider features, FeatureProviderOverr
3535

3636
public bool WaitAndRetryEnabled => overrides.WaitAndRetryEnabled ?? features.WaitAndRetryEnabled;
3737

38-
public bool OnlyIfNotExistsEnabled => overrides.OnlyIfNotExistsEnabled ?? features.OnlyIfNotExistsEnabled;
39-
4038
public bool LocalDeployEnabled => overrides.LocalDeployEnabled ?? features.LocalDeployEnabled;
4139

4240
public bool ResourceInfoCodegenEnabled => overrides.ResourceInfoCodegenEnabled ?? features.ResourceInfoCodegenEnabled;

src/Bicep.Core/Configuration/ExperimentalFeaturesEnabled.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public record ExperimentalFeaturesEnabled(
2222
bool ResourceInfoCodegen,
2323
bool ModuleExtensionConfigs,
2424
bool DesiredStateConfiguration,
25-
bool OnlyIfNotExists,
2625
bool UserDefinedConstraints,
2726
bool DeployCommands)
2827
{
@@ -44,7 +43,6 @@ public static ExperimentalFeaturesEnabled Bind(JsonElement element)
4443
ResourceInfoCodegen: false,
4544
ModuleExtensionConfigs: false,
4645
DesiredStateConfiguration: false,
47-
OnlyIfNotExists: false,
4846
UserDefinedConstraints: false,
4947
DeployCommands: false);
5048
}

src/Bicep.Core/CoreResources.Designer.cs

Lines changed: 1 addition & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Bicep.Core/CoreResources.resx

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<root>
3-
<!--
4-
Microsoft ResX Schema
5-
3+
<!--
4+
Microsoft ResX Schema
5+
66
Version 2.0
7-
8-
The primary goals of this format is to allow a simple XML format
9-
that is mostly human readable. The generation and parsing of the
10-
various data types are done through the TypeConverter classes
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
1111
associated with the data types.
12-
12+
1313
Example:
14-
14+
1515
... ado.net/XML headers & schema ...
1616
<resheader name="resmimetype">text/microsoft-resx</resheader>
1717
<resheader name="version">2.0</resheader>
@@ -26,36 +26,36 @@
2626
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
2727
<comment>This is a comment</comment>
2828
</data>
29-
30-
There are any number of "resheader" rows that contain simple
29+
30+
There are any number of "resheader" rows that contain simple
3131
name/value pairs.
32-
33-
Each data row contains a name, and value. The row also contains a
34-
type or mimetype. Type corresponds to a .NET class that support
35-
text/value conversion through the TypeConverter architecture.
36-
Classes that don't support this are serialized and stored with the
32+
33+
Each data row contains a name, and value. The row also contains a
34+
type or mimetype. Type corresponds to a .NET class that support
35+
text/value conversion through the TypeConverter architecture.
36+
Classes that don't support this are serialized and stored with the
3737
mimetype set.
38-
39-
The mimetype is used for serialized objects, and tells the
40-
ResXResourceReader how to depersist the object. This is currently not
38+
39+
The mimetype is used for serialized objects, and tells the
40+
ResXResourceReader how to depersist the object. This is currently not
4141
extensible. For a given mimetype the value must be set accordingly:
42-
43-
Note - application/x-microsoft.net.object.binary.base64 is the format
44-
that the ResXResourceWriter will generate, however the reader can
42+
43+
Note - application/x-microsoft.net.object.binary.base64 is the format
44+
that the ResXResourceWriter will generate, however the reader can
4545
read any of the formats listed below.
46-
46+
4747
mimetype: application/x-microsoft.net.object.binary.base64
48-
value : The object must be serialized with
48+
value : The object must be serialized with
4949
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
5050
: and then encoded with base64 encoding.
51-
51+
5252
mimetype: application/x-microsoft.net.object.soap.base64
53-
value : The object must be serialized with
53+
value : The object must be serialized with
5454
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
5555
: and then encoded with base64 encoding.
5656
5757
mimetype: application/x-microsoft.net.object.bytearray.base64
58-
value : The object must be serialized into a byte array
58+
value : The object must be serialized into a byte array
5959
: using a System.ComponentModel.TypeConverter
6060
: and then encoded with base64 encoding.
6161
-->
@@ -529,9 +529,6 @@
529529
<value>Parameter '{0}' is used as a resource identifier, API version, or condition in the module '{1}'. Providing a runtime value for this parameter will lead to short-circuiting or less precise predictions in What-If.</value>
530530
<comment>{0} Parameter name</comment>
531531
</data>
532-
<data name="ExperimentalFeatureNames_OnlyIfNotExists" xml:space="preserve">
533-
<value>Enable OnlyIfNotExists feature</value>
534-
</data>
535532
<data name="ImportMustBeUsedRuleDescription" xml:space="preserve">
536533
<value>All imports must be used.</value>
537534
</data>
@@ -553,4 +550,4 @@
553550
<data name="StacksExtensibilityCompatibilityRule_NonSecurePropertyValueIsReference" xml:space="preserve">
554551
<value>Non-secure config property values must be a value type to be valid for Deployment stack deployments.</value>
555552
</data>
556-
</root>
553+
</root>

0 commit comments

Comments
 (0)