-
Notifications
You must be signed in to change notification settings - Fork 756
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for dynamic loading of provider definitions (#10868)
## Overview Adds support for loading the 'az' provider dynamically sourced from an OCI artifact registry. The artifact must be restored (downloaded to the appropriate location) manually under `$BicepCacheRootDir/br/mcr.microsoft.com/bicep$providers$az/${providerVersion}` which is the target location in the Bicep cache for the `az` provider. The work to restore the provider data to the cache will be handled in a separate PR for convenience so that reviewing PRs is easier. To enable the feature `DynamicTypeLoadingEnabled` and must be set to true in `bicepconfig.json`: ```json { "experimentalFeaturesEnabled": { "extensibility": true, "dynamicTypeLoadingEnabled": true, }, "cacheRootDirectory": "~/.bicep", } ``` ## Changes - Adds a new experimental feature flag `DynamicTypeLoadingEnabled` - Adds a new factory `AzResourceTypeLoader` that is handling the concern of deciding the provider loader to use based on the feature flag and presence of an import declaration syntax in the Bicep file being processed. - Serializes the provider version by inspecting the `ImportDeclarationSyntax` vs using a hardcoded value Fixes #10662 ## Contributing a feature * [x] I have opened a new issue for the proposal, or commented on an existing one, and ensured that the Bicep maintainers are good with the design of the feature being implemented * [x] I have included "Fixes #{issue_number}" in the PR description, so GitHub can link to the issue and close it when the PR is merged * [x] I have appropriate test coverage of my new feature --------- Co-authored-by: Ariel Silverman <[email protected]>
- Loading branch information
1 parent
9da3e4c
commit b939e3d
Showing
60 changed files
with
575 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using Bicep.Core.Diagnostics; | ||
using Bicep.Core.IntegrationTests.Extensibility; | ||
|
@@ -16,19 +17,21 @@ namespace Bicep.Core.IntegrationTests | |
[TestClass] | ||
public class OutputsTests | ||
{ | ||
private ServiceBuilder ServicesWithResourceTyped => new ServiceBuilder().WithFeatureOverrides(new(TestContext, ResourceTypedParamsAndOutputsEnabled: true)); | ||
private ServiceBuilder ServicesWithResourceTyped => new ServiceBuilder() | ||
.WithFeatureOverrides(new(TestContext, ResourceTypedParamsAndOutputsEnabled: true)); | ||
|
||
[NotNull] | ||
public TestContext? TestContext { get; set; } | ||
|
||
private ServiceBuilder ServicesWithExtensibility => new ServiceBuilder() | ||
.WithFeatureOverrides(new(TestContext, ExtensibilityEnabled: true, ResourceTypedParamsAndOutputsEnabled: true)) | ||
.WithNamespaceProvider(new TestExtensibilityNamespaceProvider(BicepTestConstants.AzResourceTypeLoader)); | ||
.WithNamespaceProvider(new TestExtensibilityNamespaceProvider(BicepTestConstants.AzResourceTypeLoaderFactory)); | ||
|
||
[TestMethod] | ||
public void Output_can_have_inferred_resource_type() | ||
{ | ||
var result = CompilationHelper.Compile(ServicesWithResourceTyped, @" | ||
var result = CompilationHelper.Compile(ServicesWithResourceTyped, | ||
""" | ||
resource resource 'Microsoft.Storage/storageAccounts@2019-06-01' = { | ||
name: 'test' | ||
location: 'eastus' | ||
|
@@ -44,12 +47,14 @@ public void Output_can_have_inferred_resource_type() | |
} | ||
} | ||
output out resource = resource | ||
"); | ||
"""); | ||
|
||
result.ExcludingLinterDiagnostics().Should().NotHaveAnyDiagnostics(); | ||
|
||
var model = result.Compilation.GetEntrypointSemanticModel(); | ||
var @out = model.Root.OutputDeclarations.Should().ContainSingle().Subject; | ||
var typeInfo = model.GetTypeInfo(@out.DeclaringSyntax); | ||
|
||
typeInfo.Should().BeOfType<ResourceType>().Which.TypeReference.FormatName().Should().BeEquivalentTo("Microsoft.Storage/storageAccounts@2019-06-01"); | ||
|
||
result.Template.Should().HaveValueAtPath("$.outputs.out", new JObject() | ||
|
@@ -66,7 +71,8 @@ public void Output_can_have_inferred_resource_type() | |
[TestMethod] | ||
public void Output_can_have_specified_resource_type() | ||
{ | ||
var result = CompilationHelper.Compile(ServicesWithResourceTyped, @" | ||
var result = CompilationHelper.Compile(ServicesWithResourceTyped, | ||
""" | ||
resource resource 'Microsoft.Storage/storageAccounts@2019-06-01' = { | ||
name: 'test' | ||
location: 'eastus' | ||
|
@@ -82,12 +88,14 @@ public void Output_can_have_specified_resource_type() | |
} | ||
} | ||
output out resource 'Microsoft.Storage/storageAccounts@2019-06-01' = resource | ||
"); | ||
"""); | ||
|
||
result.ExcludingLinterDiagnostics().Should().NotHaveAnyDiagnostics(); | ||
|
||
var model = result.Compilation.GetEntrypointSemanticModel(); | ||
var @out = model.Root.OutputDeclarations.Should().ContainSingle().Subject; | ||
var typeInfo = model.GetTypeInfo(@out.DeclaringSyntax); | ||
|
||
typeInfo.Should().BeOfType<ResourceType>().Which.TypeReference.FormatName().Should().BeEquivalentTo("Microsoft.Storage/storageAccounts@2019-06-01"); | ||
|
||
result.Template.Should().HaveValueAtPath("$.outputs.out", new JObject() | ||
|
@@ -108,7 +116,8 @@ public void Output_can_have_specified_resource_type() | |
public void Output_can_have_object_type(bool enableResourceTypeParameters) | ||
{ | ||
var services = enableResourceTypeParameters ? ServicesWithResourceTyped : new ServiceBuilder(); | ||
var result = CompilationHelper.Compile(services, @" | ||
var result = CompilationHelper.Compile(services, | ||
""" | ||
resource resource 'Microsoft.Storage/storageAccounts@2019-06-01' = { | ||
name: 'test' | ||
location: 'eastus' | ||
|
@@ -124,7 +133,8 @@ public void Output_can_have_object_type(bool enableResourceTypeParameters) | |
} | ||
} | ||
output out object = resource | ||
"); | ||
"""); | ||
|
||
result.ExcludingLinterDiagnostics().Should().NotHaveAnyDiagnostics(); | ||
|
||
result.Template.Should().HaveValueAtPath("$.outputs.out", new JObject() | ||
|
@@ -137,7 +147,8 @@ public void Output_can_have_object_type(bool enableResourceTypeParameters) | |
[TestMethod] | ||
public void Output_can_have_decorators() | ||
{ | ||
var result = CompilationHelper.Compile(ServicesWithResourceTyped, @" | ||
var result = CompilationHelper.Compile(ServicesWithResourceTyped, | ||
""" | ||
resource resource 'Microsoft.Storage/storageAccounts@2019-06-01' = { | ||
name: 'test' | ||
location: 'eastus' | ||
|
@@ -155,7 +166,8 @@ public void Output_can_have_decorators() | |
@description('cool beans') | ||
output out resource 'Microsoft.Storage/storageAccounts@2019-06-01' = resource | ||
"); | ||
"""); | ||
|
||
result.ExcludingLinterDiagnostics().Should().NotHaveAnyDiagnostics(); | ||
|
||
result.Template.Should().HaveValueAtPath("$.outputs.out", new JObject() | ||
|
@@ -173,13 +185,15 @@ public void Output_can_have_decorators() | |
[TestMethod] | ||
public void Output_can_have_warnings_for_missing_type() | ||
{ | ||
var result = CompilationHelper.Compile(ServicesWithResourceTyped, @" | ||
var result = CompilationHelper.Compile(ServicesWithResourceTyped, | ||
""" | ||
resource resource 'Some.Fake/Type@2019-06-01' = { | ||
name: 'test' | ||
} | ||
output out resource 'Some.Fake/Type@2019-06-01' = resource | ||
"); | ||
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new [] | ||
"""); | ||
|
||
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[] | ||
{ | ||
// There are two warnings because there are two places in code to correct the missing type. | ||
("BCP081", DiagnosticLevel.Warning, "Resource type \"Some.Fake/Type@2019-06-01\" does not have types available."), | ||
|
@@ -192,13 +206,15 @@ public void Output_can_have_warnings_for_missing_type_but_we_dont_duplicate_them | |
{ | ||
// As a special case we don't show a warning on the output when the type is inferred | ||
// the user only has one location in code to correct. | ||
var result = CompilationHelper.Compile(ServicesWithResourceTyped, @" | ||
var result = CompilationHelper.Compile(ServicesWithResourceTyped, | ||
""" | ||
resource resource 'Some.Fake/Type@2019-06-01' = { | ||
name: 'test' | ||
} | ||
output out resource = resource | ||
"); | ||
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new [] | ||
"""); | ||
|
||
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[] | ||
{ | ||
("BCP081", DiagnosticLevel.Warning, "Resource type \"Some.Fake/Type@2019-06-01\" does not have types available."), | ||
}); | ||
|
@@ -207,20 +223,23 @@ public void Output_can_have_warnings_for_missing_type_but_we_dont_duplicate_them | |
[TestMethod] | ||
public void Output_cannot_use_extensibility_resource_type() | ||
{ | ||
var result = CompilationHelper.Compile(ServicesWithExtensibility, @" | ||
var result = CompilationHelper.Compile(ServicesWithExtensibility, | ||
""" | ||
import '[email protected]' with { | ||
connectionString: 'asdf' | ||
} as stg | ||
resource container 'stg:container' = { | ||
name: 'myblob' | ||
} | ||
output out resource = container | ||
"); | ||
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new [] | ||
"""); | ||
|
||
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[] | ||
{ | ||
("BCP227", DiagnosticLevel.Error, "The type \"container\" cannot be used as a parameter or output type. Extensibility types are currently not supported as parameters or outputs."), | ||
}); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
src/Bicep.Core.IntegrationTests/Semantics/ParamsSemanticModelTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.