Skip to content

Commit

Permalink
Reintroduce 'resourceInfo' code generation behind experimental feature (
Browse files Browse the repository at this point in the history
#16045)

The original issues with the resourceInfo function have been fixed in
the backend. This PR brings back the simplified code generation using
the `resourceInfo` function for `id`, `type`, `name` and `apiVersion`
properties, behind an experimental feature flag.

Closes #12597
###### Microsoft Reviewers: [Open in
CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/16045)
  • Loading branch information
anthony-c-martin authored Jan 8, 2025
1 parent 3be0281 commit 74c4ce3
Show file tree
Hide file tree
Showing 23 changed files with 1,656 additions and 25 deletions.
3 changes: 3 additions & 0 deletions docs/experimental-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Enabling this feature makes the `name` property in the body of `module` declarat
### `resourceDerivedTypes`
If enabled, templates can reuse resource types wherever a type is expected. For example, to declare a parameter `foo` that should be usable as the name of an Azure Storage account, the following syntax would be used: `param foo resourceInput<'Microsoft.Storage/storageAccounts@2022-09-01'>.name`. **NB:** Because resource types may be inaccurate in some cases, no constraints other than the ARM type primitive will be enforced on resource derived types within the ARM deployment engine. Resource-derived types will be checked by Bicep at compile time, but violations will be emitted as warnings rather than errors.

### `resourceInfoCodegen`
Enables the 'resourceInfo' function for simplified code generation.

### `resourceTypedParamsAndOutputs`
Enables the type for a parameter or output to be of type resource to make it easier to pass resource references between modules. This feature is only partially implemented. See [Simplifying resource referencing](https://github.com/azure/bicep/issues/2245).

Expand Down
10 changes: 6 additions & 4 deletions src/Bicep.Core.IntegrationTests/ExamplesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ public class ExamplesTests
[NotNull]
public TestContext? TestContext { get; set; }

private async Task RunExampleTest(EmbeddedFile embeddedBicep, FeatureProviderOverrides features, string jsonFileExtension)
public static async Task RunExampleTest(TestContext testContext, EmbeddedFile embeddedBicep, FeatureProviderOverrides? features = null, string jsonFileExtension = ".json")
{
var baselineFolder = BaselineFolder.BuildOutputFolder(TestContext, embeddedBicep);
features ??= new();
var baselineFolder = BaselineFolder.BuildOutputFolder(testContext, embeddedBicep);
var bicepFile = baselineFolder.EntryFile;
var jsonFile = baselineFolder.GetFileOrEnsureCheckedIn(Path.ChangeExtension(embeddedBicep.FileName, jsonFileExtension));

Expand Down Expand Up @@ -69,19 +70,20 @@ private async Task RunExampleTest(EmbeddedFile embeddedBicep, FeatureProviderOve
[DynamicData(nameof(GetExampleData), DynamicDataSourceType.Method)]
[TestCategory(BaselineHelper.BaselineTestCategory)]
public Task ExampleIsValid(EmbeddedFile embeddedBicep)
=> RunExampleTest(embeddedBicep, new(), ".json");
=> RunExampleTest(TestContext, embeddedBicep, new(), ".json");

[DataTestMethod]
[DynamicData(nameof(GetExampleData), DynamicDataSourceType.Method)]
[TestCategory(BaselineHelper.BaselineTestCategory)]
public Task ExampleIsValid_using_experimental_symbolic_names(EmbeddedFile embeddedBicep)
=> RunExampleTest(embeddedBicep, new(SymbolicNameCodegenEnabled: true), ".symbolicnames.json");
=> RunExampleTest(TestContext, embeddedBicep, new(SymbolicNameCodegenEnabled: true), ".symbolicnames.json");

[DataTestMethod]
[DynamicData(nameof(GetExtensibilityExampleData), DynamicDataSourceType.Method)]
[TestCategory(BaselineHelper.BaselineTestCategory)]
public Task ExampleIsValid_extensibility(EmbeddedFile embeddedBicep)
=> RunExampleTest(
TestContext,
embeddedBicep,
new(ExtensibilityEnabled: true),
".json");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
targetScope = 'subscription'

@description('Resource Group object definition.')
param resourceGroup object

var defaultResourceGroupProperties = {
tags: {}
deploy: true
}

// Deploy Resource Group
resource sqlRg 'Microsoft.Resources/resourceGroups@2021-04-01' = if (union(
defaultResourceGroupProperties,
resourceGroup
).deploy) {
name: resourceGroup.name
location: resourceGroup.location
tags: union(defaultResourceGroupProperties, resourceGroup).tags
properties: {}
}

// Start SQL Logical Servers deployment
module sqlLogicalServers 'modules/sql-logical-servers.bicep' = {
name: 'sqlLogicalServers'
scope: sqlRg
params: {
sqlLogicalServers: resourceGroup.sqlLogicalServers
tags: union(defaultResourceGroupProperties, resourceGroup).tags
}
}
Loading

0 comments on commit 74c4ce3

Please sign in to comment.